Learn R Programming

gmm (version 1.0-2)

HAC: Covariance matrix of weakly dependent time series

Description

Function to compute a consistent covariance matrix of the sample mean of a random vector of time series. It is consistent in presence of heteroscedasticity and autocorrelation.

Usage

HAC(x, weights = weightsAndrews2, bw = bwAndrews2, prewhite = FALSE, ar.method = "ols", 
    kernel=c("Quadratic Spectral", "Truncated", "Bartlett", "Parzen", "Tukey-Hanning"), 
    approx="AR(1)",tol = 1e-7)

Arguments

x
a $n\times q$ matrix of time series, where n is the sample size.
weights
The method to compute the kernel weights. For now, weightsAndrews2 is the only one possible. I leave the option there because I am planning to give more choices in futur versions of the package.
bw
The method to compute the bandwidth parameter. By default it is bwAndrews2 which is proposed by Andrews (1991). The alternative is bwNeweyWest2 of Ne
prewhite
logical or integer. Should the estimating functions be prewhitened? If TRUE or greater than 0 a VAR model of order as.integer(prewhite) is fitted via ar with method "ols" and demean = F
ar.method
character. The method argument passed to ar for prewhitening.
kernel
The choice of kernel
approx
a character specifying the approximation method if the bandwidth has to be chosen by bwAndrews2.
tol
numeric. Weights that exceed tol are used for computing the covariance matrix, all other weights are treated as 0.

Value

  • A $q \times q$ matrix containing an estimator of the asymptotic variance of $\sqrt{n} \bar{x}$, where $\bar{x}$ is $q\times 1$ vector with typical element $\bar{x}_i = \frac{1}{n}\sum_{j=1}^nx_{ji}$. This function is called by gmm() but can also be used by itself.

Details

HAC is simply a modified version of meatHAC from the package sandwich. The modifications have been made so that the argument x can be a matrix instead of an object of class lm or glm. The details on how is works can be found on the sandwich manual.

References

Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1--16. URL http://www.jstatsoft.org/v16/i09/.

Newey WK & West KD (1987), A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix. Econometrica, 55, 703--708.

Newey WK & West KD (1994), Automatic Lag Selection in Covariance Matrix Estimation. Review of Economic Studies, 61, 631-653.

Examples

Run this code
x <- arima.sim(n=200,list(order=c(1,0,1),ar=.5,ma=.3,sd=.5))
y <- .4*x+rnorm(200)
x <- cbind(x,y)
vcov <- HAC(x)

Run the code above in your browser using DataLab