我们可以使用AER::tobit,帮助页面告诉我们“tobit 函数是 survreg 的便捷接口”,我们可以通过定义 "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) 基本相同。