Detecting Structural Shifts, Building Counterfactuals, and Testing Interventions
Statistics & ExperimentsModel answerLast updated
Detect structural shifts in time-series data, construct counterfactual predictions under non-stationary patterns, and design spillover-resistant validation experiments.
Scenario
Imagine you are a Data Scientist at a streaming platform. Over the past three weeks, you observe a continuous, unexplained 15% decrease in the daily rate of new paid user sign-ups. The metric exhibits distinct weekly periodicity (weekend peaks) and experiences temporary surges driven by promotional marketing campaigns.
Tasks
- Structural Change-Point Detection: Detail a statistical method to prove that a structural shift occurred at a given date, rather than attributing the decline to random fluctuation or seasonal patterns.
- Counterfactual Modeling: Assuming a platform update deployed three weeks ago is suspected of causing this drop, outline a framework for building a counterfactual forecast to project expected sign-ups had the update not been deployed.
- Experimental Validation Strategy: Formulate an experimental plan to confirm whether rolling back the suspect update will recover the lost sign-ups, taking into account potential interference across users.
Requirements
- Explicitly model non-negative integer count data with multiplicative seasonality.
- Account for potential interference or network spillovers between treatment and control units in your experimental design.
Hints
Hint 1
Consider generalized linear models (such as Negative Binomial) with a log link function to naturalize multiplicative seasonal effects into additive regression terms.
Hint 2
When testing for an unknown break point tau, standard asymptotic chi-squared distributions do not apply; look into sup-likelihood ratio tests or CUSUM procedures on standardized residuals.
Hint 3
Address interference (SUTVA violations) using cluster-randomized designs (e.g., Designated Market Areas) or randomized saturation methodologies rather than simple individual-level randomization.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Step 0: Initial Data Integrity & Diagnostics
Prior to statistical modeling, confirm the decline is not an artifact of data processing or logging errors:
- Pipeline & Logging Audit: Verify whether event definitions, telemetry tracking, or attribution pipeline schemas were altered around the time of the drop.
- Source of Truth Verification: Cross-reference platform event tracking with internal billing and payment gateway records.
- Segmentation Analysis: Slice the data across key dimensions (e.g., client platform, geographic region, referral channel). A decline isolated to a single client version (e.g., iOS vs. Android) strongly points to a client-side update rather than a global macroeconomic trend.
Part 1: Structural Change-Point Detection
Because sign-up counts are non-negative and display multiplicative weekly seasonality, raw linear models are inappropriate.
1. Baseline Count Model
Model daily counts $Y_t$ using a Negative Binomial distribution with a log-link function to accommodate overdispersion relative to a Poisson distribution:
$$Y_t \sim \text{NegBin}(\mu_t, \phi), \quad \log(\mu_t) = \alpha + \gamma_{\text{dow}(t)} + \beta^\top X_t + \delta \cdot \mathbb{1}[t \ge \tau]$$
Where:
- $\gamma_{\text{dow}(t)}$ captures day-of-week fixed effects (additive on the log scale, translating to multiplicative effects on counts).
- $X_t$ incorporates external covariates (marketing spend, promotional campaign flags, holidays).
- $\tau$ is the candidate break timestamp.
- $\delta$ measures the structural level shift ($\delta \approx \log(0.85) \approx -0.16$ for a 15% drop).
2. Hypothesis Testing for an Unknown Break Date
If the precise timestamp $\tau$ is unconfirmed, test across candidate dates within a trimmed window $[\tau_{\text{start}}, \tau_{\text{end}}]$:
- Fit the model for every candidate date $\tau$ and compute the Likelihood Ratio statistic $\text{LR}(\tau)$.
- Take the maximum statistic: $\text{sup-LR} = \sup_{\tau} \text{LR}(\tau)$.
- Distribution Warning: Because the nuisance parameter $\tau$ exists only under the alternative hypothesis, the sup-LR statistic does not follow a standard $\chi^2_1$ distribution. Critical values must be derived via Andrews (1993) critical value tables or parametric bootstrapping under the null model (no break).
- The estimated break point is $\hat{\tau} = \arg\max_{\tau} \text{LR}(\tau)$, with confidence sets constructed via profile likelihood.
3. Residual CUSUM Monitoring
To continuously monitor for shifts, compute Pearson residuals from the pre-break baseline model:
$$r_t = \frac{Y_t - \hat{\mu}_t}{\sqrt{\hat{\mu}_t + \hat{\mu}_t^2 / \phi}}$$
Run a cumulative sum (CUSUM) test on $r_t$. Because seasonal variance and marketing spikes are modeled in $\hat{\mu}_t$, fluctuations in $r_t$ reflect true abnormal shifts rather than routine weekend spikes.
Part 2: Counterfactual Forecasting
To quantify lost conversions, construct a Bayesian Structural Time Series (BSTS) model (e.g., using the CausalImpact framework) over pre- and post-break periods.
Model Structure
- State Components: Incorporate a local linear trend alongside a 7-day seasonal state component.
- Control Series (Covariates): Include external predictors unaffected by the platform update, such as sign-up rates in unaffected geographic regions, organic search volume trends, or web page visits on un-updated domains.
- Prior Selection: Utilize a spike-and-slab prior on covariate coefficients to select the most predictive controls while avoiding over-fitting.
Estimation & Inference
- Train the BSTS model exclusively on pre-break data ($t < \hat{\tau}$).
- Forecast the counterfactual trajectory $\hat{Y}_t^{\text{counterfactual}}$ for the post-break window ($t \ge \hat{\tau}$).
- Calculate the pointwise effect $\Delta_t = Y_t - \hat{Y}_t^{\text{counterfactual}}$ and sum over the post-break window to obtain the total cumulative loss with posterior credible intervals.
Key Assumptions
- Independence of Controls: Control series must not suffer from spillover effects caused by the product change.
- Relationship Stability: The historical correlation between control series and the target metric must remain stable into the post-period.
- No Unobserved Confounders: No concurrent unmeasured events (e.g., competitor product launches) occurred simultaneously with the update.
Part 3: Experimental Validation Strategy (Rollback Experiment)
To prove causality, execute a feature rollback experiment.
Challenge: Interference & SUTVA Violations
Standard user-level randomization can be invalidated by network interference or shared infrastructure:
- Social / Referral Spillovers: Existing users invite prospective subscribers. If treatment and control users interact, conversion rates become interdependent.
- Market Dynamics / Shared Systems: Joint recommendation engine models or capacity allocation can leak treatment dynamics into control cohorts.
Recommended Design: Cluster-Randomized Experiment (e.g., Geo-Level)
Randomize by discrete, non-overlapping geographic markets (such as DMAs - Designated Market Areas):
- Clustering & Pairing: Group traffic by region. Pair regions using historical baseline volume, conversion profiles, and growth trajectories.
- Randomization: Within each pair, assign one region to Treatment (rollback to old version) and the other to Control (retain current version).
- Randomized Saturation (Optional Spillover Check): If intra-region leakage is suspected, assign varying treatment ratios (e.g., 0%, 50%, 100%) across higher-level regional blocks to measure cross-boundary spillovers directly.
Sample Size & Duration Considerations
Clustering increases variance by the design effect $DE = 1 + (m - 1)\rho$, where $m$ is the average cluster size and $\rho$ is the intra-cluster correlation (ICC).
- Collect data across multiple full weekly cycles (minimum 2–3 weeks) to capture full weekend seasonality.
- Calculate sample size requirements using cluster-level aggregated outcomes rather than individual user counts to ensure proper variance estimation.
Primary & Secondary Metrics
- Primary: Conversion rate (New Subscriptions / Eligible Unsubscribed Visitors) aggregated by cluster.
- Secondary / Guardrail: 7-day user retention, subscription plan selection distribution, page load latency, and revenue per user.
Summary Matrix of Potential Pitfalls
| Potential Pitfall | Impact | Mitigation Strategy |
|---|---|---|
| Naïve $\chi^2$ test on unknown break date | False positive inflation for break detection | Use Andrews' sup-LR test with bootstrapped critical values |
| Unadjusted seasonal variations | False alarms on weekend dips | Integrate explicit seasonal components ($\gamma_{\text{dow}}$) or use standardized Pearson residuals |
| User-level randomization under interference | Attenuated/biased effect estimation | Deploy Cluster-Randomized Trial (Geo-DMAs) |
| Ignoring overdispersion in count data | Underestimated standard errors | Model using Negative Binomial regression rather than standard Poisson |