VAR#

class cultivars.multivariate.reduced_form.vector_autoregression.VAR(endog, *, order, trend='c', names=None, prior=None)[source]

Bases: _VectorAutoRegressionModel[VARResult]

Reduced-form vector autoregression, estimated by multivariate least squares.

The root of the multivariate surface: a (nobs, k) panel, a lag order and a deterministic specification, fitted in one least-squares solve. The constructor is inherited from _VectorAutoRegressionModel and takes an optional prior, which shrinks the solve toward a stated belief and lets a system with more regressors than observations estimate; the result then carries the posterior inference and its standard errors come from it.

Parameters:
  • endog (ArrayLike) – The (nobs, k) panel, time down the rows.

  • order (int) – Autoregressive order p, at least zero.

  • trend (Literal['n', 'c', 'ct']) – "n", "c" (default) or "ct".

  • names (Sequence[str] | None) – One label per variable. Defaults to y1 ... yk.

  • prior (_Prior | None) – A prior from priors, or None for unrestricted least squares.

Raises:
Variables:
  • _endog – The validated (nobs, k) panel.

  • _names – The resolved variable labels.

  • _order – The autoregressive order.

  • _trend (str) – The validated trend code.

  • _prior (_Prior) – The prior, or _NoPrior for least squares.

See also

  • VARResult – the record fit() returns.

  • VARX – the same model with exogenous regressors.

  • BVAR – full posterior simulation rather than a shrunk point estimate.

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = rng.standard_normal((200, 2))
>>> res = VAR(y, order=1).fit()
>>> res.forecast(3).shape
(3, 2)

Lag selection runs on the model, before any fit, and the criteria agree on white noise:

>>> selection = VAR(y, order=1).lag_order_selection(max_lags=4)
>>> selection.selected
{'aic': 0, 'bic': 0, 'hqic': 0, 'fpe': 0}

A prior changes the solve and the result records it:

>>> from cultivars.bayes.priors import MinnesotaPrior
>>> shrunk = VAR(y, order=1, prior=MinnesotaPrior(tightness=0.1)).fit()
>>> shrunk.prior_label, shrunk.posterior is not None, bool(shrunk.n_params < 9.0)
('minnesota(l1=0.1, l2=0.5, l3=1, l4=100)', True, True)