GibbsBVAR#
- class cultivars.multivariate.large_dim.gibbs.GibbsBVAR(endog, *, order, prior=None, trend='c', names=None)[source]
Bases:
_GibbsBayesianVectorAutoRegressionModel[GibbsBVARResult]Non-conjugate Bayesian VAR: independent Normal-Wishart, sampled by Gibbs.
One model, two families of priors the conjugate path refuses. Static moment priors with any diagonal variance – the default
IndependentNormalWishartPrior, which is Litterman’s full prior with the cross-equation weight kept, or aMinnesotaPriorpassed directly – and the adaptive shrinkage hierarchies:HorseshoePrior,SpikeAndSlabPrior,DirichletLaplacePrior,NormalGammaPrior. The prior is \(\beta \sim N(\underline\beta, \underline V)\) independent of \(\Sigma \sim IW(\underline S, \underline\nu)\), so the coefficient conditional is the GLS posterior\[\bar V = \bigl(\underline V^{-1} + \Sigma^{-1} \otimes X'X\bigr)^{-1}, \qquad \bar\beta = \bar V \bigl(\underline V^{-1} \underline\beta + (\Sigma^{-1} \otimes X')\, y\bigr),\]one \((k^2 p + k n_{det})\)-dimensional Gaussian per sweep, and the covariance conditional is inverse-Wishart on the residual scatter. Static moment priors may be composed with
+(aSumOfCoefficientsPriororDummyInitialObservationPrioradds artificial rows the sampler treats as data); adaptive priors stand alone.- Variables:
_endog – The validated
(nobs_total, k)panel._order – The autoregressive order.
_trend – The deterministic specification.
_names – One label per variable.
_prior – The validated prior.
- Parameters:
endog (
ArrayLike) – The observed panel, shape(nobs, k). A proper prior makes wide systems admissible, though each Gibbs sweep costs a Cholesky of the joint coefficient precision, so very largekbelongs to the conjugate model.order (
int) – Autoregressive order, at least 1.prior (
_Prior|None) – Any finite-variance prior, static or adaptive. Defaults toIndependentNormalWishartPrior(). Adaptive priors do not compose with+.trend (
Literal['n','c','ct']) – Deterministic terms,"n","c"or"ct".names (
Sequence[str] |None) – One label per variable. Defaults toy1 ... yk.
- Raises:
SpecificationError – If the prior is improper (
NoPrior),trendis not one of the three names, ornamesdoes not have one entry per column. An adaptive prior inside a composition is accepted here and refused atfit.DimensionError – If the panel is not a time-down-the-rows matrix or too short for the order.
See also
GibbsBVARResult– the posterior recordfitreturns.BVAR– the conjugate model: exact posterior, closed-form evidence, any dimension, but a Kronecker-restricted prior.BVARSV– the same sampler with stochastic volatility on the innovations.
References
Koop, G., & Korobilis, D. (2010). Bayesian multivariate time series methods for empirical macroeconomics. Foundations and Trends in Econometrics, 3(4), 267-358.
George, E. I., Sun, D., & Ni, S. (2008). Bayesian stochastic search for VAR model restrictions. Journal of Econometrics, 142(1), 553-580.
Example
>>> import numpy as np >>> from cultivars.bayes.priors import SpikeAndSlabPrior >>> rng = np.random.default_rng(0) >>> y = np.zeros((200, 3)) >>> for t in range(1, 200): ... y[t] = 0.6 * y[t - 1] + rng.standard_normal(3) >>> model = GibbsBVAR(y, order=1, prior=SpikeAndSlabPrior()) >>> res = model.fit(n_draws=300, n_burn=100, seed=0) >>> res.inclusion_probabilities().shape (1, 3, 3) >>> bool(np.all(np.diag(res.inclusion_probabilities()[0]) > 0.5)) True >>> from cultivars.bayes.priors import HorseshoePrior, SumOfCoefficientsPrior >>> composed = GibbsBVAR(y, order=1, prior=HorseshoePrior() + SumOfCoefficientsPrior()) >>> composed.fit(n_draws=60, n_burn=20, seed=0) Traceback (most recent call last): cultivars.exceptions.SpecificationError: adaptive shrinkage priors do not compose: ...