- Introduced by
- Scott & Varian (2014); Brodersen et al. (2015)
- Year
- 2014
- Type
- State-space model / Bayesian structural model
What does it do?
Bayesian Structural Time Series (BSTS) is a state-space modelling framework that decomposes a time series into additive components (trend, seasonality and regression) and estimates them jointly by Bayesian inference.
Scott and Varian (2014) presented it for short-term forecasting, and Brodersen et al. (2015) developed its use for counterfactual causal analysis of interventions, implemented in the CausalImpact R package.
The intuition behind the method
Think of a time series as the sum of a slowly drifting trend, repeating seasonal cycles, and the influence of one or more external predictors. BSTS fits all these components at once using Bayes' rule: it starts from a prior over each component and updates to a posterior once the observed data are seen. A built-in spike-and-slab prior decides automatically which predictors belong in the model by assigning each a probability of being included, acting as a form of Bayesian variable selection. The posterior then gives not only best-guesses but a full distribution of plausible component trajectories, so uncertainty is visible at every time point.
History
Scott and Varian (2014), in 'Predicting the Present with Bayesian Structural Time Series', applied the framework to short-term forecasting with search query data alongside economic series such as initial unemployment claims and retail sales. Brodersen, Gallusser, Koehler, Remy and Scott (2015) introduced the CausalImpact approach in the Annals of Applied Statistics, using a state-space model to predict the counterfactual response to an intervention where no randomised experiment is available. The CausalImpact method is implemented in an R package.
When to use it
Choose BSTS when you have a continuous time series and need to separate its trend, seasonal and regression components, forecast with posterior uncertainty, or estimate the effect of an intervention against a counterfactual built from control series. The number of observations needed depends on how many components and regressors the model contains. Short series make it harder to separate trend from seasonality and harder to achieve MCMC convergence, so check both with your own data before relying on the results. BSTS suits settings where many candidate predictors are available relative to the series length, because the spike-and-slab prior performs the selection inside the model. Avoid it for very short series, and for series with clearly multiplicative structure unless the data are transformed first, since the components are added on the scale being modelled. For causal analysis, do not rely on the CausalImpact counterfactual when the pre-intervention period is too short to learn the relationship with the control series, when the control series may themselves have been affected by the intervention, or when other changes coincide with the intervention.
Limitations and considerations
- Short series make the separation of trend and seasonal components less reliable and MCMC convergence harder to achieve. The length needed depends on the number of components and regressors, and should be judged from convergence diagnostics and prior sensitivity checks on the actual data.
- The observation equation shown assumes Gaussian noise, epsilon_t ~ N(0, sigma^2). This describes the specification shown, so residual diagnostics are needed to check whether the assumption is reasonable for the data.
- The full posterior is sampled by MCMC, which is considerably more computationally demanding than classical state-space or ARIMA estimation.
- Results depend on the prior specifications; sensitivity analysis is needed, especially for short series where the prior carries substantial weight.
- Causal conclusions from CausalImpact rest on the assumption that no unmeasured confounder changed at the time of the intervention. They also require that the control series used as regressors were not affected by the intervention and keep a stable relationship with the outcome across the pre- and post-intervention periods, because the counterfactual depends on that relationship.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Decomposes a time series into interpretable additive components (trend, seasonality and regression), each with posterior uncertainty.
- The spike-and-slab prior gives each candidate predictor a posterior inclusion probability, so variable selection happens within the same MCMC run rather than through a separate stepwise procedure.
- Predicts the counterfactual series from pre-intervention data, so the CausalImpact analysis yields a posterior distribution of the effect at each post-intervention time point, not a single estimate.
- Because inference is Bayesian, prior information about the parameters can be encoded, and posterior draws propagate uncertainty from the components into derived quantities such as the causal effect.
Applications
- Estimating the effect of an online advertising campaign or other market intervention on an outcome such as site visits, using a counterfactual built from control series.
- Short-term forecasting of economic series, such as initial unemployment claims or retail sales, using contemporaneous search query data as predictors.
- Decomposing a series into trend, seasonal and regression components to examine the contribution of each.
- Selecting among many candidate predictors when the series is short relative to the number of regressors.
- Forecasting with posterior predictive intervals when the uncertainty of each component needs to be reported.
How it works
How it works
Bayes' rule is the engine: the posterior over all model components is proportional to the likelihood of the observed series multiplied by the priors on the trend, seasonal, regression coefficients, and noise variance. Every unknown quantity — component trajectories and parameters alike — is treated as a random variable and updated simultaneously.
Formula
p(\theta \mid y) \propto p(y \mid \theta)\, p(\theta)
The observation equation links the observed value at each time point to the sum of its additive components: a local trend μ_t, a seasonal term τ_t, and a regression contribution x_t'β, plus Gaussian noise ε_t. The trend typically evolves as a random walk or local linear trend (slope itself also drifts), and the seasonal component is modelled as a sum-to-zero constraint over a period. A spike-and-slab prior on the regression coefficients β assigns each predictor a prior inclusion probability and a coefficient prior, enabling automatic selection from potentially many candidate regressors.
Formula
y_t = \mu_t + \tau_t + x_t^\top \beta + \varepsilon_t, \quad \varepsilon_t \sim \mathcal{N}(0, \sigma^2)Multiplying all component priors by the likelihood yields a high-dimensional joint posterior over all component sequences and parameters. Because no closed form exists for this posterior, it is explored by MCMC. Posterior sampling typically combines a state-space simulation step for the component trajectories with Gibbs-type updates for the parameters; the exact sampler depends on the implementation. The result is a set of posterior draws of each component trajectory and each coefficient, from which posterior means, credible intervals, and the probability of predictor inclusion are summarised. In the CausalImpact application, a counterfactual series is predicted from the pre-intervention posterior and compared to the observed post-intervention data to estimate the causal effect.
Formula
p(\mu_{1:T},\, \tau_{1:T},\, \beta,\, \sigma^2 \mid y_{1:T}) \propto p(y_{1:T} \mid \cdot)\, p(\beta)_{\text{spike-slab}}\, p(\mu)\, p(\tau)\, p(\sigma^2)Common pitfalls
- Skipping MCMC convergence diagnostics (R-hat, effective sample size, trace plots) and interpreting point summaries from chains that have not converged.
- Using spike-and-slab selection with few observations, where the prior may shrink relevant predictors out of the model.
- Treating the CausalImpact estimate as proof of causality without checking that no unmeasured confounder drove the post-intervention change.
- Using a short pre-intervention period in CausalImpact, which gives an unreliable counterfactual.
- Applying BSTS to series with multiplicative structure (for example, seasonal swings proportional to the level) without first considering a log transformation.
Frequently asked questions
What is the difference between BSTS and ARIMA?
ARIMA models a time series as an autoregressive-moving-average process and produces point forecasts with intervals. BSTS decomposes the series into trend, seasonal and regression components estimated within a Bayesian framework, giving posterior distributions for each. A standard ARIMA specification has no built-in spike-and-slab selection across regressors; in BSTS this selection is carried out through the prior inclusion probabilities.
How does CausalImpact use BSTS?
CausalImpact fits a BSTS model on the pre-intervention period, using control series as regressors, to learn the counterfactual: what the series would have looked like without the intervention. It then extrapolates that counterfactual into the post-intervention window and compares it with the observed values. The difference, expressed as a posterior distribution, is the estimated causal impact. The key assumptions are that no unobserved confounders changed at the time of the intervention and that the control series used as regressors were not themselves affected by it.
What is a spike-and-slab prior?
A spike-and-slab prior places a probability mass (the 'spike') at exactly zero for each regression coefficient and a diffuse distribution (the 'slab') away from zero. The MCMC sampler estimates, for each predictor, the posterior probability of inclusion in the model. Predictors with high inclusion probability contribute meaningfully to the fit; those with low inclusion probability are effectively dropped. This performs variable selection without a separate stepwise procedure.
How many observations are needed for BSTS?
No fixed minimum applies. With short series, the trend and seasonal components are harder to separate and MCMC convergence is harder to achieve. The length needed depends on the number of components and regressors in the model, so check convergence and prior sensitivity on your own data. For CausalImpact, the pre-intervention period must be long enough for the model to learn the relationship between the outcome and the control series; a short pre-intervention period gives an unreliable counterfactual.
Related methods
Sources
Scott, S. L. & Varian, H. R. (2014). Predicting the Present with Bayesian Structural Time Series. International Journal of Mathematical Modelling and Numerical Optimisation, 5(1/2), 4–23.
Open DOI referenceBrodersen, K. H., Gallusser, F., Koehler, J., Remy, N. & Scott, S. L. (2015). Inferring Causal Impact Using Bayesian Structural Time-Series Models. Annals of Applied Statistics, 9(1), 247–274.
Open DOI reference