我在网上找到了如何使用以下方法来应用赫特塞德松的稳健标准误差。
model<-lm(a~b+c+d,data = data)
plot(model, which=1)
bptest(a) #I have heterscedasticity
coeftest(model, vcov = vcovHC(model, type = "HC0")) #new coeff models
我试着用
plot(coeftest(model, vcov = vcovHC(model, type = "HC0")),which = 1)
看到残差图与新的系数,然而没有运气。你能帮助如何得到残差图与这种转变。
Robust标准误差只是改变了标准误差,这并不影响我们对系数的估计。因此残差将是相同的。我们可以检查一下。
#data
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
library(lmtest)
coeftest(lm.D9)
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.03200 0.22022 22.8501 9.547e-15 ***
groupTrt -0.37100 0.31143 -1.1913 0.249
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
coefs <- coeftest(lm.D9, vcov = vcovHC(lm.D9, type = "HC0"))
coefs
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.03200 0.17493 28.7662 <2e-16 ***
groupTrt -0.37100 0.29545 -1.2557 0.2253
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#check if estimates are the same, we see it in the input, but just to be really sure
coefs[1:2] == lm.D9$coefficients
(Intercept) groupTrt
TRUE TRUE