Gera Kuiv
Gera Kuiv

Reputation: 31

How find a residual plot after applying heteroscedasticity robust errors

I found in the web how to apply hetersocedasticity robust standard errors using the following method

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

I tried to use

plot(coeftest(model, vcov = vcovHC(model, type = "HC0")),which = 1) 

to see the plot of residuals with new coefficients, however had no luck. Can you help how get a residual plot with this transformation.

Upvotes: 0

Views: 331

Answers (1)

Ahorn
Ahorn

Reputation: 3876

Robust standard errors only change the standard errors and this does not affect the estimate of our coefficients. Thus the residuals will be the same. We can check that:

#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

Upvotes: 1

Related Questions