HierarchicalBVAR#

class cultivars.multivariate.large_dim.hierarchical.HierarchicalBVAR(endog, *, order, sum_of_coefficients=True, dummy_initial_observation=True, decay=1.0, exogenous=100.0, persistence=1.0, trend='c', names=None)[source]#

Giannone-Lenza-Primiceri hierarchical shrinkage over the conjugate BVAR.

The conjugate Normal-inverse-Wishart prior with Minnesota moments is indexed by the overall tightness \(\lambda\) and, when the dummy-observation priors are included, by the sum-of-coefficients looseness \(\mu\) and the dummy-initial-observation looseness \(\delta\) (larger is looser, as in the paper). Each carries a Gamma hyperprior – mode 0.2 and standard deviation 0.4 for \(\lambda\), mode 1 and standard deviation 1 for \(\mu\) and \(\delta\) – and the conjugate model’s closed-form marginal likelihood \(p(y \mid \theta)\) is the likelihood of the hyperparameter posterior. fit finds its mode by direct optimization in log space and, under the full method, explores it by adaptive random-walk Metropolis, drawing one (B, Sigma) from the exact conditional posterior at every kept state. The lag decay, the deterministic looseness and the persistence prior mean are held fixed, as in the paper.

Variables:
  • _endog – The validated (nobs_total, k) panel.

  • _order – The autoregressive order.

  • _trend – The deterministic specification.

  • _names – One label per variable.

  • _prior – The prior at the hyperprior modes, the search’s start.

  • _soc – Whether the sum-of-coefficients dummies are active.

  • _dio – Whether the dummy-initial-observation row is active.

  • _decay – The fixed Minnesota lag decay.

  • _exogenous – The fixed looseness of the deterministic block.

  • _persistence – The fixed prior mean of each own first lag.

Parameters:
  • endog (ArrayLike) – The observed panel, shape (nobs, k).

  • order (int) – Autoregressive order, at least 1.

  • sum_of_coefficients (bool) – Include the sum-of-coefficients dummies, with their looseness mu as a hyperparameter.

  • dummy_initial_observation (bool) – Include Sims’ co-persistence dummy, with its looseness delta as a hyperparameter.

  • decay (float) – Minnesota lag decay, held fixed as in the paper.

  • exogenous (float) – Looseness of the deterministic block, held fixed.

  • persistence (float | Sequence[float]) – Prior mean of each variable’s own first lag, one value for all or one per variable.

  • trend (Literal['n', 'c', 'ct']) – Deterministic terms, "n", "c" or "ct".

  • names (Sequence[str] | None) – One label per variable. Defaults to y1 ... yk.

Raises:
  • SpecificationError – If trend is not one of the three names, names does not have one entry per column, or the prior’s own validation of decay, exogenous or persistence fails.

  • DimensionError – If the panel is not a time-down-the-rows matrix or too short for the order.

See also

References

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

Example

>>> 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)
>>> res = HierarchicalBVAR(y, order=1).fit(
...     method="empirical", n_draws=100, seed=0
... )
>>> res.hyper_names
('lambda', 'mu', 'delta')
>>> res.beta_draws.shape
(100, 3, 2)
>>> lambda_only = HierarchicalBVAR(
...     y, order=1, sum_of_coefficients=False, dummy_initial_observation=False
... ).fit(method="empirical", n_draws=50, seed=0)
>>> lambda_only.hyper_names, lambda_only.prior_label, lambda_only.n_dummy
(('lambda',), 'glp(lambda)', 0)

Attributes#

endog

The validated sample.

is_shrunk

Whether a prior contributes anything to this estimate.

k_endog

Number of endogenous variables.

n_regressors

Regressors per equation.

names

Variable labels.

observed

The effective sample a replication is shaped like, (nobs, k).

order

Autoregressive order.

prior

The prior on the coefficients; NoPrior when unrestricted.

trend

Deterministic specification.

Methods#

fit(*[, method, n_draws, n_burn, seed])

Estimate the hyperparameter posterior, then the VAR under it.

lag_order_selection([max_lags])

Score every order from zero to max_lags on one common sample.

prior_replications([n_replications, seed])

Data sets the prior generates, shaped like the effective sample.