---
title: Experimentation and causal inference
url: https://gurkanozkan.ai/learn/topics/experiments/
markdown: https://gurkanozkan.ai/learn/topics/experiments.md
kind: topic
tracks:
  - ML engineering
  - Applied LLM
  - AI leadership
json: https://gurkanozkan.ai/api/learn/topics/experiments.json
---

# Experimentation and causal inference

Online controlled experiments are how ML and LLM teams prove a model moved a business outcome rather than an offline score. Interviewers test the full loop: choosing the unit of randomisation and the primary, secondary and guardrail metrics, sizing the test from a minimum detectable effect, avoiding peeking, spotting broken experiments (sample ratio mismatch, novelty, interference) and knowing what to do when you cannot randomise or when your own model decides which labels you ever see. Expect to do a sample-size calculation by hand and to explain off-policy evaluation for recommenders or bandits.

## Key concepts

### Experiment design

State a hypothesis and a decision rule before launch. Pick the randomisation unit (user, session, account, region, time slot) so that units do not affect each other and analysis uses the same unit. Define one primary metric (or an overall evaluation criterion) tied to long-term value, secondary metrics that explain why, and guardrails that must not degrade (latency, errors, complaints, cost per request, revenue). Run whole weekly cycles and fix the sample size or a sequential plan in advance.

### Power and minimum detectable effect

For two proportions, n per arm ≈ (z₁₋α/₂ + z₁₋β)² × [p₁(1−p₁) + p₂(1−p₂)] / δ²; with α = 0.05 two-sided and 80% power the multiplier (1.96 + 0.84)² ≈ 7.85. Required n scales with variance and with 1/δ², so halving the MDE quadruples the sample. Keep percentage-point and relative lifts distinct: a 1% relative lift on a 10% baseline is 0.1 pp and needs about 100× the users of a 1 pp lift.

### Variance reduction

CUPED regresses the metric on a pre-experiment covariate (often the same metric before the test): Y_adj = Y − θ(X − mean X) with θ = cov(Y, X)/var(X). Variance falls by a factor (1 − ρ²), so a correlation of 0.7 roughly halves the required sample; Microsoft reported ~50% reductions on Bing. Stratification, capping outliers and choosing more sensitive metrics also help. ML or LLM predictions can serve as covariates in regression adjustment; 2026 work shows how to do this with a 'do no harm' guarantee (falling back to the difference in means when predictions are uninformative), with modest but real gains.

### Peeking and sequential testing

Checking a fixed-horizon test repeatedly and stopping at the first p < 0.05 inflates false positives: about 14% with 5 looks, 19% with 10 and 25% with 20. Valid alternatives are group sequential designs with alpha spending (best power when the maximum sample is known; data arriving in batches), always-valid inference such as mSPRT (any number of looks, streaming data), or simply committing to the horizon. Bayesian dashboards are not immune if stopping rules are not designed in.

### Validity threats

