Calculate Newey-West standard errors without an an lm object in R
Update -- I closed this question and posted on crossvalidated.com.
I have found some good information on using the sandwich
package and the NeweyWest()
function to find heteroskedastic autocorrelation consistent (HAC) standard errors.
But NeweyWest()
only takes lm
objects.
> library(sandwich)
> NeweyWest(rnorm(100))
Error in UseMethod("estfun") :
no applicable method for 'estfun' applied to an object of class "c('double', 'numeric')"
>
I frequently get vectors of returns unassociated wit开发者_开发百科h a linear regression for which I would like to find HAC standard errors. Any ideas? Should I write my own? Thanks!
There's been a slight misunderstanding. I was thinking in terms of residuals, but what you asked is the standard error of the mean. That's easily obtained by modelling your vector against the intercept, or :
NeweyWest(lm(rnorm(100)~1))
For the standard deviation :
x <- rnorm(100)
NeweyWest(lm(x~1))*length(x)
Sorry for the misunderstanding, my bad.
精彩评论