Hierarchical Bayesian VAR
Python · R · Part 7 of the VAR arc — prior selection & density forecasts
Overview
Part 7 of the VAR arc: letting the data choose the shrinkage. Every Bayesian VAR so far fixed the Minnesota tightness by hand — , or the BGR in-sample-fit rule of Part 3. But how much a VAR should shrink is not a matter of taste: it is a parameter the data can speak to. Giannone, Lenza & Primiceri (2015) put a prior on the hyperparameters and estimate them by the marginal likelihood — the fully Bayesian, hierarchical answer to "how much should a VAR shrink?". This example builds that from scratch, then delivers the payoff the stochastic-volatility and time-variation notebooks implicitly promised but never measured: a proper density-forecast evaluation, where getting the shrinkage right — with its uncertainty — visibly improves the whole predictive distribution, not just the point forecast.
A conjugate BVAR whose evidence is closed-form
The trick that makes hierarchical estimation tractable is a change of prior. Earlier notebooks used an independent-Normal Minnesota prior, which needs Gibbs and has no closed-form evidence. Here the natural-conjugate (Normal-inverse-Wishart) version is implemented by dummy observations (Theil mixed estimation): the prior is written as artificial data rows appended to the sample, so the posterior is just the regression on the stacked system — and the marginal likelihood is closed-form (a matric-variate- normalising constant). Three hyperparameters index the dummies: (overall Minnesota tightness, the master knob), (Doan sum-of-coefficients — shrinks toward unit roots, a no-cointegration prior), and (Sims dummy-initial-observation — allows a common stochastic trend, i.e. cointegration). The last two are exactly what let a levels BVAR behave sensibly at the unit-root/cointegration boundary that Part 6 was all about. Following GLP, Gamma hyperpriors on are sampled by random-walk Metropolis using the closed-form evidence as the likelihood; the coefficients then follow analytically. A new from-scratch module (bvarglp.py), fit on a 7-variable FRED-QD system in log-levels, .
Results
The data want less shrinkage than the convention. The marginal likelihood places at ~0.29 (68% band ≈ [0.26, 0.32]) — clearly to the right of the conventional 0.2 — and pulls the sum-of-coefficients hyperparameter well off its prior mode (median ≈ 2.4 vs a mode of 1), while the dummy-initial-observation term moves only slightly (≈ 1.14). Every earlier notebook collapsed all this to one fixed number; the hierarchical treatment keeps the uncertainty, and the density forecasts reward it. Best density forecasts: integrating over the hyperparameter posterior, the GLP-hierarchical BVAR has the highest average log predictive score (−3.85), beating a fixed Minnesota tightness (−4.28) and a near-flat prior (−4.54) over 79 quarters — estimating the shrinkage and carrying its uncertainty improves the whole predictive density. The same closed-form evidence gives Bayes factors: the unit-root/cointegration-aware prior components are supported "beyond decisively" (log₁₀ BF ≈ 60 over plain Minnesota), and all dominate shorter lags. Calibration, honestly: the PIT histograms are near-uniform but all three models are mildly over-dispersed (68% intervals cover ~0.75–0.84) — the hierarchical model earns its top score by fit, not by being tightest. This is the measured payoff of Parts 3–5: those added shrinkage, SV and time-variation for better uncertainty; here the predictive densities are finally scored. Cross-checked in R against the BVAR package (itself a GLP implementation), which reproduces the hierarchical posterior.
Notebooks
Downloads
bvarglp.py The from-scratch conjugate dummy-observation BVAR with closed-form marginal likelihood and hierarchical prior selection (new module; the bvar.py engine is left untouched)
bvecm_glp_data.csv 7-variable FRED-QD macro system in log-levels (output, prices, funds rate, consumption, investment, hours, unemployment), quarterly 1959–2019 References
- Giannone, D., Lenza, M. & Primiceri, G. E. (2015). Prior selection for vector autoregressions. Review of Economics and Statistics 97(2), 436–451. — the hierarchical marginal-likelihood prior selection reproduced here
- Doan, T., Litterman, R. & Sims, C. (1984). Forecasting and conditional projection using realistic prior distributions. Econometric Reviews 3(1), 1–100. — the Minnesota prior and the sum-of-coefficients dummy
- Sims, C. A. (1993). A nine-variable probabilistic macroeconomic forecasting model. In Business Cycles, Indicators, and Forecasting, NBER, 179–212. — the dummy-initial-observation prior
- Bańbura, M., Giannone, D. & Reichlin, L. (2010). Large Bayesian vector auto regressions. Journal of Applied Econometrics 25(1), 71–92. — the dummy-observation implementation of the conjugate prior
- Geweke, J. & Amisano, G. (2010). Comparing and evaluating Bayesian predictive distributions of asset returns. International Journal of Forecasting 26(2), 216–230. — the log predictive score used for density-forecast evaluation
- Kass, R. E. & Raftery, A. E. (1995). Bayes factors. Journal of the American Statistical Association 90(430), 773–795. — the Bayes-factor scale for the prior-component comparisons
- Kuschnig, N. & Vashold, L. (2021). BVAR: Bayesian vector autoregressions with hierarchical prior selection in R. Journal of Statistical Software 100(14), 1–27. — the R
BVARpackage used in the cross-check