[R-SIG-Finance] Vector autoregression with Newey-West standard errors
Liviu Andronic
landronimirc at gmail.com
Tue Jun 9 18:35:32 CEST 2009
Dear all,
I'm currently fitting vector autoregression using VAR() from package
`vars'. It estimates VAR by using OLS, and by default it provides
"naive" standard errors (not HC and not HAC).
> require(vars)
> data(Canada)
> Canada <- (as.data.frame(Canada))
> head(Canada)
e prod rw U
1 929.6 405.4 386.1 7.53
2 929.8 404.6 388.1 7.70
3 930.3 403.8 390.5 7.47
4 931.4 404.2 394.0 7.27
5 932.7 405.0 396.8 7.37
6 933.6 404.4 400.0 7.13
> temp <- VAR(Canada[,1:3], p = 1, type = "const")
> coef(temp)
$e
Estimate Std. Error t value Pr(>|t|)
e.l1 0.923983 0.023492 39.3313 1.202e-53
prod.l1 0.155238 0.028725 5.4043 6.697e-07
rw.l1 0.008184 0.006824 1.1992 2.340e-01
const 5.255418 13.451377 0.3907 6.971e-01
$prod
Estimate Std. Error t value Pr(>|t|)
e.l1 -0.06662 0.032275 -2.064 4.229e-02
prod.l1 1.02613 0.039463 26.002 1.777e-40
rw.l1 0.02744 0.009376 2.926 4.478e-03
const 40.29543 18.480012 2.180 3.220e-02
$rw
Estimate Std. Error t value Pr(>|t|)
e.l1 0.1568 0.03650 4.296 4.907e-05
prod.l1 -0.1394 0.04463 -3.124 2.496e-03
rw.l1 0.9362 0.01060 88.303 1.012e-80
const -62.0937 20.89779 -2.971 3.928e-03
However, I would like to obtain Heteroskedasticity-Autocorrelation
Consistent standard errors using NeweyWest() from package `sandwich',
which handles principally `lm' and `glm' objects. I noticed that the
VAR() returns an object of class `varest', which contains a list of
fitted `lm' objects. So I tried to apply NeweyWest() to individual
`lm' components of `varest', unsuccessfully.
> class(temp)
[1] "varest"
> class(temp$varresult$e)
[1] "lm"
> temp.lm <- temp$varresult$e
> class(temp.lm)
[1] "lm"
> require(sandwich)
> NeweyWest(temp.lm)
Error in AA %*% t(X) : requires numeric matrix/vector arguments
In addition: Warning message:
In ar.ols(x, aic = aic, order.max = order.max, na.action = na.action, :
model order: 1singularities in the computation of the projection
matrixresults are only valid up to model order0
> vcovHAC(temp.lm)
Error in bread. %*% meat. : non-conformable arguments
I would have expected the above to have worked. For "standard" `lm'
objects, I never had any such issues:
> temp.std.lm <- lm(e ~ prod + rw, data=Canada)
> class(temp.std.lm)
[1] "lm"
> NeweyWest(temp.std.lm) # the variance-covariance matrix of the estimates
(Intercept) prod rw
(Intercept) 30738.384 -83.52869 7.65428
prod -83.529 0.23111 -0.02458
rw 7.654 -0.02458 0.00539
> require(lmtest)
> coeftest(temp.std.lm, df = Inf, vcov = NeweyWest) # NW std errs for regression coefs
z test of coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 476.4344 175.3237 2.72 0.00658 **
prod 0.8819 0.4807 1.83 0.06659 .
rw 0.2454 0.0734 3.34 0.00083 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Could anyone suggest a way to work around this error? Thank you,
Liviu
PS I am also cc-ing this message to the authors of `vars' and
`sandwich', Bernhard Pfaff and Achim Zeileis, respectively. Perhaps
they could shed some light on the issue.
> sessionInfo()
R version 2.8.1 (2008-12-22)
i686-pc-linux-gnu
locale:
LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C
attached base packages:
[1] grid splines tcltk stats graphics grDevices datasets
[8] utils methods base
other attached packages:
[1] Matrix_0.999375-23 relimp_1.0-1
[3] dse1_2008.10-1 tframe_2009.2-1
[5] setRNG_2008.3-1 lmtest_0.9-24
[7] vars_1.4-5 urca_1.2-2
[9] strucchange_1.3-7 sandwich_2.2-1
[11] zoo_1.5-6 MASS_7.2-47
[13] abind_1.1-0 RcmdrPlugin.TeachingDemos_1.0-3
[15] TeachingDemos_2.3 RcmdrPlugin.HH_1.1-24
[17] HH_2.1-29 leaps_2.9
[19] multcomp_1.0-8 mvtnorm_0.9-7
[21] lattice_0.17-25 RcmdrPlugin.IaeTlse_0.1-3
[23] RcmdrPlugin.Export_0.3-0 Design_2.2-0
[25] survival_2.35-4 Hmisc_3.6-0
[27] xtable_1.5-5 Rcmdr_1.4-10
[29] car_1.2-14 JGR_1.6-4
[31] iplots_1.1-3 JavaGD_0.5-2
[33] rJava_0.6-2 fortunes_1.3-6
[35] ctv_0.5-2 PolynomF_0.93
loaded via a namespace (and not attached):
[1] cluster_1.12.0 nlme_3.1-92 tools_2.8.1
More information about the R-SIG-Finance
mailing list