Designing and Analyzing an Ad-Scheduling A/B Experiment
Statistics & ExperimentsModel answerLast updated
Plan and analyze an ad-scheduling A/B test. Covers randomization, CUPED, ratio metric linearization, sample sizing, multiple testing, and delayed offline conversion handling.
You are an analytics lead designing and executing an evaluation plan for a new ad-scheduling algorithm ($B$) versus the current baseline ($A$).
Today is September 1, 2025. The evaluation window spans 7 complete days ending today: August 26, 2025 through September 1, 2025 inclusive.
System & Business Context
- Traffic Environment: Users interact with the platform across three client platforms (web, iOS, Android) throughout different time-of-day slots. A single user can experience multiple ad impressions per day.
- Target & Guardrail Metrics: The primary metric under study is
watch_time_per_impression(in seconds). Key guardrail metrics are Click-Through Rate (CTR), skip rate, Daily Active Users (DAU), and user complaint rate. - Characteristics: Strong daily and intra-day seasonality exists. A subset of ad inventory consists of long-form video creatives.
- Delayed Measurement: Offline conversion events (such as subsequent online store visits) report with an ingestion lag of 24 to 48 hours.
Write an experimental plan and data analysis protocol answering the following seven components with explicit statistical justification:
- Randomization Strategy & Contamination Control: Explain your choice among user-level, device-level, or impression-level randomization. Detail how you will handle cross-platform activity and time slots. Provide the precise hashing syntax for variant assignment.
- Stratification & Variance Reduction (CUPED): Define post-experiment stratification variables. Specify the pre-period date range for CUPED, define the exact baseline covariate, and state the adjusted metric formula.
- Metric Formulations & Outlier Handling: Write the exact mathematical formulation of
watch_time_per_impressionat the unit level, explaining why naive impression-level variance estimation is flawed. Specify your Intent-to-Treat (ITT) protocol and two-stage winsorization rule for outliers. - Hypothesis Testing Framework: Specify whether the primary test should be one-tailed or two-tailed. Formulate the test statistic (e.g., Welch's z-test with linearized ratio variance) and state the non-inferiority setup for guardrails.
- Sample Size & Stopping Criteria: Calculate the required sample size per arm assuming a baseline mean of 42 seconds, standard deviation of 55 seconds, target minimum detectable effect (MDE) of $+5%$ relative lift, $\alpha = 0.05$ (two-sided), and power $1 - \beta = 0.80$. Explain how user-level clustering and CUPED alter this calculation, and detail your sequential monitoring policy.
- Reporting & Health Diagnostics: Outline the final confidence interval derivation, post-strata aggregation, and multiple-testing correction (e.g., Holm-Bonferroni) across guardrails. List two diagnostics for randomization balance and two for novelty/seasonality effects (note any calendar anomaly on September 1, 2025).
- Handling Delayed Offline Signals: Describe how you will re-evaluate results if offline conversion metrics are missing for the final 48 hours of the experiment window, including adjustments to the readout timeline.
Hints
Hint 1
Remember that watch_time_per_impression is a cluster-level ratio metric. The randomization unit is the user, but the denominator is impression count, requiring the delta method or bootstrap to account for variance correctly.
Hint 2
Consider calendar properties of the test window (e.g., September 1, 2025 is Labor Day in the US). Check for day-of-week interactions and holiday effects during diagnostic checks.
Hint 3
When applying CUPED to ratio metrics, ensure the pre-period covariate is constructed identically (e.g., pre-period linearized watch time) to maximize correlation and avoid bias.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Randomization Unit and Exposure Control
Unit Selection: User-Level
We randomize at the user level (using a unified account ID).
- Why not impression-level? Impression-level randomization violates unit independence. If a single user experiences policy $A$ at 10:00 AM and policy $B$ at 2:00 PM, treatment carryover, ad fatigue, and learning effects leak across variants. Furthermore, user-level metrics like Daily Active Users (DAU) cannot be calculated under impression-level splits.
- Why not device-level? Device-level split leads to cross-platform contamination (e.g., a user assigned to $A$ on iOS and $B$ on Web). This degrades intent-to-treat integrity and dilutes treatment effects.
Hashing & Bucketing Key
Assignment is determined using deterministic cryptographic hashing on the primary account identifier:
$$\text{bucket} = \text{MurmurHash3_x86_32}\Big(\text{"ad_sched_exp_2025_q3:"} \mathbin{\Vert} \text{user_id}\Big) \pmod{1000}$$
- Buckets 0–499: Assigned to Control (Policy $A$)
- Buckets 500–999: Assigned to Treatment (Policy $B$)
For unauthenticated traffic without a user_id, assignment falls back to a persistent first-party cookie/device ID, isolated in a secondary analysis stratum.
Exposure Control & Triggering
To prevent selection bias, metrics are computed only over triggered users: users who entered an auction where Policy $A$ and Policy $B$ would have made different ad-scheduling decisions. Counterfactual logging records an exposure log event at the moment of eligibility, regardless of whether an ad was ultimately rendered. Frequency capping logic remains uniform across both variants.
2. Stratification and Variance Reduction (CUPED)
Strata Specification
Because a single user spans multiple platform and time-of-day slots, these dynamic dimensions cannot serve as user randomization strata. Instead, we perform post-stratification on pre-experiment user features:
- Primary Client Platform: Web, iOS, Android (determined by modal impressions in pre-period).
- Historical Engagement Tier: Low, Medium, High pre-period impression volume terciles.
- Long-Form Video Consumer: Binary flag ($\ge 20%$ pre-period views on creatives $> 30\text{s}$).
This creates $3 \times 3 \times 2 = 18$ mutually exclusive user strata.
CUPED Formulation
- Pre-period Window: August 12, 2025 to August 25, 2025 (14 full days, ending immediately prior to test launch, capturing two full weekly cycles without overlapping the experiment).
- Covariate ($X_i$): User $i$'s linearized pre-period watch time per impression. For users with zero pre-period impressions, $X_i = 0$, and a missing-indicator interaction term is included in the adjustment model.
The CUPED-adjusted outcome for user $i$ is:
$$\widehat{Y}_{i}^{\text{CUPED}} = Y_i - \hat{\theta} \left(X_i - \bar{X}\right)$$
where $\hat{\theta}$ is estimated globally across pooled arms to avoid bias:
$$\hat{\theta} = \frac{\widehat{\text{Cov}}(Y, X)}{\widehat{\text{Var}}(X)}$$
This reduces metric variance by a factor of $1 - \rho_{XY}^2$, where $\rho_{XY}$ is the linear correlation between pre-period and in-experiment outcomes.
3. Metric Formalization and Outlier Handling
Mathematical Formulation
The target KPI is a ratio metric calculated across the user population:
$$R_g = \frac{\sum_{i \in g} W_i}{\sum_{i \in g} I_i}$$
where $W_i$ is the total winsorized watch time (seconds) for user $i$, and $I_i$ is total ad impressions received by user $i$ in variant $g$.
Evaluating the variance of $R_g$ via standard sample formulas on raw impression rows is mathematically invalid due to intra-user correlation. We apply the Delta Method (Linearization) to project the metric to the user level:
$$L_i = \frac{W_i - R_g \cdot I_i}{\bar{I}}$$
where $\bar{I} = \frac{1}{N} \sum_{i=1}^N I_i$ is the mean impressions per user. The variance of $\bar{L}$ across users accurately models the standard error of $\hat{R}_g$.
Guardrails Definition Table
| Metric Name | Numerator | Denominator | Direction of Harm |
|---|---|---|---|
| CTR | Total Clicks | Total Impressions | Decrease ($\downarrow$) |
| Skip Rate | Total Skipped Ads | Total Skippable Impressions | Increase ($\uparrow$) |
| DAU | Active Days Count | $7 \times N_{\text{users}}$ | Decrease ($\downarrow$) |
| Complaint Rate | Total Negative Feedback Events | Total Impressions / 1,000 | Increase ($\uparrow$) |
ITT & Outlier Handling
- Intent-to-Treat (ITT): Every user who triggers eligibility remains in their assigned arm for evaluation, regardless of client-side ad rendering failures or drop-off.
- Two-Stage Winsorization:
- Impression Level: Cap any single impression watch time at the creative duration $T_{\text{max}}$ (eliminates video player loop bugs).
- User Level: Cap aggregate user watch time $W_i$ at the $99.9\text{th}$ percentile evaluated on the pre-period distribution. The threshold is locked prior to experiment start.
4. Hypothesis Testing Framework
Tail Choice
We conduct a two-tailed test for the primary metric ($\alpha = 0.05$). While policy $B$ is intended to optimize placement, sub-optimal scheduling can induce user fatigue or poor placement relevance, causing negative lift.
Test Statistic Formulation
We use a Welch’s z-test on Stratified CUPED Linearized Means:
$$\hat{\Delta} = \sum_{s=1}^S w_s \left( \bar{Y}^{\text{CUPED}}{B, s} - \bar{Y}^{\text{CUPED}}{A, s} \right)$$
$$\text{SE}(\hat{\Delta}) = \sqrt{ \sum_{s=1}^S w_s^2 \left( \frac{s_{B, s}^2}{n_{B, s}} + \frac{s_{A, s}^2}{n_{A, s}} \right) }$$
$$Z = \frac{\hat{\Delta}}{\text{SE}(\hat{\Delta})} \sim \mathcal{N}(0, 1)$$
where $w_s = \frac{N_s}{N}$ represents the population weight of stratum $s$, and $s_{g, s}^2$ is the sample variance of the linearized CUPED metric in stratum $s$ for group $g$.
Guardrail metrics are tested using one-sided non-inferiority tests with pre-defined non-inferiority margins $\delta_{\text{guardrail}}$ (e.g., CTR relative decrease $< 0.5%$).
5. Sample Size and Stopping Policy
Unadjusted Sample Size Calculation
Given baseline mean $\mu = 42\text{s}$, $\sigma = 55\text{s}$, MDE $= +5% \implies \delta = 0.05 \times 42 = 2.1\text{s}$, $\alpha = 0.05$ (two-sided, $z_{1-\alpha/2} = 1.96$), and power $0.80$ ($z_{1-\beta} = 0.8416$):
$$n_{\text{per arm}} = \frac{2 \cdot (z_{1-\alpha/2} + z_{1-\beta})^2 \cdot \sigma^2}{\delta^2} = \frac{2 \cdot (1.96 + 0.8416)^2 \cdot 55^2}{(2.1)^2}$$
$$n_{\text{per arm}} = \frac{2 \cdot (7.8489) \cdot 3025}{4.41} \approx \mathbf{10,768 \text{ independent units}}$$
Clustering and CUPED Adjustments
-
Intra-User Clustering: If units are impressions with average $m = 6$ impressions/user and intra-class correlation $\rho_{\text{ICC}} = 0.25$:
$$\text{Design Effect (VIF)} = 1 + (m - 1)\rho_{\text{ICC}} = 1 + (5)(0.25) = 2.25$$
Adjusted sample size $= 10,768 \times 2.25 \approx 24,228$ impressions $\approx 4,038$ users per arm.
-
CUPED Variance Reduction: Assuming baseline correlation $\rho_{XY} = 0.5$, variance scales by $(1 - 0.5^2) = 0.75$.
Final required users per arm $\approx 4,038 \times 0.75 \approx \mathbf{3,029 \text{ users per arm}}$.
Sequential Monitoring Policy
We execute a fixed-horizon 7-day test to capture full day-of-week seasonality.
If real-time safety monitoring is required during the run, fixed $p$-value thresholding is strictly forbidden. Instead, we use the mixture Sequential Probability Ratio Test (mSPRT) for guardrail monitoring:
$$\Lambda_n = \int \prod_{i=1}^n \frac{f(Y_i \mid \theta)}{f(Y_i \mid 0)} dH(\theta) > \frac{1}{\alpha_{\text{guardrail}}}$$
Early stopping occurs only for safety breaches (guardrail violations) driven by the mSPRT bound.
6. Readout, Diagnostics, and Corrections
Confidence Intervals & Strata Aggregation
The point estimate for relative lift is $\hat{\gamma} = \frac{\hat{\Delta}}{\hat{R}_A}$. Its $95%$ Confidence Interval is:
$$\hat{\gamma} \pm 1.96 \cdot \sqrt{\operatorname{Var}\left(\frac{\hat{\Delta}}{\hat{R}_A}\right)}$$
where the variance of the ratio is obtained via the second-order Delta Method expansion:
$$\operatorname{Var}\left(\frac{\hat{\Delta}}{\hat{R}_A}\right) \approx \frac{\operatorname{Var}(\hat{\Delta})}{\hat{R}_A^2} + \frac{\hat{\Delta}^2 \operatorname{Var}(\hat{R}_A)}{\hat{R}_A^4} - 2\frac{\hat{\Delta}}{\hat{R}_A^3}\operatorname{Cov}(\hat{\Delta}, \hat{R}_A)$$
Multiple Guardrail Correction: Holm-Bonferroni Procedure
To bound the Family-Wise Error Rate (FWER) at $\alpha = 0.05$ across $k=4$ guardrails:
- Sort guardrail non-inferiority $p$-values in ascending order: $p_{(1)} \le p_{(2)} \le p_{(3)} \le p_{(4)}$.
- Test sequential threshold: $p_{(i)} \le \frac{\alpha}{k - i + 1}$.
- Reject $H_0$ (confirm no harm) sequentially; stop at the first non-significant result.
Diagnostic Checks
┌──────────────────────────────────────────┐
│ Diagnostic Validation Suite │
└────────────────────┬─────────────────────┘
│
┌───────────────────────┴───────────────────────┐
▼ ▼
┌───────────────────────────┐ ┌───────────────────────────┐
│ Randomization Diagnostics│ │ Seasonality & Temporal │
└─────────────┬─────────────┘ └─────────────┬─────────────┘
│ │
┌───────────┴───────────┐ ┌───────────┴───────────┐
▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ SRM Test│ │ Baseline│ │ Calendar│ │ Novelty │
│ (Chi^2) │ │ Balance │ │ Anomaly │ │ Decay │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
- Randomization Balance Diagnostics:
- Sample Ratio Mismatch (SRM): A Chi-square goodness-of-fit test on user assignment counts against the theoretical $50/50$ split. A result of $p < 0.001$ invalidates the experiment data pipeline.
- Pre-Experiment Metric Balance: Calculate Standardized Mean Differences (SMD) on pre-period watch time and impression volume across arms. Any SMD $> 0.05$ signals randomization failure.
- Seasonality and Temporal Diagnostics:
- Holiday Anomaly Check: Note that September 1, 2025 is Labor Day (US Holiday). Run a daily interaction model $\hat{\Delta}_t$; if Sept 1 exhibits a structural shift, report both full 7-day ITT and a 6-day non-holiday sensitivity slice (Aug 26–Aug 31).
- Novelty / Wear-in Decay: Plot daily treatment effects $\hat{\Delta}_t$ over time $t \in [1, 7]$. A monotonic downward trend points to temporary novelty rather than sustainable algorithm performance.
7. Handling Delayed Offline Conversions
Problem Framing
Offline conversion logs exhibit a 24–48 hour ingestion lag. Evaluating the standard window (Aug 26–Sept 1) on Sept 1 leaves the data for Aug 31 and Sept 1 incomplete for offline conversion metrics (e.g., store visits).
Timeline: Aug 26 -------------------------> Aug 30 │ Aug 31 ------ Sep 01
Primary KPI (Watch Time): [ Complete 7-Day Window Included ]
Offline Conversion Metrics: [ Complete Data ] │ [ Incomplete (48h Lag) ]
Re-analysis & Readout Protocol
- Primary KPI Decision Gate: The primary KPI (
watch_time_per_impression) is tracked via immediate online events. Declare the primary decision on the planned Sept 1 readout using the complete 7-day dataset. - Two-Stage Offline Metric Readout:
- Immediate Readout (Truncated Window): For offline conversion guardrails, compute metrics over the fully ingested sub-window: August 26, 2025 to August 30, 2025 (5 days).
- Final Readout (Shifted Window): Hold decision sign-off on offline metrics until September 3, 2025 to allow the full 7-day conversion pipeline (ending Sept 1) to settle.
- Imputation & Survival Modeling (If Early Sign-Off Required): If an early decision is required on Sept 1 for offline metrics, fit a non-parametric right-censored time-to-event model (Kaplan-Meier / Nelson-Aalen) estimating conversion probability $P(T \le t \mid X)$ based on exposure age $t$, adjusting for partial-observation bias rather than treating missing conversions as zeros.