Artificial Intelligence 20 min read

Using BSTS and CausalImpact for Causal Effect Estimation in Structured Time‑Series Data

The article explains how Bayesian Structured Time Series (BSTS) combined with the CausalImpact library can be used to estimate causal effects for policies or marketing interventions when traditional A/B experiments are infeasible, detailing model theory, Bayesian inference, MCMC estimation, code implementation, and a real‑world holiday‑push case study.

Ctrip Technology
Ctrip Technology
Ctrip Technology
Using BSTS and CausalImpact for Causal Effect Estimation in Structured Time‑Series Data

When a product or marketing strategy cannot be evaluated with a strict A/B test, scientific causal inference becomes essential; the article proposes using the Bayesian Structured Time Series (BSTS) model together with the open‑source CausalImpact package to estimate the counterfactual impact of such interventions.

Traditional evaluation methods—simple pre‑post comparison, propensity‑score matching (PSM), and synthetic control (SCM)—are discussed, highlighting their reliance on strong assumptions (e.g., no hidden confounders, perfectly matched control groups) that are often unrealistic in practice.

The BSTS model is introduced as a Bayesian state‑space framework that captures structural features of time‑series data, such as local trends, seasonality, and cyclical components. By placing prior distributions on parameters and updating them with observed data, BSTS yields posterior distributions and credible intervals for forecasts.

Mathematically, the model consists of an observation equation linking observed values to latent states and a state transition equation describing how those latent states evolve over time. Extensions allow covariates X to be incorporated, turning the observation equation into a regression component.

Bayesian inference is performed via Markov‑Chain Monte Carlo (MCMC). The workflow includes: (1) specifying priors for parameters θ and initial states; (2) constructing a Markov chain and sampling with Gibbs or other MCMC algorithms; (3) computing posterior distributions using Bayes’ rule. The article outlines each step with the corresponding formulas.

Implementation details are provided in Python using TensorFlow Probability and the CausalImpact library. Example code snippets illustrate data simulation, model initialization, and impact analysis: import tensorflow as tf import tensorflow_probability as tfp from causalimpact import CausalImpact # ... data generation and model fitting ... ci = CausalImpact(data, pre_period, post_period) ci.plot() ci.summary()

A practical case study evaluates a holiday‑push marketing campaign for train ticket purchases. Historical data from previous years are used to train the BSTS model, which then predicts the counterfactual (no‑push) trajectory for the target year. The observed versus predicted series, pointwise differences, and cumulative effects are visualized, showing a modest but statistically insignificant uplift.

The article summarizes the strengths of BSTS—its ability to model structural time‑series features and provide Bayesian credible intervals—and its weaknesses, notably the sensitivity to prior specification and the computational cost of MCMC.

Further extensions discuss decomposing time series into long‑cycle, short‑cycle, seasonal, and covariate‑driven components, and combining Bayesian forecasts with machine‑learning models for the non‑seasonal parts.

In conclusion, BSTS coupled with CausalImpact offers a rigorous way to estimate causal effects for interventions that cannot be isolated via classic experiments, provided the data exhibit clear structural patterns and the priors are carefully chosen.

causal inferencetime seriesBayesian ModelingBSTSCausalImpactMarketing EvaluationMCMC
Ctrip Technology
Written by

Ctrip Technology

Official Ctrip Technology account, sharing and discussing growth.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.