无法计算稳健的标准误差(vcovHC):多重共线性和NaN误差

时间:2015-03-13 08:50:32

标签: r standard-error robust

我有以下数据集:

share <- c(-0.16,-0.07,0,0,-0.06,-0.06,-0.18,-0.23,-0.07,-0.24,0,0,-0.22,-0.15,0,0,-0.09,-0.2,0,-0.19,0,-0.16,-0.24,-0.14,-0.22,-0.22,0,-0.18,0,0,-0.01,0,0,-0.14,0,-0.06,0,-0.12,0,0,-0.14,0,0,0,-0.02,0,0,0,0,0,-0.19,0,-0.21,-0.08,0,0,0,-0.1,-0.17,0,0,-0.13,-0.08,-0.1,0,-0.05,-0.06,0,0,-0.1,0,0,0,-0.16,0,-0.18,-0.04,-0.08,0,-0.06,0,0,0,-0.2,0,0,-0.08,0,0,-0.01,0,-0.16,-0.08,0,0,0,-0.02,-0.18,0.17,-0.2,-0.14,0,-0.24)
grade <- c(-22.64,-2.39,-15.3,-22.34,-6.39,5.25,0.47,33.61,-0.54,-25.21,16.41,-13.94,21.04,-19.64,-7.48,-32.18,-19.48,21.65,0.88,-1.6,28.49,13.61,-1.69,19.34,2.19,-7.25,6.65,7.25,20.56,16.25,17.24,12.3,3.7,-8.64,8.25,3.27,6,14.32,0.91,8.6,-6.84,13.35,6.99,3.36,0.29,19.46,2,10.75,8.76,-6.54,36.46,28.88,0.44,4.73,3.52,-10.7,-3.88,-2.36,-15.12,9.55,-4.96,10.7,6.84,-10.98,13.03,3.46,14.65,-1.66,6.89,-11.47,-6.52,15.64,3.02,4.11,-8.41,4.77,18.97,-3.73,9.54,-6.06,13.1,-24.62,-2.5,-30.26,3.82,12.97,4,2.21,14.33,12.47,-55.11,19.86,13.7,9.19,-11.01,-2.52,13.1,3.83,1.51,4.18,-3.14,-5.85,8.39)
treat <- c(0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0)
dataset <- as.data.frame(cbind(share, grade, treat))

我想运行以下线性模型,并使用sandwich包计算可靠的标准错误。

library(sandwich)
model <- lm(grade ~ treat + share + treat*share, dataset)
robSE <- sqrt(diag(vcovHC(model, type = "HC2")))

线性模型的输出很好,但不计算稳健的标准误差:为每个标准误差返回NaN

我的猜测是NaN归因于变量treatshare几乎完全共线(只有一个观察点treat=1和{{1 }})。问题是我必须使用这些变量;我无法取代它们。

是否有人可以考虑解决此问题的解决方法/解决方案?

1 个答案:

答案 0 :(得分:2)

在做了一些阅读并遵循@DominicComtois建议之后,我想在这里我将不得不使用HC1HC3HC4(Long和Ervin 2000,Hayes and Cai 2007)或HC4m(Cribari-Neto和Silva 2011)会更好,但它们都会给出NaN的结果。 HC0的问题在于它往往偏向于小到中等大样本(Hayes和Cai 2007,Cribari-Neto和Silva 2011)。

参考

Cribari-Neto F.,da Silva W.B. (2011年)。线性回归模型的一个新的异方差性一致性协方差矩阵估计器。 Adv Stat Anal 95:129-146。

Hayes,A。F.,&amp;蔡,L。(2007)。在OLS回归中使用异方差性 - 一致性标准误差估计:引入和软件实现。行为研究方法,39,709-722。

Long,J.S.,Ervin,L.H。(2000)。在线性回归模型中使用异方差性一致的标准误差。上午。统计。 54,217-224。