You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Posterior inclusion probability per covariate (spike-and-slab only; returns None for horseshoe)
posterior_shrinkage
ndarray | None
Mean shrinkage factor kappa_j per covariate (horseshoe only; returns None for spike-and-slab). Values near 0 = weakly shrunk (included), near 1 = strongly shrunk.
Expected number of active covariates for spike-and-slab prior
dynamic_regression
bool
False
Enable time-varying regression coefficients
prior_type
str
"spike_slab"
"spike_slab" (discrete variable selection) or "horseshoe" (continuous shrinkage). Horseshoe is recommended for dense DGP settings.
state_model
str
"local_level"
"local_level" or "local_linear_trend"
nseasons
int | None
None
Seasonal cycle count. nseasons=1 is equivalent to no seasonal component.
season_duration
int | None
None
Duration of each seasonal block; defaults to 1 when nseasons is set. Requires nseasons to be set.
CausalImpactResults
Returned by ci._results. A frozen dataclass containing all computed quantities.
Fields
Field
Type
Description
actual
ndarray
Observed y values in the post period
point_effects
ndarray
Mean effect per time point
point_effect_lower
ndarray
Lower pointwise credible interval per time point
point_effect_upper
ndarray
Upper pointwise credible interval per time point
point_effect_mean
float
Mean of point effects across time
ci_lower
float
Lower CI bound on average effect
ci_upper
float
Upper CI bound on average effect
cumulative_effect_total
float
Total cumulative effect
relative_effect_mean
float
Relative effect (effect / predicted)
p_value
float
Bayesian one-sided tail probability
predictions_mean
ndarray
Mean counterfactual prediction
predictions_sd
ndarray
Posterior standard deviation of the counterfactual prediction
predictions_lower
ndarray
Lower CI on counterfactual
predictions_upper
ndarray
Upper CI on counterfactual
Horseshoe Prior (alternative to spike-and-slab)
CausalImpact supports the horseshoe prior (Carvalho, Polson & Scott 2010)
applied to BSTS regression, following the formulation of
Kohns & Bhattacharjee (2022) (arXiv:2011.00938).
When to use horseshoe
Scenario
Recommended prior
Few true covariates (sparse DGP)
spike_slab (default)
Many true covariates (dense DGP)
horseshoe
Usage
fromcausal_impactimportCausalImpact, ModelOptionsci=CausalImpact(
data, pre_period, post_period,
model_args=ModelOptions(prior_type='horseshoe'),
)
print(ci.posterior_shrinkage) # mean(kappa_j), 0=included 1=shrunk# ci.posterior_inclusion_probs is None for horseshoe (spike-slab only)
Shrinkage diagnostics
Property
prior_type
Meaning
posterior_inclusion_probs
spike_slab
E[gamma_j] — discrete inclusion probability
posterior_inclusion_probs
horseshoe
None (not applicable)
posterior_shrinkage
horseshoe
E[kappa_j] — continuous shrinkage factor kappa_j = 1/(1+lambda_j^2 * tau^2). Values close to 0 indicate the covariate is weakly shrunk (effectively included).