VARMAX models
This is a brief introduction notebook to VARMAX models in Statsmodels. The VARMAX model is generically specified as: $$ y_t = \nu + A_1 y_{t-1} + \dots + A_p y_{t-p} + B x_t + \epsilon_t + M_1 \epsilon_{t-1} + \dots M_q \epsilon_{t-q} $$
where $y_t$ is a $\text{k_endog} \times 1$ vector.
Model specification
The VARMAX
class in Statsmodels allows estimation of VAR, VMA, and VARMA models (through the order
argument), optionally with a constant term (via the trend
argument). Exogenous regressors may also be included (as usual in Statsmodels, by the exog
argument), and in this way a time trend may be added. Finally, the class allows measurement error (via the measurement_error
argument) and allows specifying either a diagonal or unstructured innovation covariance matrix (via the error_cov_type
argument).
Example 1: VAR
Below is a simple VARX(2) model in two endogenous variables and an exogenous series, but no constant term. Notice that we needed to allow for more iterations than the default (which is maxiter=50
) in order for the likelihood estimation to converge. This is not unusual in VAR models which have to estimate a large number of parameters, often on a relatively small number of time series: this model, for example, estimates 27 parameters off of 75 observations of 3 variables.
/Users/taugspurger/sandbox/statsmodels/statsmodels/tsa/base/tsa_model.py:171: ValueWarning: No frequency information was provided, so inferred frequency QS-OCT will be used.
% freq, ValueWarning)
Statespace Model Results
==================================================================================
Dep. Variable: ['dln_inv', 'dln_inc'] No. Observations: 75
Model: VARX(2) Log Likelihood 348.270
Date: Mon, 14 May 2018 AIC -670.540
Time: 21:45:05 BIC -640.413
Sample: 04-01-1960 HQIC -658.511
- 10-01-1978
Covariance Type: opg
===================================================================================
Ljung-Box (Q): 58.29, 41.41 Jarque-Bera (JB): 17.34, 10.35
Prob(Q): 0.03, 0.41 Prob(JB): 0.00, 0.01
Heteroskedasticity (H): 0.45, 1.13 Skew: 0.07, -0.55
Prob(H) (two-sided): 0.05, 0.77 Kurtosis: 5.35, 4.45
Results for equation dln_inv
====================================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------------
L1.dln_inv -0.2766 0.088 -3.141 0.002 -0.449 -0.104
L1.dln_inc 0.3241 0.621 0.522 0.601 -0.892 1.540
L2.dln_inv -0.1158 0.157 -0.738 0.461 -0.423 0.192
L2.dln_inc 0.4004 0.387 1.034 0.301 -0.359 1.159
beta.dln_consump 0.5566 0.753 0.739 0.460 -0.919 2.032
Results for equation dln_inc
====================================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------------
L1.dln_inv 0.0339 0.042 0.805 0.421 -0.049 0.117
L1.dln_inc 0.0928 0.132 0.700 0.484 -0.167 0.352
L2.dln_inv 0.0517 0.051 1.018 0.309 -0.048 0.151
L2.dln_inc 0.2731 0.169 1.617 0.106 -0.058 0.604
beta.dln_consump 0.4837 0.199 2.430 0.015 0.094 0.874
Error covariance matrix
============================================================================================
coef std err z P>|z| [0.025 0.975]
--------------------------------------------------------------------------------------------
sqrt.var.dln_inv 0.0441 0.003 14.176 0.000 0.038 0.050
sqrt.cov.dln_inv.dln_inc 0.0013 0.002 0.553 0.581 -0.003 0.006
sqrt.var.dln_inc -0.0127 0.001 -12.409 0.000 -0.015 -0.011
============================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
From the estimated VAR model, we can plot the impulse response functions of the endogenous variables.
Example 2: VMA
A vector moving average model can also be formulated. Below we show a VMA(2) on the same data, but where the innovations to the process are uncorrelated. In this example we leave out the exogenous regressor but now include the constant term.
/Users/taugspurger/sandbox/statsmodels/statsmodels/tsa/base/tsa_model.py:171: ValueWarning: No frequency information was provided, so inferred frequency QS-OCT will be used.
% freq, ValueWarning)
Statespace Model Results
==================================================================================
Dep. Variable: ['dln_inv', 'dln_inc'] No. Observations: 75
Model: VMA(2) Log Likelihood 353.887
+ intercept AIC -683.775
Date: Mon, 14 May 2018 BIC -655.965
Time: 21:45:10 HQIC -672.670
Sample: 04-01-1960
- 10-01-1978
Covariance Type: opg
===================================================================================
Ljung-Box (Q): 68.73, 39.27 Jarque-Bera (JB): 12.41, 13.31
Prob(Q): 0.00, 0.50 Prob(JB): 0.00, 0.00
Heteroskedasticity (H): 0.44, 0.81 Skew: 0.05, -0.48
Prob(H) (two-sided): 0.04, 0.60 Kurtosis: 4.99, 4.83
Results for equation dln_inv
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0182 0.005 3.794 0.000 0.009 0.028
L1.e(dln_inv) -0.2621 0.106 -2.482 0.013 -0.469 -0.055
L1.e(dln_inc) 0.5296 0.632 0.839 0.402 -0.708 1.768
L2.e(dln_inv) 0.0343 0.149 0.231 0.818 -0.257 0.326
L2.e(dln_inc) 0.1744 0.478 0.365 0.715 -0.762 1.111
Results for equation dln_inc
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0207 0.002 13.120 0.000 0.018 0.024
L1.e(dln_inv) 0.0482 0.042 1.158 0.247 -0.033 0.130
L1.e(dln_inc) -0.0780 0.139 -0.560 0.576 -0.351 0.195
L2.e(dln_inv) 0.0175 0.042 0.412 0.680 -0.066 0.101
L2.e(dln_inc) 0.1247 0.152 0.820 0.412 -0.173 0.423
Error covariance matrix
==================================================================================
coef std err z P>|z| [0.025 0.975]
----------------------------------------------------------------------------------
sigma2.dln_inv 0.0020 0.000 7.353 0.000 0.001 0.003
sigma2.dln_inc 0.0001 2.33e-05 5.833 0.000 9.01e-05 0.000
==================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
Caution: VARMA(p,q) specifications
Although the model allows estimating VARMA(p,q) specifications, these models are not identified without additional restrictions on the representation matrices, which are not built-in. For this reason, it is recommended that the user proceed with error (and indeed a warning is issued when these models are specified). Nonetheless, they may in some circumstances provide useful information.
/Users/taugspurger/sandbox/statsmodels/statsmodels/tsa/statespace/varmax.py:152: EstimationWarning: Estimation of VARMA(p,q) models is not generically robust, due especially to identification issues.
EstimationWarning)
/Users/taugspurger/sandbox/statsmodels/statsmodels/tsa/base/tsa_model.py:171: ValueWarning: No frequency information was provided, so inferred frequency QS-OCT will be used.
% freq, ValueWarning)
Statespace Model Results
==================================================================================
Dep. Variable: ['dln_inv', 'dln_inc'] No. Observations: 75
Model: VARMA(1,1) Log Likelihood 354.283
+ intercept AIC -682.567
Date: Mon, 14 May 2018 BIC -652.439
Time: 21:45:12 HQIC -670.537
Sample: 04-01-1960
- 10-01-1978
Covariance Type: opg
===================================================================================
Ljung-Box (Q): 68.76, 39.00 Jarque-Bera (JB): 10.81, 14.04
Prob(Q): 0.00, 0.52 Prob(JB): 0.00, 0.00
Heteroskedasticity (H): 0.43, 0.91 Skew: 0.00, -0.45
Prob(H) (two-sided): 0.04, 0.81 Kurtosis: 4.86, 4.91
Results for equation dln_inv
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0110 0.067 0.164 0.870 -0.120 0.142
L1.dln_inv -0.0055 0.722 -0.008 0.994 -1.421 1.410
L1.dln_inc 0.3587 2.788 0.129 0.898 -5.105 5.822
L1.e(dln_inv) -0.2537 0.734 -0.346 0.729 -1.691 1.184
L1.e(dln_inc) 0.1262 3.028 0.042 0.967 -5.809 6.061
Results for equation dln_inc
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0165 0.028 0.584 0.559 -0.039 0.072
L1.dln_inv -0.0344 0.288 -0.119 0.905 -0.599 0.530
L1.dln_inc 0.2348 1.144 0.205 0.837 -2.008 2.478
L1.e(dln_inv) 0.0904 0.295 0.307 0.759 -0.487 0.668
L1.e(dln_inc) -0.2390 1.177 -0.203 0.839 -2.545 2.067
Error covariance matrix
============================================================================================
coef std err z P>|z| [0.025 0.975]
--------------------------------------------------------------------------------------------
sqrt.var.dln_inv 0.0449 0.003 14.529 0.000 0.039 0.051
sqrt.cov.dln_inv.dln_inc 0.0017 0.003 0.641 0.522 -0.003 0.007
sqrt.var.dln_inc 0.0116 0.001 11.648 0.000 0.010 0.013
============================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).