Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update summary when using NeweyWest?

Tags:

r

lm

summary

I am using NeweyWest standard errors to correct my lm() / dynlm() output. E.g.:

fit1<-dynlm(depvar~covariate1+covariate2)
coeftest(fit1,vcov=NeweyWest)

Coefficients are displayed the way I´d like to, but unfortunately I loose all the regression output information like R squared, F-Test etc. that is displayed by summary. So I wonder how I can display robust se and all the other stuff in the same summary output.

Is there a way to either get everything in one call or to overwrite the 'old' estimates? I bet I just missed something badly, but that is really relevant when sweaving the output.

Test example, taken from ?dynlm.

require(dynlm)
require(sandwich)
data("UKDriverDeaths", package = "datasets")
uk <- log10(UKDriverDeaths)
dfm <- dynlm(uk ~ L(uk, 1) + L(uk, 12))

#shows R-squared, etc.
summary(dfm)

#no such information
coeftest(dfm, vcov = NeweyWest)

btw.: same applies for vcovHC

like image 610
Matt Bannert Avatar asked Jul 14 '11 09:07

Matt Bannert


1 Answers

coefficients is just a matrix in the lm (or dynlm) summary object, so all you need to do is unclass the coeftest() output.

library(dynlm)
library(sandwich)
library(lmtest)
temp.lm <- dynlm(runif(100) ~ rnorm(100))
temp.summ <- summary(temp.lm)
temp.summ$coefficients <- unclass(coeftest(temp.lm, vcov. = NeweyWest))
like image 143
Richard Herron Avatar answered Sep 19 '22 09:09

Richard Herron