HAC: HAC Covariance Matrix Estimation 'HAC' computes the central...

Description Usage Arguments Value Source Examples

View source: R/hac.r

Description

HAC Covariance Matrix Estimation HAC computes the central quantity (the meat) in the HAC covariance matrix estimator, also called sandwich estimator. HAC is the abbreviation for "heteroskedasticity and autocorrelation consistent".

Usage

1
HAC(mcond, method = "Bartlett", bw)

Arguments

mcond

a q-dimensional multivariate time series. In the case of OLS regression with q regressors mcond contains the series of the form regressor*residual (see example below).

method

kernel function, choose between "Truncated", "Bartlett", "Parzen", "Tukey-Hanning", "Quadratic Spectral".

bw

bandwidth parameter, controls the number of lags considered in the estimation.

Value

mat a (q,q)-matrix

Source

Heberle, J. and Sattarhoff, C. (2017) <doi:10.3390/econometrics5010009> "A Fast Algorithm for the Computation of HAC Covariance Matrix Estimators"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 
data(MUSKRAT)
y <- ts(log10(MUSKRAT))
n <- length(y)
t <- c(1:n)
t2 <- t^2
out2 <- lm(y ~ t +t2)
mat_xu <- matrix(c(out2$residuals,t*out2$residuals, t2*out2$residuals),nrow=62,ncol=3)
hac <- HAC(mat_xu, method="Bartlett", 4)

mat_regr<- matrix(c(rep(1,62),t,t2),nrow=62,ncol=3)
mat_q <- t(mat_regr)%*%mat_regr/62
vcov_HAC <- solve(mat_q)%*%hac%*%solve(mat_q)/62
# vcov_HAC is the HAC covariance matrix estimation for the OLS coefficients. 

Example output

Loading required package: Matrix
Loading required package: vars
Loading required package: MASS
Loading required package: strucchange
Loading required package: zoo

Attaching package:zooThe following objects are masked frompackage:base:

    as.Date, as.Date.numeric

Loading required package: sandwich
Loading required package: urca
Loading required package: lmtest
Loading required package: fftwtools

tsapp documentation built on Oct. 30, 2021, 5:08 p.m.

Related to HAC in tsapp...