VAR#
- class cultivars.multivariate.reduced_form.vector_autoregression.VAR(endog, *, order, trend='c', names=None, prior=None)[source]#
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_VectorAutoRegressionModeland 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 orderp, at least zero.trend (
Literal['n','c','ct']) –"n","c"(default) or"ct".names (
Sequence[str] |None) – One label per variable. Defaults toy1 ... yk.prior (
_Prior|None) – A prior frompriors, orNonefor unrestricted least squares.
- Raises:
SpecificationError – If the order, trend or names are malformed.
DimensionError – If the sample cannot support the specification.
- 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
_NoPriorfor least squares.
See also
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)
Attributes#
The validated sample. |
|
Whether a prior contributes anything to this estimate. |
|
Number of endogenous variables. |
|
Regressors per equation. |
|
Variable labels. |
|
Autoregressive order. |
|
The prior on the coefficients; |
|
Deterministic specification. |
Methods#
|
Estimate the system and return the fitted result. |
|
Score every order from zero to |