地狱,有人能告诉我如何在Tobit模型中使用White标准错误吗? 以下代码适用于线性模型,但不适用于轨道模型。
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)
答案 0 :(得分:0)
我们可以使用AER::tobit
,该帮助页面告诉我们“功能tobit是survreg的便捷接口” ,我们可以通过定义{{1} }对象(这是很难的方法)。
无论如何,"Surv"
为{em>带来了survreg()
选项:“如果公式中没有cluster()项,则基于个人的独立性,使用健壮的'三明治'标准误差,基于并且robust=TRUE
也可以与robust=TRUE
一起使用,因为它会传递给AER::tobit()
。
首先,我们使自己确信,两种轨道方法都能得出相同的结果。
survreg()
现在比较-首先没有明显的标准错误:
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
基本上相同。