VAR#

class impulso.spec.VAR(*, lags, max_lags=None, prior='minnesota', volatility='constant', exog_prior_scale=100.0, error_dist='gaussian')[source]#

Bases: ImpulsoBaseModel

Immutable 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 (int | Literal['aic', 'bic', 'hq'])

  • max_lags (int | None)

  • prior (Literal['minnesota'] | ~impulso.protocols.Prior)

  • volatility (Literal['constant', 'sv'] | ~impulso.protocols.PyMCVolatilityProcess)

  • exog_prior_scale (Annotated[float, Gt(gt=0)])

  • error_dist (Literal['gaussian', 'student_t'] | ~impulso.protocols.ErrorDistribution)

lags#

Fixed lag order (int >= 1) or selection criterion string.

Type:

int | Literal[‘aic’, ‘bic’, ‘hq’]

max_lags#

Upper bound for automatic selection. Only valid with string lags.

Type:

int | None

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:

float

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

The Minnesota Prior / Usage

Writing a Custom Prior / Using your custom prior

Granger Causality and Toda-Yamamoto / Query a fitted model

Granger Causality and Toda-Yamamoto / Toda-Yamamoto for integrated systems / The manual route

Heavy-Tailed Observation Errors / Fitting

Heavy-Tailed Observation Errors / Reading the posterior for nu / Is it worth it? Comparing against the Gaussian fit

Choosing Lag Order / Fixed lag order

Prior and Posterior Predictive Checks / Checking the prior before you fit

Impulso

The conjugate VAR: fast Bayesian estimation / When to reach for ConjugateVAR instead of the NUTS VAR / Scope

Probabilistic Forecasts

The Minnesota Prior, From Scratch

Model Checks and Validation

Identification in structural VARs: Cholesky vs sign restrictions / A case study using U.S. monetary policy data / Impulse Response Function

Oil supply news with an external instrument / How the announcement surprise identifies one shock

Fitting Your First Bayesian VAR

Counterfactuals, conditional forecasts, and structural scenarios / “What if” analysis in the style of Antolín-Díaz, Petrella & Rubio-Ramírez (2021) / The Lucas critique still applies

Stochastic volatility: modelling time-varying uncertainty / Model / Stochastic volatility inside a VAR

Structural Shocks in the Atmosphere

fit(data, sampler=None)[source]#

Estimate the Bayesian VAR model.

Parameters:
  • data (VARData) – VARData instance.

  • sampler (Sampler | None) – Sampler protocol instance. Defaults to _default_sampler() (cores=1, chains=4, target_accept=0.8). Pass an explicit NUTSSampler(cores=n) to opt into parallel chains.

Returns:

FittedVAR with posterior draws.

Return type:

FittedVAR

Expand for references to impulso.spec.VAR.fit

Writing a Custom Prior / Using your custom prior

Granger Causality and Toda-Yamamoto / Query a fitted model

Granger Causality and Toda-Yamamoto / Toda-Yamamoto for integrated systems / The manual route

Heavy-Tailed Observation Errors / Fitting

Heavy-Tailed Observation Errors / Reading the posterior for nu / Is it worth it? Comparing against the Gaussian fit

Impulso

Stochastic volatility: modelling time-varying uncertainty / Model / Stochastic volatility inside a VAR

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

Expand for references to impulso.spec.VAR.prior_predictive

Prior and Posterior Predictive Checks / Checking the prior before you fit

property resolved_error_dist: ErrorDistribution#

Resolve string error-distribution shorthand to an ErrorDistribution instance.

property resolved_prior: Prior#

Resolve string prior shorthand to a Prior instance.

property resolved_volatility: PyMCVolatilityProcess#

Resolve string volatility shorthand to a PyMCVolatilityProcess instance.