开发者

Calculate Newey-West standard errors without an an lm object in R

开发者 https://www.devze.com 2023-01-29 13:50 出处:网络
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 autocorrelatio

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号