16

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

Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
  • 4
    So we're clear, is that `dynlm` from the `dynlm` package, `NeweyWest` from the `sandwich` package, and `coeftest` from the `lmtest` package? – Richie Cotton Jul 14 '11 at 10:15
  • 1
    @ran2, can you please add the necessary `library` or `require` statements to your question so that it becomes reproducible? – Andrie Jul 14 '11 at 10:29
  • sorry guys... thought with the stomach.. lunchtime and I was starving. edited my post. Thank you @Richie Cotton for helping out! – Matt Bannert Jul 14 '11 at 11:13

2 Answers2

18

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))
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
Richard Herron
  • 9,760
  • 12
  • 69
  • 116
  • thx so much, unclass was exactly the piece I was missing. sry for the delayed accept though. – Matt Bannert Aug 11 '11 at 07:41
  • Does Newey West change the estimator though? All I see is that it changes the covariance of the estimator, which in turn changes hypothesis testing... – Ye Tian Mar 20 '16 at 15:26
  • @YeTian No it doesn't change the estimators as far as I know. It only changes the hypothesis testing and confidence intervals. – WillZ Dec 22 '16 at 22:58
0

If you specify the covariance matrix, the F-statistics change and you need to compute it again using waldtest() right? Because

temp.summ$coefficients <- unclass(coeftest(temp.lm, vcov. = NeweyWest))

only overwrites the coefficients. F-statistics change but R^2 remains the same .

Jason Tyler
  • 1,331
  • 13
  • 26