Performs LM tests for error AC in VAR models. The code is based on Paul Catani's original R code used in the paper Wild Bootstrap Tests for Autocorrelation in Vector Autoregressive Models (Ahlgren and Catani, 2016).
ACtest(fit, h = 4, HCtype = c("LM", "HC0", "HC1", "HC2", "HC3"), univariate = FALSE)
# S3 method for ACtest
print(x, ...)
a list of class "ACtest"
.
the fit
argument object.
the type of object of fit
.
a vector of the HCtype
's used.
the lag length of the alternative VAR(h) model for the errors.
a 1 x 5 matrix of the P. values of the tests.
a 1 x 5 matrix of the Q statistics of the tests.
a K x 5 matrix of the P. values of the univariate tests.
a K x 5 matrix of the Q statistics of the univariate tests.
the 'univariate' argument.
who ran the test and when.
computation time taken to run the test.
how the function ACtest()
was called.
an object of class "VARfit"
that was returned by the VARfit
function, or an object of class "verest"
from the function vars::VAR
in the vars package.
the lag length of the alternative VAR(h) model for the errors.
a vector containing some or all (default) of "LM"
, "HC0"
, "HC1"
, "HC2"
and "HC3"
. The "LM"
type assumes homoscedastic errors, while the "HC"
types are different Heteroskedasticity-consistent tests (see 'Details').
either FALSE
, TRUE
, or "only"
. If TRUE
, the test will also be performed in its univariate form, if "only"
, only the univariate version will be used.
Object with class attribute ‘ACtest’.
further arguments passed to or from other methods.
To run the wild bootstrap version of the test, please use the output from this function with the function wildBoot
.
Mathematical details
The tests for error AC are based on the least squares (LS) residuals from the \(K\)-dimensional vector autoregressive (VAR) model with \(p\) lags (abstracting from deterministic terms):
$$ \mathbf{y}_{t}=\mathbf{\Pi }_{1}\mathbf{y}_{t-1}+\cdots +\mathbf{\Pi }_{p} \mathbf{y}_{t-p}+\mathbf{u}_{t},\quad \text{E}(\mathbf{u}_{t})=\mathbf{0} ,\quad \text{E}(\mathbf{u}_{t}\mathbf{u}_{t}^{\prime })=\mathbf{\Omega},\ \ \ \ t=1,\ldots ,N. $$
The LS residuals are
$$ \widehat{\mathbf{u}}_{t}=\mathbf{y}_{t}-\widehat{\mathbf{\Pi }}_{1}\mathbf{y} _{t-1}-\cdots -\widehat{\mathbf{\Pi }}_{p}\mathbf{y}_{t-p}, $$ where \(\widehat{\mathbf{\Pi }}_{1},\ldots ,\widehat{\mathbf{\Pi }}_{p}\) are the LS estimates of the \(K\times K\) parameter matrices \(\mathbf{\Pi } _{1},\ldots ,\mathbf{\Pi }_{p}\).
The LM statistic is computed from the auxilary model
$$ \widehat{\mathbf{u}}_{t}=\mathbf{\Pi }_{1}\mathbf{y} _{t-1}+\cdots +\mathbf{\Pi }_{p}\mathbf{y}_{t-p} + \mathbf{D}_{1}\widehat{\mathbf{u}}_{t-1}+\cdots +% \mathbf{D}_{h}\widehat{\mathbf{u}}_{t-h}+\mathbf{e}_{t} $$ $$ =(\mathbf{Z}_{t-1}^{\prime }\otimes \mathbf{I}_{K})\boldsymbol{\phi }+(\widehat{% \mathbf{U}}_{t-1}^{\prime }\otimes \mathbf{I}_{K})\boldsymbol{\psi }+\mathbf{e}% _{t}, \ $$ where \(\mathbf{Z}_{t-1}=(\mathbf{y}_{t-1}^{\prime },\ldots ,\mathbf{y}_{t-p}^{\prime })^{\prime }\), \(\boldsymbol{\phi } =\text{vec}(\mathbf{Pi}_{1},\ldots ,\mathbf{Pi}_{p})^{\prime }\), \(\widehat{\mathbf{U}}% _{t-1}=(\widehat{\mathbf{u}}_{t-1}^{\prime },\ldots ,\widehat{% \mathbf{u}}_{t-h}^{\prime })^{\prime }\) and \(\boldsymbol{\psi } =\text{vec}(\mathbf{D}_{1},\ldots ,\mathbf{D}_{h})^{\prime }\). The symbol \(\otimes \) denotes the Kronecker product and the symbol vec denotes the column vectorisation operator. The first \(h\) values of the residuals \(\widehat{\mathbf{u}}_{t}\) are set to zero in the auxiliary model, so that the series length is equal to the series length in the original VAR model.
The LM statistic for error AC of order \(h\) is given by $$ Q_{\text{LM}}(h) = N \widehat{\boldsymbol{\psi}}^{\prime} \bigl(\widehat{\boldsymbol{\Sigma}}^{\psi\psi}\bigr)^{-1} \widehat{\boldsymbol{\psi}} $$
where \(\widehat{\boldsymbol{\psi }}\) is the LS estimate of \(\boldsymbol{\psi } \) and \(\widehat{\boldsymbol{\Sigma }}^{\psi \psi }\) is the block of
$$ \left( N^{-1}\sum_{t=1}^{N}\left[ \begin{array}{c} \mathbf{Z}_{t-1}\otimes \mathbf{I}_{K} \\ \widehat{\mathbf{U}}_{t-1}\otimes \mathbf{I}_{K}% \end{array}% \right] \widehat{\boldsymbol{\Sigma }}_{\mathbf{u}}^{-1}\left[ \begin{array}{cc} \mathbf{Z}_{t-1}^{\prime }\otimes \mathbf{I}_{K} & \widehat{\mathbf{U}}% _{t-1}^{\prime }\otimes \mathbf{I}_{K}% \end{array}% \right] \right) ^{-1} $$ corresponding to \(\boldsymbol{\psi }\). Here \(\widehat{\boldsymbol{\Sigma }}_{\mathbf{u}% }=N^{-1}\sum_{t=1}^{N}\widehat{\mathbf{u}}_{t}\widehat{\mathbf{u}}% _{t}^{\prime }\) is the estimator of the error covariance matrix from the VAR model.
The multivariate heteroskedasticity-consistent covariance matrix estimator (HCCME) for the auxilary model is given by (Hafner and Herwartz 2009) $$ \mathbf{V}_{N}^{-1}\mathbf{W}_{N}\mathbf{V}_{N}^{-1} = (\boldsymbol{\Gamma}_{N}\otimes \mathbf{I}_{K})^{-1} \mathbf{W}_{N} (\boldsymbol{\Gamma}_{N}\otimes \mathbf{I}_{K})^{-1} $$
where $$ \mathbf{V}_{N} =\boldsymbol{\Gamma }_{N}\otimes \mathbf{I}_{K}, $$ $$ \boldsymbol{\Gamma }_{N} =\frac{1}{N}\sum_{t=1}^{N}\left( \begin{array}{c} \widehat{\mathbf{U}}_{t-1} \\ \mathbf{Z}_{t-1}% \end{array}% \right) \left( \begin{array}{cc} \widehat{\mathbf{U}}_{t-1}^{\prime } & \mathbf{Z}_{t-1}^{\prime }% \end{array}% \right) , $$ $$ \mathbf{W}_{N} =\frac{1}{N}\sum_{t=1}^{N}\left( \begin{array}{c} \widehat{\mathbf{U}}_{t-1} \\ \mathbf{Z}_{t-1}% \end{array}% \right) \left( \begin{array}{cc} \widehat{\mathbf{U}}_{t-1}^{\prime } & \mathbf{Z}_{t-1}^{\prime }% \end{array}% \right) \otimes (\widehat{\mathbf{u}}_{t}\widehat{\mathbf{u}}_{t}^{\prime }). $$
The HCCME-based LM statistics for error AC are obtained from the expression for \(Q_{\text{LM}}(h)\) by replacing \(\widehat{\boldsymbol{\Sigma }}^{\psi \psi }\) by the block of \(% \mathbf{V}_{N}^{-1}\mathbf{W}_{N}\mathbf{V}_{N}^{-1}=(\Gamma _{N}\otimes \mathbf{I}_{K})^{-1}\mathbf{W}_{N}(\Gamma _{N}\otimes \mathbf{I}_{K})^{-1}\) corresponding to \(\boldsymbol{\psi }\) and with \(% \widehat{\mathbf{u}}_{t}\) defined by \(HC_{0}\), \(HC_{1}\), \(HC_{2}\) and \(HC_{3} \), respectively.
\(HC_{0}\) uses \(\widehat{\mathbf{u}}_{t}\widehat{\mathbf{u}}_{t}^{\prime }\). \(HC_{1}\) multiplies the elements of \(\widehat{\mathbf{u}}_{t}\widehat{\mathbf{u}}_{t}^{\prime }\) by \(N/(N-Kp)\). \(HC_{2}\) replaces \(\widehat{% \mathbf{u}}_{t}\) by \(\widehat{\mathbf{u}}_{t}/(1-h_{t})^{1/2}\), where \(h_{t}=\mathbf{Z}_{t}(\mathbf{Z}^{\prime }\mathbf{Z})^{-1}\mathbf{Z}_{t}^{\prime }\) is the \(t\)th diagonal element of \(\mathbf{Z}(\mathbf{Z}^{\prime }\mathbf{Z})^{-1}\mathbf{Z}^{\prime }\), and \(\mathbf{% Z}=(\mathbf{Z}_{0},\ldots ,\mathbf{Z}_{N-1})\). \(HC_{3}\) replaces \(\widehat{\mathbf{u}}_{t}\) by \(\widehat{\mathbf{u}}_{t}/(1-h_{t})\).
See MacKinnon and White (1985) for details.
The recursive-design wild bootstrap (WB) tests for error AC are computed using Algorithm 1 in Ahlgren and Catani (2016). The Fixed-design WB tests for error AC are computed using Algorithm 2 in Ahlgren and Catani (2016).
Ahlgren, N. & Catani, P. (2016). Wild bootstrap tests for autocorrelation in vector autoregressive models. Stat Papers, <doi:10.1007/s00362-016-0744-0>.
Hafner, C. M. and Herwartz, H., (2009). Testing for Linear Vector Autoregressive Dynamics under Multivariate Generalized Autoregressive Heteroskedasticity. Stat Neerl, 63, 294--323
MacKinnon, J. G. and White, H. (1985). Some Heteroskedasticity Consistent Covariance Matrix Estimators with Improved Finite Sample Properties. J Econom, 29, 305--325
VARfit
to estimate a VAR(p), and wildBoot
to run the Wild Bootstrap versions of the tests.
fit <- VARfit(y = VodafoneCDS, p = 3, const = TRUE, trend = FALSE)
test <- ACtest(fit = fit, h = 1, HCtype = c("LM", "HC0", "HC1", "HC2", "HC3"))
test
Run the code above in your browser using DataLab