Sample ratio mismatch (observed split differs from design, tested with chi-square) signals broken assignment, logging or bot filtering and invalidates results until explained. Novelty and primacy effects make early weeks unrepresentative; look at effects by cohort and exposure day. Interference violates SUTVA in marketplaces and social products: a dispatch model given to some riders changes couriers available to control riders, so use switchback (time-slot) or geo/cluster randomisation. Multiple metrics and segments need correction or pre-registration; very surprising results usually mean a bug (Twyman's law).

### Ratio metrics and unit mismatch

If you randomise users but analyse per-session or per-query metrics (click-through per query), observations are correlated within users and naive standard errors are too small. Use the delta method or a user-level bootstrap. The same applies to LLM experiments measured per message when assignment is per user.

### Selection bias and feedback loops

When a model gates outcomes, you only observe labels for what it lets through: blocked transactions never get a chargeback, rejected loan applicants never default. Retraining on these labels teaches the model its own past decisions. Remedies: a small randomised holdout or exploration rate that approves some would-be-blocked cases (with risk limits), logging propensities, and reweighting by inverse propensity.

### Off-policy evaluation

To estimate a new policy π₁ from logs of an old policy π₀, inverse propensity scoring weights each logged reward by π₁(a|x)/π₀(a|x). It is unbiased if π₀ gave every action π₁ might take a non-zero probability and the propensities were logged, but variance explodes when weights are large. Self-normalised IPS and weight clipping reduce variance; doubly robust estimators combine a reward model with IPS and stay consistent if either part is right. When you cannot randomise at all, use quasi-experimental designs: difference-in-differences, synthetic control, regression discontinuity or instrumental variables.

## Worked examples

### Sample size for a 10% → 11% conversion test, and the effect of CUPED

Baseline conversion is 10%. How many users per arm detect a 1-percentage-point lift at α = 0.05 (two-sided) and 80% power? What if the lift were 1% relative, and what does CUPED with ρ = 0.5 buy?

**Solution**

**1 pp lift (10% → 11%)**:
n = 7.85 × (0.10 × 0.90 + 0.11 × 0.89) / 0.01² = 7.85 × (0.0900 + 0.0979) / 0.0001
= 7.85 × 1,879 ≈ **14,750 per arm** (~29.5k users in total).

**1% relative lift (10% → 10.1%)**: δ = 0.001, so
n ≈ 7.85 × (0.0900 + 0.0908) / 0.000001 ≈ **1.42 million per arm**. Confusing pp with relative lift
is a 100× planning error.

**CUPED with ρ = 0.5**: variance × (1 − 0.25) → n ≈ 14,750 × 0.75 ≈ **11,060 per arm**.

**Duration**: if 4,000 eligible users arrive per day split 50/50, 14,750 per arm takes ~7.4 days;
round up to a full 7- or 14-day cycle to cover weekday effects.


### Diagnosing a 52/48 split

A 50/50 test shows 52,000 users in control and 48,000 in treatment. In a separate small test the split is 520 vs 480. Which is a sample ratio mismatch, and what do you do?

**Solution**

Expected 50,000 each. χ² = (52,000 − 50,000)² / 50,000 + (48,000 − 50,000)² / 50,000 = 80 + 80 =
**160**, p ≈ 1e-36. This is a definite **SRM**.

Small test: χ² = 400/500 + 400/500 = **1.6**, p ≈ 0.21. Same percentages, but consistent with chance.

For the large test do not interpret the metrics. Look for the cause: treatment crashes or slower
pages losing users before logging, redirects, bot filters that interact with the treatment,
assignment bugs, or triggering conditions that differ between arms. Slice the SRM by platform,
browser and day to localise it; fix and re-run.


### Off-policy estimate from logged propensities

An old recommender showed item A with probability 0.8 and item B with 0.2, and logged propensities. In 10 logged impressions, A was shown 8 times (4 clicks) and B twice (2 clicks). Estimate the click rate of a new policy that always shows B, and comment on reliability.

**Solution**

**Weights**: π₁/π₀ = 0/0.8 = 0 for A impressions; 1/0.2 = **5** for B impressions.

**IPS** = (1/10) × Σ wᵢ rᵢ = (1/10) × (5 × 1 + 5 × 1) = **1.0** (predicted 100% click rate).

**SNIPS** = Σ wᵢ rᵢ / Σ wᵢ = 10 / 10 = **1.0** here too.

The estimate rests on just two impressions; had one B impression not been clicked, IPS would be
0.5. With realistic data the same logic applies at scale: the effective sample size is
(Σw)² / Σw², which collapses when the new policy concentrates on actions the old policy rarely
chose. Use doubly robust estimation with a reward model, clip weights, report confidence intervals,
and confirm promising policies with a live A/B test.


## What changed recently

- **Jun 2026: LLM-simulated A/B tests as a surrogacy problem.** A 2026 paper by Persson, Schultzberg and Ankargren framed 'LLM users instead of A/B tests' as surrogate-outcome inference: raw LLM outputs recovered only 39% of the human treatment effect on the Upworthy headline archive, and calibration against human data was needed to close the gap, with a falsification test and a worst-case bias bound. Simulated users can screen variants, but their effects are correct only under assumptions you must test. [Source](https://arxiv.org/abs/2606.17165)
- **Jun 2026: AI predictions as covariates for variance reduction.** A 2026 paper showed how to use ML or LLM predictions as covariates in regression adjustment, CUPED-style, with a 'do no harm' property: the estimate falls back to the plain difference in means when predictions are uninformative, unlike some prediction-powered inference variants. The reported gains are real but modest. Interviewers who ask about variance reduction now expect you to discuss model-based covariates and their guarantees. [Source](https://arxiv.org/abs/2606.08853)
- **May 2026: Offline evals and online experiments: a funnel, not a fork.** Spotify described LLM evals as a filter in front of experiments: offline judges check output quality cheaply, and online tests check user impact, which judges cannot. It reported that about 12% of its tests ship a win while about 64% yield valid learning (a caught regression, a ruled-out idea), arguing that the win rate understates the value of experimentation. Expect product questions on how an eval suite and an A/B programme divide the work. [Source](https://engineering.atspotify.com/2026/5/better-experiments-with-llm-evals-a-funnel-not-a-fork)
- **Sep 2025: OpenAI buys an experimentation platform.** OpenAI agreed to acquire Statsig, an A/B testing and feature-flagging platform, and its founder became OpenAI's CTO of Applications. AI product companies now treat feature flags and controlled experiments as core infrastructure for shipping model and prompt changes, so candidates for applied roles are expected to know experimentation, not only offline evals. [Source](https://openai.com/index/vijaye-raji-to-become-cto-of-applications-with-acquisition-of-statsig/)
- **Apr 2025: AgentA/B: LLM agents as simulated shoppers.** AgentA/B ran a between-subjects test with 1,000 persona-driven LLM agents navigating Amazon.com web pages, proposing simulated users for faster UI testing. It is the reference point for the question 'could we replace A/B tests with agents?', which strong candidates answer with validation against past experiments and clear limits on external validity. [Source](https://arxiv.org/abs/2504.09723)

## Pitfalls

- Confusing percentage-point and relative lifts, or forgetting that both arms need n.
- Stopping the first day p < 0.05 appears on a fixed-horizon test.
- Interpreting metrics from a test with a sample ratio mismatch.
- Randomising users but computing naive per-session standard errors.
- User-level randomisation in a two-sided marketplace where treatment and control compete for the same supply.
- Treating offline gains as proof of online value; offline–online gaps often come from leakage, feedback loops or metric mismatch.

## How interviewers probe it

- Design the experiment that decides whether to launch a new savings-nudge model: unit, metrics, guardrails, duration, decision rule.
- Compute the sample size for a given baseline and MDE, then name levers to reduce it.
- A PM peeks daily and stops at p < 0.05: what is wrong and what valid alternatives exist?
- Week-one uplift fades and control holds 52% of users: interpret both.
- How do you estimate a new recommendation policy's value from logs of the old one?
- A/B testing an LLM prompt or model: primary vs guardrail metrics (resolution, re-asks, latency, cost), and why per-message metrics need care.

## Reading

- [How Not To Run an A/B Test](https://www.evanmiller.org/how-not-to-run-an-ab-test.html) (Blog, 10 min, Intro): Short, memorable demonstration of how peeking inflates false positives.
- [Trustworthy Online Controlled Experiments: A Practical Guide to A/B Testing](https://experimentguide.com/) (Book, 600 min, Core): The standard practitioner reference; prioritise chapters on metrics, SRM, variance and pitfalls.
- [Improving the Sensitivity of Online Controlled Experiments by Utilizing Pre-Experiment Data](https://exp-platform.com/Documents/2013-02-CUPED-ImprovingSensitivityOfControlledExperiments.pdf) (Paper, 40 min, Core): The CUPED paper: variance reduction with pre-period covariates.
- [A Dirty Dozen: Twelve Common Metric Interpretation Pitfalls in Online Controlled Experiments](https://exp-platform.com/Documents/2017-08%20KDDMetricInterpretationPitfalls.pdf) (Paper, 40 min, Core): Real Microsoft examples of SRM, ratio-metric and novelty mistakes.
- [Always Valid Inference: Bringing Sequential Analysis to A/B Testing](https://arxiv.org/abs/1512.04922) (Paper, 60 min, Deep): Theory behind p-values and intervals that stay valid under continuous monitoring.
- [Doubly Robust Policy Evaluation and Learning](https://arxiv.org/abs/1103.4601) (Paper, 50 min, Deep): Combines reward models with inverse propensity weighting for off-policy evaluation.
- [Causal Inference: The Remix](https://mixtape.scunning.com/) (Book, 120 min, Intro): Free text; read potential outcomes, DAGs and difference-in-differences for non-randomised settings.
- [Better Experiments with LLM Evals — A funnel, not a fork](https://engineering.atspotify.com/2026/5/better-experiments-with-llm-evals-a-funnel-not-a-fork) (Blog, 5 min, Intro): How a large experimentation team combines offline LLM judges with online tests, and why judges cannot replace them.

## Practise this topic

- [You built a new savings-nudge model. Design the experiment that decides whether to launch it.](https://gurkanozkan.ai/learn/questions/mle-designing-an-a-b-test-end-to-end-49.md)
- [Baseline conversion is 10%. How many users per arm do you need to detect a 1-percentage-point lift at α=0.05 and 80% power? What levers reduce it?](https://gurkanozkan.ai/learn/questions/mle-sample-size-and-minimum-detectable-effect-50.md)
- [A PM checks the dashboard daily and stops when p < 0.05. What is wrong, and what valid alternatives exist?](https://gurkanozkan.ai/learn/questions/mle-peeking-and-sequential-testing-51.md)
- [You want to test a new rider-dispatch model at Deliveroo. Why might user-level randomisation give biased results, and what designs help?](https://gurkanozkan.ai/learn/questions/mle-interference-in-marketplaces-52.md)
- [How can you estimate a new recommendation policy's performance from logs collected by the old policy?](https://gurkanozkan.ai/learn/questions/mle-offline-evaluation-of-recommenders-and-bandits-53.md)
- [Your test shows a big uplift in week one that fades. Also, control has 52% of users instead of 50%. Interpret both.](https://gurkanozkan.ai/learn/questions/mle-novelty-effects-guardrails-and-sample-ratio-mismatch-54.md)
- [Transactions your model blocks never get a true label. How does that bias retraining, and how do you correct it?](https://gurkanozkan.ai/learn/questions/mle-feedback-loops-from-model-gated-outcomes-32.md)
- [How would you A/B test a new model or prompt in a chat product? Which metrics are primary, secondary and guardrails?](https://gurkanozkan.ai/learn/questions/applied-llm-evl-04.md)
- [A model shows a big offline improvement but the A/B test is flat. What might be happening?](https://gurkanozkan.ai/learn/questions/lead-td-09.md)
- [A vendor offers to replace part of your A/B testing with LLM agents that role-play user personas and click through your site, as in the AgentA/B research. What…](https://gurkanozkan.ai/learn/questions/recent-a-exp-01.md)
- [A model update passed offline evals, and an A/B test showed users preferred it, but within days it was criticised as 'sycophantic' and rolled back. Explain how…](https://gurkanozkan.ai/learn/questions/recent-a-debug-02.md)
- [Your engineers say coding agents make them much faster, and leadership wants to cut hiring on that basis. METR's 2025 trial found experienced developers 19%…](https://gurkanozkan.ai/learn/questions/recent-a-lead-01.md)
- [You are A/B testing a new LLM model and prompt for a customer-support assistant. Outputs are non-deterministic, the provider may update the model mid-test, and…](https://gurkanozkan.ai/learn/questions/recent-a-exp-02.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
