我有以下数据集:
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
是由于变量treat
和share
几乎完全共线(只有一个观察结果,其中treat=1
和share!=0
)。问题是我必须使用这些变量;我无法替换它们。
有人能想到这个问题的解决方法/解决方案吗?