TVPVAR.fit#

TVPVAR.fit(*, n_draws=2000, n_burn=1000, thin=2, k_drift=0.01, seed=None)[source]#

Estimate by Gibbs sampling.

Each iteration draws the whole coefficient path by one Durbin-Koopman simulation-smoother pass given (Q, Sigma), then Q from its inverse-Wishart conditional on the path’s increments, then Sigma from its inverse-Wishart conditional on the residuals. ceil((n_draws - n_burn) / thin) paths are kept.

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

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

  • thin (int) – Keep every thin-th post-burn draw.

  • k_drift (float) – Primiceri’s k_Q: prior scale of coefficient drift relative to the training coefficient uncertainty. The single most consequential number in the model – it is what disciplines a parameter path with more parameters than data. At the default 0.01 a slow drift of several tenths over a few hundred observations is shrunk to a few hundredths; values of 0.05 to 0.3 let such drift through.

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

Return type:

TVPVARResult

Returns:

The fitted TVPVARResult.

Raises:

Example

The drift prior is the dial: on a coefficient that climbs by 0.6 over the sample, the posterior mean path moves far more under a loose k_drift than under the default:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.zeros((240, 2))
>>> phi = np.linspace(0.2, 0.8, 240)
>>> for t in range(1, 240):
...     y[t, 0] = phi[t] * y[t - 1, 0] + rng.standard_normal()
...     y[t, 1] = 0.4 * y[t - 1, 1] + 0.3 * y[t - 1, 0] + rng.standard_normal()
>>> model = TVPVAR(y, order=1, training=40)
>>> tight = model.fit(n_draws=40, n_burn=15, seed=0)
>>> loose = model.fit(n_draws=40, n_burn=15, k_drift=0.3, seed=0)
>>> moved = lambda r: r.coefficient_path("y1", "y1.L1")[[0, -1], 1]
>>> bool(np.diff(moved(loose))[0] > 3.0 * np.diff(moved(tight))[0])
True
>>> tight.n_kept, tight.n_draws, tight.n_burn, tight.thin
(13, 40, 15, 2)
>>> model.fit(n_draws=10, n_burn=10)
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: n_draws (10) must exceed n_burn (10).