VAR#
- class impulso.spec.VAR(*, lags, max_lags=None, prior='minnesota', volatility='constant', exog_prior_scale=100.0, error_dist='gaussian')[source]#
Bases:
ImpulsoBaseModelImmutable VAR model specification.
VAR specifies the reduced-form model — lag order, coefficient prior, volatility process, and observation error distribution. Nothing here says which shock is which: structural meaning is layered on afterwards, by applying an identification scheme to the FittedVAR that fit returns.
- Parameters:
- lags#
Fixed lag order (int >= 1) or selection criterion string.
- Type:
int | Literal[‘aic’, ‘bic’, ‘hq’]
- prior#
Prior shorthand string or Prior protocol instance.
- Type:
Literal[‘minnesota’] | impulso.protocols.Prior
- volatility#
Volatility shorthand string or PyMCVolatilityProcess protocol instance.
- Type:
Literal[‘constant’, ‘sv’] | impulso.protocols.PyMCVolatilityProcess
- exog_prior_scale#
Tightness of the prior on the exogenous coefficients B_exog, read in contribution space: one prior standard deviation moves an endogenous variable by this many of its own AR(1) residual standard deviations when the regressor moves by one of its own. The default of 100 is deliberately loose — deterministic and exogenous terms are conventionally left near-uninformative (the conjugate engine uses Vc = 10e6 on the intercept), and the prior’s job here is to stop the scale of the regressor from silently setting the answer, not to shrink. Lower it to shrink B_exog towards zero. Applies only to VAR.fit; prior governs the lag coefficients.
- Type:
- error_dist#
Observation error distribution — shorthand string (“gaussian”, the default, or “student_t”) or an ErrorDistribution protocol instance. The string form takes the adapter’s defaults, so error_dist=”student_t” infers the degrees of freedom; pass StudentT(nu=5.0) to fix them. Heavy- tailed errors are rejected in combination with time-varying volatility. Governs the exogenous block only; prior governs the lag coefficients. Both VAR.fit and VAR.prior_predictive build the same graph, so it applies to either.
- Type:
Literal[‘gaussian’, ‘student_t’] | impulso.protocols.ErrorDistribution
Expand for references to
impulso.spec.VAR- fit(data, sampler=None)[source]#
Estimate the Bayesian VAR model.
- Parameters:
- Returns:
FittedVAR with posterior draws.
- Return type:
- model_config = {'arbitrary_types_allowed': True, 'frozen': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- prior_predictive(data, *, draws=500, random_seed=None)[source]#
Simulate data from the prior, before seeing the likelihood.
Builds the same PyMC graph fit builds and calls pymc.sample_prior_predictive on it, so the prior that gets simulated is exactly the prior that gets sampled — no hand-rolled second implementation to drift out of sync.
The simulated obs paths are one-step-ahead given the observed lags: for each prior draw, y_t = c + B x_t^obs (+ B_exog z_t) + L_t eps_t where x_t^obs stacks the observed lags of data. The design matrices are baked into the graph, so this is the prior predictive of the estimation-sample conditional means, not a simulated path iterated from initial conditions. That is what arviz.plot_ppc(…, group=”prior”) expects and what makes the prior comparable to the data on the same time axis.
Note
Under volatility=”sv” the per-variable log-volatility priors are seeded from the OLS residuals of data (see StochasticVolatility.build_pymc_latent), so the “prior” is mildly data-informed in its scale. The constant-volatility default is not.
Note
PyMC returns a single chain, so the obs variable has shape (1, draws, T - n_lags, n_vars).
- Parameters:
data (VARData) – VARData instance. Anchors the prior simulation on the real lags (and, if present, the real exogenous regressors), and fixes the lag order when lags is a selection criterion.
draws (int) – Number of prior draws.
random_seed (int | Generator | None) – Seed or Generator passed straight through to pymc.sample_prior_predictive.
- Returns:
InferenceData-schema container with prior (every latent), prior_predictive (the simulated obs, dims (chain, draw, time, var)) and observed_data (the realised obs) groups.
- Return type:
InferenceData
- property resolved_error_dist: ErrorDistribution#
Resolve string error-distribution shorthand to an ErrorDistribution instance.
- property resolved_volatility: PyMCVolatilityProcess#
Resolve string volatility shorthand to a PyMCVolatilityProcess instance.