天啊,有人能告诉我如何在 Tobit 模型中使用白色标准误差吗? 以下代码适用于线性模型,但不适用于 tobit 模型。
library(censReg)
library(sandwich)
# OLS model
reg_ols <- lm(vrs_eff ~ cows, data=milk_data)
summary(reg_ols)
# using White standard errors
# vcovHC: Heteroskedasticity-consistent estimation
# of the covariance matrix of the coefficient estimates in regression models.
cov_mat_OLS <- vcovHC(reg_ols, type="HC")
cov_mat_OLS
# coeftest is a generic function for performing z and
# (quasi-)t Wald tests of estimated coefficients.
# Calculate new t and p values with white standard errors
coeftest(reg_ols, cov_mat_OLS)
# Tobit model
reg_tobit <- censReg(vrs_eff ~ cows, left=0, right=1, data=milk_data)
summary(reg_tobit)
cov_mat_T <- vcovHC(reg_tobit, type="HC")
cov_mat_T
coeftest(reg_tobit, cov_mat_T)
summary(reg_ols)
summary(reg_tobit)
最佳答案
我们可以使用 AER::tobit
,该帮助页面告诉我们“tobit 函数是 survreg 的一个便捷接口(interface)”,我们可以用它来估计 Tobit 模型通过定义“Surv”对象(这是困难的方法)。
无论如何,survreg()
为 带来了一个 robust=TRUE
选项“如果没有的话,基于个体的独立性,使用稳健的‘三明治’标准错误公式中的 cluster() 项,基于簇的独立性(如果存在)。” 并且 robust=TRUE
也适用于 AER::tobit()
,因为传递给 survreg()
。
演示
首先,我们说服自己,两种 tobit 方法都会给出相同的结果。
library(censReg); library(AER)
data("Affairs")
fit.censReg <- censReg(frml, data=Affairs, right=4)
fit.AER <- tobit(frml, data=Affairs, right=4, x=TRUE)
stopifnot(all.equal(fit.censReg$estimate[1:6], fit.AER$coefficients))
现在比较——首先没有稳健的标准错误:
summary(tobit(frml, data=Affairs, right=4))$coefficients
# Test of coefficients:
#
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) 7.900980 2.803855 2.8179 0.0048339 **
# age -0.177598 0.079906 -2.2226 0.0262441 *
# yearsmarried 0.532302 0.141168 3.7707 0.0001628 ***
# religiousness -1.616336 0.424397 -3.8085 0.0001398 ***
# occupation 0.324186 0.253878 1.2769 0.2016238
# rating -2.207007 0.449832 -4.9063 9.281e-07 ***
# Log(scale) 2.072319 0.110396 18.7717 < 2.2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
第二,具有强大的标准错误:
summary(tobit(frml, data=Affairs, right=4, robust=TRUE))$coefficients
# Test of coefficients:
#
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) 7.90098 3.00928 2.6255 0.0086511 **
# age -0.17760 0.08684 -2.0451 0.0408424 *
# yearsmarried 0.53230 0.14457 3.6820 0.0002314 ***
# religiousness -1.61634 0.43674 -3.7009 0.0002148 ***
# occupation 0.32419 0.25338 1.2795 0.2007325
# rating -2.20701 0.44971 -4.9076 9.218e-07 ***
# Log(scale) 2.07232 0.11196 18.5088 < 2.2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
请注意,sandwich::vcovCL()
函数实际上是为集群设计的。但我们可以对其进行一些“破解”,并将各个观察结果作为集群(即行名称)给出。这适用于 censReg()
和 tobit()
:
library(sandwich)
coeftest(fit.AER, vcov.=vcovCL(fit.AER, cluster=rownames(Affairs), type="HC0"))
# z test of coefficients:
#
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) 7.900980 3.011782 2.6234 0.0087068 **
# age -0.177598 0.086912 -2.0434 0.0410105 *
# yearsmarried 0.532302 0.144688 3.6790 0.0002342 ***
# religiousness -1.616336 0.437101 -3.6979 0.0002174 ***
# occupation 0.324186 0.253587 1.2784 0.2011075
# rating -2.207007 0.450084 -4.9035 9.412e-07 ***
# Log(scale) 2.072319 0.112057 18.4934 < 2.2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# same
coeftest(fit.censReg, vcov.=vcovCL(fit.censReg, cluster=rownames(Affairs), type="HC0"))
正如我们所见,vcovCL
标准错误与 AER::tobit(.,robust=TRUE)
基本相同。
关于r - Tobit 模型,带有白标准误差的回归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52078167/