cultivars.bayes#

Bayesian workflow for the package’s samplers: priors, chains, checks, evidence, combination.

The Bayesian models live with their frequentist counterparts, a BVAR beside the VAR, a SV among the univariate models. This package holds what surrounds a fit rather than the fit itself, in the order a Bayesian analysis runs. A prior is chosen and stated as a record (priors); the sampler’s draws are checked for convergence before they are read as a posterior (chains); the fitted model is run as a data-generating machine and compared with the sample it was fitted to, and the prior is run the same way before any sample is touched (checks); competing models are weighed by marginal likelihood, Bayes factor, and posterior model probability (evidence); and, when no model deserves the whole verdict, their predictive densities are combined by model averaging or stacking (combination). Each module is a leaf: names are imported from the module, not from this package, and nothing here depends on which model produced the draws beyond the result protocols in _core.

Layout. priors is the one module with state: the Minnesota family, the conjugate and independent Normal-Wishart pairings, the dummy-observation priors, and the adaptive shrinkage hierarchies, composable with +. chains is rhat(), the split-chain effective sample sizes, the Monte Carlo standard error, Geweke’s test, and the convergence() record that bundles them. checks is posterior_predictive_check(), prior_predictive_check(), and the PredictiveCheckTest record they produce. evidence is marginal_likelihood(), which selects the exact, Chib, harmonic-mean, or bridge estimate a result supports, and compare(), which turns a set of them into posterior model probabilities. combination is bayesian_model_average() and stacking().

Example

State a prior, fit, check the chain, and read the evidence:

>>> import numpy as np
>>> from cultivars.multivariate.large_dim.bayesian import BVAR
>>> rng = np.random.default_rng(0)
>>> y = np.zeros((120, 2))
>>> for t in range(1, 120):
...     y[t] = 0.7 * y[t - 1] + rng.standard_normal(2)
>>> prior = priors.NormalInverseWishartPrior(tightness=0.1)
>>> res = BVAR(y, order=1, prior=prior).fit(n_draws=400, seed=0)
>>> evidence.marginal_likelihood(res).method
'analytic'
>>> checks.posterior_predictive_check(res, seed=0).adequate()
True

Modules#

chains

Convergence diagnostics for Markov chain Monte Carlo output.

checks

Prior and posterior predictive checks: the model as a data-generating machine.

combination

Model combination: Bayesian model averaging and predictive stacking.

evidence

Marginal likelihoods, Bayes factors, and posterior model probabilities.

priors

Priors for the Bayesian vector autoregressions: moments, dummies, and hierarchies.