VARXResult#

class cultivars.multivariate.reduced_form.vector_autoregression.VARXResult(*, endog, names, order, trend, sigma_u, sigma_ml, resid, fittedvalues, design, llf, nobs, n_params, posterior=None, prior_label='none', coefficients, deterministic, exog, exog_names, exog_order, exog_coefficients)[source]

Bases: _VectorResult, _SummaryMixin, _ComparisonMixin, _VectorInferenceMixin, _VectorPropagationMixin

A fitted vector autoregression with exogenous regressors.

The estimated system is

\[y_t = D d_t + \sum_{i=1}^{p} A_i y_{t-i} + \sum_{j=0}^{s} B_j x_{t-j} + u_t, \qquad u_t \sim (0, \Sigma_u),\]

with the distributed lag of \(x\) appended to the design after the endogenous lags. Everything the reduced-form surface offers is inherited unchanged, because the exogenous block does not enter the moving-average representation: irf, fevd, historical_decomposition, granger_causality, stability_check and residual_diagnostics read the endogenous dynamics and are therefore the same objects they are for a plain VAR on \((A_1, \dots, A_p, \Sigma_u)\).

forecast() is the exception, and it is the only new behaviour in the model. A VARX forecast is conditional on a path for \(x\), and this class has no model of \(x\) to supply one, so it asks for the path and refuses without it.

Note

Granger causality is a test between endogenous variables. An exogenous regressor cannot be named as a cause, because its block is conditioned on rather than modelled; the coefficient on it and its lags, with standard errors, is in params, bse and equation().

Variables:
  • endog – The (n, k) endogenous sample.

  • exog – The (n, m) exogenous sample, aligned on the same index.

  • names – Endogenous labels, in Cholesky order.

  • exog_names – Exogenous labels.

  • order – Endogenous autoregressive order p.

  • exog_order – Exogenous lags s beyond the contemporaneous term.

  • trend – "n", "c" or "ct".

  • coefficients – (p, k, k) stack of A_1, ..., A_p.

  • exog_coefficients – (s + 1, k, m) stack of B_0, ..., B_s.

  • deterministic – (d, k) deterministic coefficients.

  • sigma_u – Residual covariance with the degrees-of-freedom correction.

  • sigma_ml – Residual covariance divided by the effective sample.

  • resid – (nobs, k) residuals over the effective sample.

  • fittedvalues – (nobs, k) one-step conditional means.

  • design – (nobs, d + kp + m(s + 1)) regressor matrix as estimated.

  • llf – Gaussian log-likelihood.

  • nobs – Effective sample size n - max(p, s).

  • n_params – Free parameters, covariance included.

See also

  • VARX – the model whose fit() returns this record.

  • VARResult – the surface this record inherits.

  • GVAR – consumes to_varx() to close conditional units into one system.

References

Lütkepohl, H. (2005). New Introduction to Multiple Time Series Analysis. Springer. Chapter 10.

Example

A bivariate system driven by one exogenous series that hits the first equation on impact and the second with a lag. The fit recovers both impact matrices, the fitted values are the design applied row by row, and the forecast needs the future path:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> A = np.array([[0.5, 0.2], [0.0, 0.4]])
>>> B0, B1 = np.array([[1.0], [0.0]]), np.array([[0.0], [0.5]])
>>> x = rng.standard_normal((200, 1))
>>> y = np.zeros((200, 2))
>>> for t in range(1, 200):
...     y[t] = A @ y[t - 1] + B0 @ x[t] + B1 @ x[t - 1] + 0.3 * rng.standard_normal(2)
>>> res = VARX(y, x, order=1, exog_order=1, names=("a", "b"), exog_names=("z",)).fit()
>>> res.exog_coefficients.shape, res.k_exog, res.nobs, res.n_params
((2, 2, 1), 1, 199, 13)
>>> bool(np.abs(res.exog_coefficients[0] - B0).max() < 0.1)
True
>>> bool(np.abs(res.exog_coefficients[1] - B1).max() < 0.1)
True
>>> fitted = (
...     res.deterministic[0]
...     + y[:-1] @ res.coefficients[0].T
...     + x[1:] @ res.exog_coefficients[0].T
...     + x[:-1] @ res.exog_coefficients[1].T
... )
>>> bool(np.allclose(fitted, res.fittedvalues))
True
>>> res.forecast(2, exog_future=np.zeros((2, 1))).shape
(2, 2)
>>> res.forecast(2)
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: a VARX forecast is conditional on the ...

Private methods#

_comparison_label()

Short specification label for a ranking table.

_from_fit(fit, model)

Assemble the public result from the internal fit and its model.

_summary_table()

Structured summary rendered by every display path.

_trailing_blocks()

The distributed-lag coefficients, in design order.

_trailing_labels()

Distributed-lag column names, contemporaneous term first.