GibbsBVAR.fit#

GibbsBVAR.fit(*, n_draws=2000, n_burn=500, thin=1, seed=None)[source]#

Run the Gibbs sampler and keep the post-burn draws.

Each sweep draws all coefficients jointly given the covariance, the covariance given the coefficients, and – under an adaptive prior – the scale hierarchy; the first n_burn sweeps are discarded and every thin-th of the rest is kept. The same seed reproduces the chain exactly.

Parameters:
  • n_draws (int) – Total sampler iterations.

  • n_burn (int) – Burn-in iterations discarded, below n_draws.

  • thin (int) – Keep every thin-th post-burn draw, at least 1.

  • seed (int | Generator | None) – Seed or generator, for reproducibility.

Return type:

GibbsBVARResult

Returns:

The fitted GibbsBVARResult.

Raises:
  • SpecificationError – If the prior is improper, mixes adaptive components into a composition, or the draw bookkeeping is inconsistent.

  • NumericalError – If a conditional draw collapses.

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.zeros((200, 2))
>>> for t in range(1, 200):
...     y[t] = 0.5 * y[t - 1] + rng.standard_normal(2)
>>> model = GibbsBVAR(y, order=1)
>>> res = model.fit(n_draws=200, n_burn=50, thin=3, seed=0)
>>> res.n_kept, res.n_draws, res.n_burn, res.thin
(50, 200, 50, 3)
>>> again = model.fit(n_draws=200, n_burn=50, thin=3, seed=0)
>>> bool(np.array_equal(res.beta_draws, again.beta_draws))
True
>>> model.fit(n_draws=50, n_burn=50)
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: n_draws (50) must exceed n_burn (50).