Convenience function for computing the long-run variance (matrix) of a (possibly multivariate) series of observations.
lrvar(x, type = c("Andrews", "Newey-West"), prewhite = TRUE, adjust = TRUE, ...)
numeric vector, matrix, or time series.
lrvar is a simple wrapper function for computing the long-run variance
(matrix) of a (possibly multivariate) series
x. First, this simply fits
a linear regression model
x ~ 1 by
the corresponding variance of the mean(s) is estimated either by
(Andrews quadratic spectral kernel HAC estimator) or by
(Newey-West Bartlett HAC estimator).
For a univariate series
x a scalar variance is computed. For a
x the covariance matrix is computed.
suppressWarnings(RNGversion("3.5.0")) set.seed(1) ## iid series (with variance of mean 1/n) ## and Andrews kernel HAC (with prewhitening) x <- rnorm(100) lrvar(x) #>  0.007958048 ## analogous multivariate case with Newey-West estimator (without prewhitening) y <- matrix(rnorm(200), ncol = 2) lrvar(y, type = "Newey-West", prewhite = FALSE) #> [,1] [,2] #> [1,] 0.0097884718 0.0005978738 #> [2,] 0.0005978738 0.0073428222 ## AR(1) series with autocorrelation 0.9 z <- filter(rnorm(100), 0.9, method = "recursive") lrvar(z) #>  0.4385546