Question

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 with a linear regression for which I would like to find HAC standard errors. Any ideas? Should I write my own? Thanks!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top