[R] Robust covariance matrix with NeweyWest()
Achim Zeileis
Achim.Zeileis at uibk.ac.at
Wed Sep 28 22:08:18 CEST 2011
On Wed, 28 Sep 2011, Andreas Klein wrote:
> Dear R-users,
>
> I would like to compute a robust covariance matrix of two series of
> realizations of random variables:
>
> ###Begin Example###
>
> data <- cbind(rnorm(100), rnorm(100))
> model <- lm(data ~ 1)
> vcov(model)
>
> library(sandwich)
> NeweyWest(model) #produces an error
>
>
> ###End Example###
>
> NeweyWest() produces an error but sandwich(), vcovHAC(), kernHAC,
> weave(),... do not produce any errors. It seems that the model object
> does not fit in that special case.
Short version: This is/was a bug. A fixed version has just been released
on the CRAN master site.
Medium version: Until binary packages are available (if needed), you can
work around the bug by computing the truncation lag by hand.
NeweyWest(model, lag = floor(bwNeweyWest(model, weights = 1)))
Long version: In the bandwidth selection -- function bwNeweyWest() --
estimating/score functions pertaining to intercepts are omitted by default
(following Newey & West's advice). This is, of course, unless there is
only an intercept in which case its estimating/score function is used. The
code handled this correctly in models with one intercept but not in mlm
objects which can have two intercept scores (and no other regressors), as
in your case. Fixed now.
Best,
Z
>
> Nevertheless, the problem is that I need the robust version of the covariance matrix according to Newey and West (1987, 1994).
>
> Any ideas or suggestions to solve the problem?
>
> Kind regards,
> Andy
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list