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.
Statespace Model Results
==================================================================================
Dep. Variable: ['dln_inv', 'dln_inc'] No. Observations: 75
Model: VARX(2) Log Likelihood 348.269
Date: Tue, 28 Feb 2017 AIC -670.537
Time: 21:35:16 BIC -640.410
Sample: 04-01-1960 HQIC -658.508
- 10-01-1978
Covariance Type: opg
===================================================================================
Ljung-Box (Q): 59.41, 42.46 Jarque-Bera (JB): 16.41, 13.03
Prob(Q): 0.02, 0.37 Prob(JB): 0.00, 0.00
Heteroskedasticity (H): 0.46, 1.03 Skew: 0.05, -0.64
Prob(H) (two-sided): 0.06, 0.95 Kurtosis: 5.29, 4.59
Results for equation dln_inv
====================================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------------
L1.dln_inv -0.2773 0.088 -3.149 0.002 -0.450 -0.105
L1.dln_inc 0.3374 0.620 0.544 0.586 -0.877 1.552
L2.dln_inv -0.1160 0.157 -0.740 0.459 -0.423 0.191
L2.dln_inc 0.3971 0.387 1.025 0.305 -0.362 1.156
beta.dln_consump 0.5448 0.752 0.724 0.469 -0.929 2.019
Results for equation dln_inc
====================================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------------
L1.dln_inv 0.0335 0.042 0.794 0.427 -0.049 0.116
L1.dln_inc 0.0962 0.133 0.726 0.468 -0.164 0.356
L2.dln_inv 0.0516 0.051 1.017 0.309 -0.048 0.151
L2.dln_inc 0.2734 0.169 1.622 0.105 -0.057 0.604
beta.dln_consump 0.4818 0.198 2.427 0.015 0.093 0.871
Error covariance matrix
============================================================================================
coef std err z P>|z| [0.025 0.975]
--------------------------------------------------------------------------------------------
sqrt.var.dln_inv 0.0441 0.003 14.164 0.000 0.038 0.050
sqrt.cov.dln_inv.dln_inc 0.0013 0.002 0.549 0.583 -0.003 0.006
sqrt.var.dln_inc -0.0127 0.001 -12.420 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.
Statespace Model Results
==================================================================================
Dep. Variable: ['dln_inv', 'dln_inc'] No. Observations: 75
Model: VMA(2) Log Likelihood 353.887
+ intercept AIC -683.775
Date: Tue, 28 Feb 2017 BIC -655.965
Time: 21:35:20 HQIC -672.670
Sample: 04-01-1960
- 10-01-1978
Covariance Type: opg
===================================================================================
Ljung-Box (Q): 68.49, 39.14 Jarque-Bera (JB): 12.79, 13.08
Prob(Q): 0.00, 0.51 Prob(JB): 0.00, 0.00
Heteroskedasticity (H): 0.44, 0.81 Skew: 0.06, -0.48
Prob(H) (two-sided): 0.04, 0.60 Kurtosis: 5.02, 4.81
Results for equation dln_inv
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0182 0.005 3.800 0.000 0.009 0.028
L1.e(dln_inv) -0.2572 0.106 -2.430 0.015 -0.465 -0.050
L1.e(dln_inc) 0.5135 0.633 0.812 0.417 -0.726 1.753
L2.e(dln_inv) 0.0295 0.149 0.198 0.843 -0.263 0.322
L2.e(dln_inc) 0.1819 0.475 0.383 0.702 -0.749 1.113
Results for equation dln_inc
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0207 0.002 13.087 0.000 0.018 0.024
L1.e(dln_inv) 0.0487 0.042 1.173 0.241 -0.033 0.130
L1.e(dln_inc) -0.0789 0.139 -0.568 0.570 -0.351 0.193
L2.e(dln_inv) 0.0176 0.042 0.415 0.678 -0.066 0.101
L2.e(dln_inc) 0.1290 0.153 0.844 0.399 -0.170 0.428
Error covariance matrix
==================================================================================
coef std err z P>|z| [0.025 0.975]
----------------------------------------------------------------------------------
sigma2.dln_inv 0.0020 0.000 7.351 0.000 0.001 0.003
sigma2.dln_inc 0.0001 2.33e-05 5.822 0.000 9e-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.
/private/tmp/statsmodels/statsmodels/tsa/statespace/varmax.py:153: EstimationWarning: Estimation of VARMA(p,q) models is not generically robust, due especially to identification issues.
EstimationWarning)
Statespace Model Results
==================================================================================
Dep. Variable: ['dln_inv', 'dln_inc'] No. Observations: 75
Model: VARMA(1,1) Log Likelihood 354.291
+ intercept AIC -682.583
Date: Tue, 28 Feb 2017 BIC -652.455
Time: 21:35:24 HQIC -670.553
Sample: 04-01-1960
- 10-01-1978
Covariance Type: opg
===================================================================================
Ljung-Box (Q): 69.15, 40.99 Jarque-Bera (JB): 11.03, 18.14
Prob(Q): 0.00, 0.43 Prob(JB): 0.00, 0.00
Heteroskedasticity (H): 0.45, 0.78 Skew: 0.01, -0.52
Prob(H) (two-sided): 0.05, 0.54 Kurtosis: 4.88, 5.17
Results for equation dln_inv
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0103 0.064 0.161 0.872 -0.115 0.135
L1.dln_inv -0.0059 0.685 -0.009 0.993 -1.349 1.337
L1.dln_inc 0.3915 2.708 0.145 0.885 -4.916 5.699
L1.e(dln_inv) -0.2446 0.696 -0.352 0.725 -1.608 1.119
L1.e(dln_inc) 0.1210 2.963 0.041 0.967 -5.686 5.928
Results for equation dln_inc
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
const 0.0164 0.026 0.619 0.536 -0.036 0.068
L1.dln_inv -0.0318 0.273 -0.116 0.907 -0.568 0.504
L1.dln_inc 0.2372 1.079 0.220 0.826 -1.878 2.352
L1.e(dln_inv) 0.0872 0.280 0.312 0.755 -0.461 0.636
L1.e(dln_inc) -0.2367 1.115 -0.212 0.832 -2.422 1.949
Error covariance matrix
============================================================================================
coef std err z P>|z| [0.025 0.975]
--------------------------------------------------------------------------------------------
sqrt.var.dln_inv 0.0449 0.003 14.510 0.000 0.039 0.051
sqrt.cov.dln_inv.dln_inc 0.0017 0.003 0.654 0.513 -0.003 0.007
sqrt.var.dln_inc 0.0116 0.001 11.775 0.000 0.010 0.013
============================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).