R 应用异方差稳健误差后如何找到残差图
我在网上找到了如何使用以下方法应用异质性稳健标准误差R 应用异方差稳健误差后如何找到残差图,r,linear-regression,R,Linear Regression,我在网上找到了如何使用以下方法应用异质性稳健标准误差 model稳健标准误差只会改变标准误差,这不会影响我们系数的估计。因此,残差将是相同的。我们可以检查: #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("C
model稳健标准误差只会改变标准误差,这不会影响我们系数的估计。因此,残差将是相同的。我们可以检查:
#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
#数据
ctl