SpikeAndSlabPrior#

class cultivars.bayes.priors.SpikeAndSlabPrior(*, spike=0.1, slab=10.0, inclusion=0.5, deterministic_scale=10.0)[source]

Bases: _AdaptivePrior

Stochastic search variable selection: exclusion as a latent state.

George, Sun and Ni’s (2008) BVAR prior. Each standardized lag coefficient carries a Bernoulli indicator choosing between a spike, a normal tight enough around zero that the coefficient is effectively excluded, and a slab loose enough that it is effectively free,

\[\beta_{ij} \mid \gamma_{ij} \sim (1 - \gamma_{ij})\, \mathcal{N}(0, \tau_{0,ij}^2) + \gamma_{ij}\, \mathcal{N}(0, \tau_{1,ij}^2), \qquad \gamma_{ij} \sim \mathrm{Bernoulli}(p),\]

where \(\beta_{ij}\) is the coefficient divided by the Minnesota unit ratio \(s_i / s_j\). Given the coefficients the indicators are conditionally independent Bernoullis with the exact odds

\[\frac{\Pr(\gamma_{ij} = 1 \mid \beta_{ij})}{\Pr(\gamma_{ij} = 0 \mid \beta_{ij})} = \frac{p}{1 - p} \cdot \frac{\tau_{0,ij}}{\tau_{1,ij}} \exp\!\Bigl\{\frac{\beta_{ij}^2}{2} \Bigl(\frac{1}{\tau_{0,ij}^2} - \frac{1}{\tau_{1,ij}^2}\Bigr)\Bigr\},\]

so the Gibbs sweep redraws them without tuning, and their conditional probabilities averaged over kept sweeps are a Rao-Blackwellized posterior inclusion probability per coefficient. That is this prior’s distinctive output and what inclusion_probabilities() reports; a global-local prior has no such quantity, because it never asks whether a coefficient is in. SSVS is this object’s sampler, not a second prior; the two names in the literature name one thing.

The spike and slab widths follow the semiautomatic default: each coefficient’s least-squares standard error on the standardized scale, times spike and slab, so the spike is narrower than the data can resolve and the slab wider than any coefficient the data would produce. The inclusion probability is a fixed hyperparameter rather than being given its own Beta layer, matching the reference treatment. The deterministic and exogenous columns are never candidates for exclusion; they sit at a fixed loose variance.

Variables:
  • spike – Spike width as a multiple of the coefficient’s reference standard error; small is a harder exclusion.

  • slab – Slab width on the same scale; large is freer.

  • inclusion – Prior inclusion probability of each lag coefficient.

  • deterministic_scale – Looseness of the unshrunk deterministic and exogenous rows, in units of each equation’s residual scale.

Raises:

SpecificationError – If 0 < spike < slab fails, if inclusion is not strictly between zero and one, or if deterministic_scale is not positive, at the first moment call, which is the model’s fit.

Note

The prior mean is zero everywhere and there is no persistence hyperparameter: an exclusion means the coefficient is zero, and centring the spike elsewhere would change what exclusion means. Difference the data, or use the Minnesota family, for random-walk centring. Adaptive priors do not compose, and the Chib marginal likelihood is not offered under one; compare by predictive score. Inclusion probabilities are posterior statements about this sample: a coefficient the sample estimates away from zero is included whether or not the generating process had it.

Warning

Only GibbsBVAR samples the indicators. The static moments interface reports the variance with every indicator in and the unit ratio as reference, slab**2 on the standardized lag block, which is what admissibility checks need and not the mixture; a model that reads only the static moments is fitting a fixed Gaussian prior under this class’s label.

See also

  • inclusion_probabilities() – the averaged conditional probability per lag coefficient, this prior’s diagnostic.

  • HorseshoePrior – continuous shrinkage with no

    exclusion state, when the question is how much rather than whether.

  • NormalGammaPrior – continuous shrinkage with a tunable tail.

References

George, E. I., Sun, D., & Ni, S. (2008). Bayesian stochastic search for VAR model restrictions. Journal of Econometrics, 142(1), 553-580.

George, E. I., & McCulloch, R. E. (1993). Variable selection via Gibbs sampling. Journal of the American Statistical Association, 88(423), 881-889.

Koop, G., & Korobilis, D. (2010). Bayesian multivariate time series methods for empirical macroeconomics. Foundations and Trends in Econometrics, 3(4), 267-358.

Example

Three series of which only the first has an own lag. The own lag is included with probability one and most noise coefficients sit near the floor the hard spike leaves them; the second inclusion is a coefficient this sample estimates at 0.2, which is the sample’s doing, not the prior’s:

>>> import numpy as np
>>> from cultivars.multivariate.large_dim.gibbs import GibbsBVAR
>>> rng = np.random.default_rng(0)
>>> y = np.zeros((200, 3))
>>> for t in range(1, 200):
...     y[t] = np.array([0.8, 0.0, 0.0]) * y[t - 1] + rng.standard_normal(3)
>>> res = GibbsBVAR(y, order=1, prior=SpikeAndSlabPrior()).fit(
...     n_draws=1500, n_burn=500, seed=0
... )
>>> res.prior_label
'ssvs(spike=0.1, slab=10, p=0.5)'
>>> probability = res.inclusion_probabilities()[0]
>>> probability[0, 0].round(2), bool(probability[1, 2] > 0.7)
(np.float64(1.0), True)
>>> probability > 0.5
array([[ True, False, False],
       [False, False,  True],
       [False, False, False]])
>>> np.abs(res.coefficients[0]).round(1)
array([[0.7, 0. , 0. ],
       [0. , 0. , 0.2],
       [0. , 0. , 0. ]])

Private methods#

_check()

Reject widths and probabilities that do not describe a prior.

_draw_scales(standardized, context, rng, scales)

Exact Bernoulli conditionals for the indicators.

_initial_scales(context, reference)

Anchor both widths to the reference scale; start everything in.

_label()

Short description for summary tables and comparison rows.

_scale_variance(scales, context)

Spike or slab variance per the current indicators, loose elsewhere.

_tracked(scales, context)

The Rao-Blackwellized inclusion probability per lag coefficient.

_tracked_label()

What the averaged diagnostic is.