HierarchicalBVARResult#

class cultivars.multivariate.large_dim.hierarchical.HierarchicalBVARResult(*, endog, names, order, trend, prior_label, coefficients, deterministic, beta_mean, sigma_u, beta_draws, sigma_draws, log_marginal_likelihood, posterior_df, resid, fittedvalues, nobs, n_dummy, hyper_names, hyper_mode, hyper_draws, acceptance_rate, method)[source]

Bases: BVARResult

A fitted hierarchical BVAR: the tightness carries a posterior too.

Everything the conjugate result reports, with one change of meaning and one addition. The change: under the full method the retained (B, Sigma) draws marginalize over the hyperparameters \(\theta = (\lambda, \mu, \delta)\),

\[p(B, \Sigma \mid y) = \int p(B, \Sigma \mid y, \theta)\, p(\theta \mid y)\, d\theta, \qquad p(\theta \mid y) \propto p(y \mid \theta)\, p(\theta),\]

with \(p(y \mid \theta)\) the conjugate model’s closed-form marginal likelihood, so every band downstream – coefficients, impulse responses, the predictive – includes hyperparameter uncertainty; log_marginal_likelihood is the value at the hyperparameter mode, conditional on it. The addition is the hyperparameter layer itself: the posterior mode, the kept draws, and the chain’s acceptance rate.

Note

Under method="empirical" the (B, Sigma) draws condition on hyper_mode, hyper_draws is empty and acceptance_rate is nan; hyperparameter_interval refuses. A hyperparameter whose dummies carry no information – mu when the presample mean is zero, since the sum-of-coefficients rows are that mean divided by mu – has a posterior equal to its hyperprior and a mode at the search’s start; the marginal likelihood is flat in it, which is correct and worth noticing. The summary’s acceptance-rate guidance is for the kept span; a short run after a long adaptive burn-in can sit above it without harm.

Variables:
  • hyper_names – One label per hyperparameter, in draw-column order – "lambda", then "mu" and "delta" when active, parameterized as in Giannone-Lenza-Primiceri.

  • hyper_mode – Posterior-mode hyperparameter vector.

  • hyper_draws – (S, d) kept hyperparameter draws; empty under empirical Bayes.

  • acceptance_rate – Metropolis acceptance over the kept span; nan under empirical Bayes.

  • method – "full" or "empirical".

See also

  • HierarchicalBVAR – the model that produces this record.

  • BVARResult – the conjugate record this one extends, with the tightness fixed.

References

Giannone, D., Lenza, M., & Primiceri, G. E. (2015). Prior selection for vector autoregressions. Review of Economics and Statistics, 97(2), 436-451.

Example

The full hierarchy on a bivariate VAR(1): the tightness has a posterior, the mode agrees with the empirical-Bayes fit, and the coefficient bands marginalize over it:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.zeros((150, 2))
>>> for t in range(1, 150):
...     y[t] = 0.6 * y[t - 1] + rng.standard_normal(2)
>>> y += 5.0
>>> model = HierarchicalBVAR(y, order=1)
>>> full = model.fit(method="full", n_draws=300, n_burn=300, seed=0)
>>> full.method, full.hyper_names, full.hyper_draws.shape, full.n_kept
('full', ('lambda', 'mu', 'delta'), (300, 3), 300)
>>> low, mean, high = full.hyperparameter_interval("lambda")
>>> bool(0.0 < low < mean < high < 1.0), bool(0.1 < full.acceptance_rate < 0.9)
(True, True)
>>> empirical = model.fit(method="empirical", n_draws=100, seed=0)
>>> bool(np.allclose(empirical.hyper_mode, full.hyper_mode))
True
>>> bool(empirical.log_marginal_likelihood == full.log_marginal_likelihood)
True

Private methods#

_summary_table()

Build the structured summary.