Potential outcomes, the fundamental problem and randomized experiments
Before this lesson: lesson 01 (association versus causal effect, confounding); expectation and variance (probability lesson 02) and confidence intervals (probability lesson 06). Helpful: hypothesis testing and A/B testing. Time: about 85 minutes, plus the notebook.
Why this matters #
- A/B tests are randomized experiments. Every claim "the new ranking model raises clicks by 2%" rests on the logic of this lesson. When the logic breaks (users talk to each other, the split is not really random), the numbers are wrong.
- Clinical trials are randomized for the same reason. Regulators accept a drug on a randomized trial, not on observational data.
- Observational methods (lessons 05–08) try to imitate a randomized experiment. Their assumptions (exchangeability given , positivity) are the conditions of this lesson, made conditional on covariates.
- Causal ML (uplift models, heterogeneous effects in lesson 08) estimates the CATE , defined here.
1. Predict first #
2. The picture #
Two columns for every unit #
Eight students () can take a tutoring program () or not (). For each student there are two potential outcomes: , the test score if the student takes tutoring, and , the score if not. The individual treatment effect is . A table of both columns for all units is called the science table. These numbers are made up for teaching:
| student | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 40 | 45 | 50 | 55 | 70 | 75 | 80 | 85 | |
| 50 | 55 | 58 | 63 | 74 | 78 | 84 | 88 | |
| 10 | 10 | 8 | 8 | 4 | 3 | 4 | 3 |
Tutoring helps every student, and it helps the weak students most. The average treatment effect is points.
Now suppose the four weakest students choose tutoring: . We see for students 1–4 and for students 5–8, and nothing else.
Switch between "what nature knows" and "what we see". In the second view the potential outcome that did not happen is a grey "?". Change who takes tutoring, or click a cell to move one student. Blue rows are treated, orange rows are controls. The bars show the naive difference split into the effect on the treated (ATT) and the selection bias; the dashed aqua line is the true ATE. Notice: when the weakest choose, the naive difference is although every effect is positive.
The naive difference compares the observed means: . The data seem to say "tutoring lowers scores by 21 points". The reason: the tutored students were weaker before tutoring. Without tutoring, their mean would have been , far below the controls' . This gap of is the selection bias. The effect on the tutored students themselves is . And indeed .
A science table has four units: , . Units 1 and 2 are treated. What are the ATE, the ATT and the naive difference?
, so the ATE is and the ATT (units 1 and 2) is . We observe for units 1–2 (mean 5) and for units 3–4 (mean 7), so the naive difference is . The selection bias is , and .
The fundamental problem #
For each unit we observe only
The other potential outcome is the counterfactual: what would have happened under the other treatment. Holland (1986) called this the fundamental problem of causal inference: we can never observe for any unit. So causal inference is a missing-data problem. Every method of this track fills the missing half of the science table with assumptions plus data. The question is always: which assumptions, and can we defend them?
3. Definitions and main results #
Potential outcomes and the assumptions that link them to data #
The potential-outcomes framework goes back to Neyman (1923) for experiments and Rubin (1974) for observational studies; it is also called the Neyman–Rubin model. We write for the treatment and for the outcome. Other books use (Hernán and Robins), (economics), (Imbens and Rubin) or (Pearl) for the treatment; the ideas are the same.
To connect the potential outcomes to the data we need two assumptions.
- Consistency. If unit receives treatment , its observed outcome is its potential outcome under : . This needs a well-defined treatment: "tutoring" must mean one program, not ten different ones. "Being overweight" is a poor treatment: diet, exercise and surgery all change weight, with different effects on health.
- No interference. The potential outcomes of unit depend only on 's own treatment, not on the treatments of other units. It fails for vaccines (my infection risk depends on whether my family is vaccinated), for social networks (my posts depend on my friends' feed), and for marketplaces (a discount for some buyers takes items away from others).
Together these two are the stable unit treatment value assumption (SUTVA) (Rubin 1980). Without SUTVA, is not even one number: it depends on everyone else's treatment.
Estimands: which average do we want? #
The estimand is the quantity we want to know. The estimator is the recipe that turns data into a number. The estimate is the number we get. Four common estimands:
| Estimand | Definition | Question it answers |
|---|---|---|
| ATE | What if we treat everyone versus no one? | |
| ATT | What did the treatment do for those who took it? | |
| ATC | What would it do for those who did not take it? | |
| CATE | What is the effect for units with covariates ? |
For the tutoring table with the four weakest treated: ATE , ATT , ATC . They differ because the effect differs between students. A school that wants to make tutoring compulsory needs the ATE; a school that asks "was our voluntary program worth it?" needs the ATT. The covariates are always pre-treatment: measured before and not affected by it.
Why the naive difference fails #
Proposition (decomposition of the naive difference). Under consistency,
Proof.
- By consistency, when and when . So the naive difference is .
- Subtract and add the same term (the treated group's mean without treatment, which we never observe): .
- By linearity of expectation, the first bracket is .
The selection bias compares the two groups as they would be without treatment. It is zero when the groups are alike in their . With the weakest students treated it is , and . With the strongest treated, the naive difference is .
Identification: exchangeability #
Identification means writing the estimand as a function of the distribution of the observed data (or ). Only then can data estimate it. We separate two steps: what the data can identify (this section), and how to estimate it well (the next sections).
- Exchangeability (also called ignorability or unconfoundedness): . The treatment is independent of the potential outcomes: the treated and the untreated would have had the same distribution of outcomes under either treatment.
- Positivity: . Both groups exist.
Theorem. Under consistency, exchangeability and positivity, for : . Hence .
Proof.
- , by exchangeability: is independent of , so conditioning on does not change its mean. The conditional mean is defined because of positivity ().
- , by consistency: in the group with , is the observed .
- Take the difference of the results for and .
In the decomposition, exchangeability makes the selection bias zero and the ATT equal to the ATE. In observational data we cannot test exchangeability: it is a statement about of the treated, which is never observed. Conditional exchangeability and positivity given , , are the versions used with observed confounders in lesson 05. Positivity can be checked in data; conditional exchangeability cannot.
Randomization makes exchangeability true by design #
In a randomized experiment the experimenter assigns with a random device: a coin for each unit (Bernoulli randomization), or a lottery that picks exactly of units (complete randomization). The random device does not look at the units. So is independent of everything about the units, including and every covariate, measured or not. Exchangeability holds by construction, and the theorem gives .
There is also an exact finite-sample version. Fix the units and their science table. Only the lottery is random.
Theorem (Neyman 1923). Under complete randomization with treated and controls, the difference in means is unbiased for the sample ATE , and
where and .
Proof of unbiasedness (and where the variance comes from)
- By consistency, . The potential outcomes are fixed numbers; only the are random.
- Every unit has the same chance to be treated: , so and .
- By linearity: .
The variance needs the covariances for (drawing one unit for treatment makes the others slightly less likely). A direct calculation with these covariances gives the formula (Imbens and Rubin 2015, chapter 6). The notebook checks it by enumerating all assignments.
"Unbiased" means "right on average over the lotteries". One experiment can still miss. With the tutoring table there are possible lotteries. Their 70 estimates have mean exactly and range from to ; 20 of the 70 (28.6%) are negative.
Press "Randomize once" a few times, then "Randomize 1000 times" and "All 70 assignments". Each experiment gives tutoring to 4 of the 8 students by lottery. The blue histogram collects the estimates; the aqua line is the true ATE, 6.25. Notice that the mean of the histogram is on the aqua line, but single estimates spread with an SD of about 11. Switch to the Fisher view: one experiment, the sharp null, and the exact p-value (observed statistic in magenta).
Balance. Randomization balances every covariate on average: the expected difference in means of any pre-treatment variable between the groups is zero, for measured and unmeasured variables alike. In one experiment, chance imbalance happens, and it is the reason for the spread above.
In one randomized A/B test, the difference in means came out 3 units above the true ATE (you know the truth because the data were simulated). What does this show?
Unbiasedness is a property of the distribution of the estimator over all possible lotteries: . A single estimate differs from by a random error whose size is described by . To see bias, you would need the average over many repeated experiments (the histogram in the figure).
Neyman's variance and why the usual estimate is conservative #
For the tutoring table: , , , , :
The SD is . This is exactly the variance of the 70 estimates in the figure.
In a real experiment we do not know : it needs both potential outcomes of the same unit. The usual estimate replaces and by the sample variances of the observed groups and drops the last term:
Its expectation is (here against ). So it is conservative: confidence intervals are a little too wide, never too narrow on average. The two agree when the effect is the same for every unit (). With large , is close to normal (central limit theorem), and is an approximate 95% confidence interval (probability lesson 06).
Fisher's randomization test #
Fisher (1935) asked a different question. The sharp null hypothesis says the treatment has no effect for any unit: for all , that is, . Under the science table is fully known: both potential outcomes equal the observed . So we can compute the test statistic for every possible lottery, and the p-value is exact, with no large-sample approximation.
Fisher randomization test.
- Choose a statistic, for example the difference in means . Compute it on the real assignment: .
- Under , the outcome vector stays the same for every assignment. For each possible assignment (all of them, or many random ones), compute .
- The two-sided p-value is the share of assignments with .
The p-value is valid in any sample size, because it uses only the randomization that the experimenter really did. It is the permutation test of probability lesson 12, seen as a causal test.
Two different nulls. Neyman's null is "the average effect is zero": . Fisher's sharp null is "the effect is zero for every unit". The sharp null is stronger. Effects of for half the units and for the other half satisfy Neyman's null but not Fisher's.
Effects are for half of the users and for the other half. Which null hypothesis is true?
The average effect is , so Neyman's null holds. Fisher's sharp null needs for every unit, and here no unit has a zero effect. A test of the sharp null can reject although the ATE is zero, because the outcomes spread more in one group.
Better designs: blocking and regression adjustment #
The spread of comes from chance imbalance in covariates that affect the outcome. Two tools reduce it.
- Blocking (stratified randomization). Group units into blocks with similar covariates (age groups, countries, user segments) and run a separate lottery inside each block. The estimate is a weighted average of the block estimates (weights = block sizes). Inside each block the covariate is nearly constant, so the imbalance in it is removed by design. The estimate stays unbiased. Its variance is much smaller when the blocking variable predicts the outcome. When the blocking variable does not predict the outcome, blocking costs little (in small samples it can be slightly worse). Matched pairs are blocks of size 2.
- Regression adjustment. Regress on and pre-treatment covariates . Lin (2013) showed that the regression with , centered and their interaction is consistent for the ATE and asymptotically never less precise than the difference in means, even if the linear model is wrong. CUPED, a common variance-reduction method in A/B testing, is regression adjustment on the pre-experiment value of the metric (see probability lesson 12).
Never adjust for a post-treatment variable. A variable measured after the treatment can be affected by it (a mediator, lesson 01). Adjusting for it removes part of the effect, or creates bias by selecting different kinds of units in each group. The covariates in blocking and in regression adjustment must be pre-treatment.
Switch between the three designs and press "Assign again"; then press "Run 500 experiments". The top panel shows the age of the treated (above the axis) and the controls (below); dashed lines mark the group means. Age raises the outcome. In the bottom panel each row collects 500 estimates; the aqua line is the true effect, 5. Self-selection (magenta) is biased by more than 10 points. Complete randomization is centered on 5 with an SD of about 2.5. Blocking by age is also centered on 5, with an SD of about 1.
In an A/B test of a new home page, should the analysis adjust for "number of sessions during the test" to reduce variance?
Randomization guarantees balance only for variables fixed before assignment. If the new page changes how often people visit, "sessions during the test" is partly an outcome of the treatment. Adjusting for it compares users with the same number of sessions, who are different kinds of users in the two groups. Use the number of sessions before the test (CUPED) instead.
A/B tests are randomized experiments #
Online experiments add a few practical points.
- Unit of randomization versus unit of analysis. If you randomize users but analyze page views, the page views of one user are correlated, and the usual standard error is too small. Analyze at the level of the randomized unit, or use cluster-robust standard errors.
- Sample-ratio mismatch (SRM). If the design splits 50/50 and you see 50,600 against 49,400 users, a chi-square test gives , . Something broke the randomization (a bug, a redirect, bots), and the groups may no longer be exchangeable. Check SRM before you read any result.
- Interference. In marketplaces and social networks, treating one user affects others, and SUTVA fails. Cluster randomization randomizes whole groups (cities, schools, friend clusters). Switchback designs switch a whole market between treatment and control over time windows.
- Sample size and peeking. How many users you need, and why stopping at the first significant result inflates false positives, are covered in probability lesson 12 and interview lesson 09.
Answers to section 1. (1) Yes. With the weakest four treated, the tutored mean is 56.5 and the other mean is 77.5: a naive difference of , while every . The selection bias () is larger than the effect on the treated (). (2) No. Unbiasedness is about the average over all lotteries; one estimate has random error with SD about 11 in the tutoring example. (3) The smallest two-sided p-value is : the observed assignment and its mirror image are the two most extreme of the 70.
4. Worked example #
(a) Estimands and the decomposition. Use the tutoring table with the four weakest students treated, .
- Individual effects: .
- ATE: .
- ATT (students 1–4): . ATC (students 5–8): . Check: .
- Observed means: treated ; control . Naive difference .
- Selection bias: , minus , gives .
- Check: . ✓
(b) Neyman's variance. Same table, complete randomization with .
- . .
- . .
- . .
- ; SD .
- Without the last term: (SD ), the conservative value.
(c) Fisher's test by hand, with four units. Two of four units are treated by lottery: units 1 and 2. Observed outcomes . The statistic is .
- Under the sharp null, the outcomes stay the same under every lottery.
- There are lotteries. Treated pairs and statistics: : ; : ; : ; : ; : ; : .
- Lotteries with : two of six. p-value .
Even the most extreme result gives : four units can never show a significant effect. The test is exact, but the design decides what it can detect.
(d) One real lottery for the eight students. Suppose the lottery tutors students 1, 3, 4 and 7. Observed: treated , mean ; controls , mean ; , although the true ATE is . Fisher's test over the 70 lotteries gives . With eight students, chance imbalance dominates: here the control group happens to contain three of the four strongest students (5, 6 and 8).
5. In code #
NumPy checks parts (a), (b) and (d). The notebook has these cells and the exercises.
import numpy as np
from itertools import combinations
Y0 = np.array([40, 45, 50, 55, 70, 75, 80, 85.])
Y1 = np.array([50, 55, 58, 63, 74, 78, 84, 88.])
tau = Y1 - Y0
T = np.array([1, 1, 1, 1, 0, 0, 0, 0]) # the four weakest take tutoring
naive = Y1[T == 1].mean() - Y0[T == 0].mean()
att = tau[T == 1].mean()
bias = Y0[T == 1].mean() - Y0[T == 0].mean()
print(tau.mean(), att, naive, bias) # 6.25 9.0 -21.0 -30.0
# all 70 lotteries that give tutoring to 4 of the 8 students
est = []
for treated in combinations(range(8), 4):
t = np.zeros(8, dtype=int); t[list(treated)] = 1
est.append(Y1[t == 1].mean() - Y0[t == 0].mean())
est = np.array(est)
neyman = Y1.var(ddof=1) / 4 + Y0.var(ddof=1) / 4 - tau.var(ddof=1) / 8
print(len(est), est.mean(), est.var().round(2), neyman.round(2)) # 70 6.25 122.24 122.24
print((est < 0).mean().round(3)) # 0.286
# Fisher randomization test for one lottery: students 1, 3, 4, 7 tutored
t_obs = np.array([1, 0, 1, 1, 0, 0, 1, 0])
y_obs = np.where(t_obs == 1, Y1, Y0)
stat = y_obs[t_obs == 1].mean() - y_obs[t_obs == 0].mean()
null = []
for treated in combinations(range(8), 4): # sharp null: y_obs is the whole table
t = np.zeros(8, dtype=int); t[list(treated)] = 1
null.append(y_obs[t == 1].mean() - y_obs[t == 0].mean())
p = np.mean(np.abs(null) >= abs(stat) - 1e-9)
print(stat, p.round(3)) # -5.0 0.686
est.var() divides by the number of lotteries (70), because the 70 lotteries are the whole
population of possible experiments. The small tolerance 1e-9 protects the comparison from rounding.
6. Where it shows up #
- Online experiments. Search, ads, feeds and recommenders run thousands of A/B tests a year. Ranking-model launches are decided on randomized comparisons of user metrics, not on offline accuracy alone (Kohavi, Tang and Xu 2020).
- Clinical trials and vaccine trials. Randomized controlled trials are the standard of evidence. Vaccine trials face interference; cluster-randomized trials randomize villages or schools.
- Uplift modeling and heterogeneous effects. Marketing targets users with a high CATE , not users with a high predicted outcome. Randomized data are the best training data for these models (lesson 08).
- Policy learning and bandits. Logged data from randomized policies allow unbiased evaluation of new policies by importance weighting (lesson 11, RL lesson 03).
- ML for science. Randomized designs appear in agricultural field trials (Fisher's original setting), in perturbation screens in biology (CRISPR knockouts as interventions) and in randomized evaluation of AI tools in scientific workflows.
7. Common mistakes #
- Reading the naive difference as an effect. It is plus selection bias. Check: ask how units got their treatment; if they chose it, expect selection bias.
- "Unbiased" means "correct in my sample". No: correct on average over randomizations. Check: report a confidence interval, not only the point estimate.
- Mixing up estimands. ATE, ATT and ATC differ when effects differ between units. Check: write the estimand before the estimator, and say which population it is about.
- Ignoring interference. If treated users affect control users, the difference in means does not estimate any of the usual estimands. Check: ask whether units interact; consider cluster or switchback randomization.
- Adjusting for post-treatment variables. It breaks the balance that randomization gave. Check: every covariate in the analysis must be measured before assignment.
- Skipping the randomization check. A sample-ratio mismatch or covariate imbalance far beyond chance means the randomization failed. Check: test the split ratio and the balance of pre-treatment covariates first.
- Confusing the sharp null with "no average effect". Fisher's test answers "no effect for anyone"; Neyman's confidence interval answers questions about the ATE.
8. Check yourself #
- Write the observed outcome in terms of , and . Which assumption does
this use?
Answer
. It uses consistency (and no interference, so that depends only on ). - In the tutoring table, let the four strongest students take tutoring. Compute the naive
difference, the ATT and the selection bias.
Answer
Treated mean ; control mean ; naive . ATT . Selection bias . Check: . - A vaccine trial randomizes individuals inside the same households. Which assumption is in danger,
and what design fixes it?
Answer
No interference (part of SUTVA): a vaccinated family member lowers the infection risk of an unvaccinated one, so control outcomes depend on others' treatment. Randomize whole households (cluster randomization), and analyze at the household level. - Why is the usual variance estimate conservative?
Answer
The true variance is . The term (the spread of individual effects) cannot be estimated, because no unit shows both potential outcomes. Dropping it gives an expectation that is at least the true variance; equality holds when all are equal. - Give one reason to report the ATT instead of the ATE.
Answer
When the policy question is about those who take the treatment, for example "was the voluntary program worth it for its participants?". The ATT is also identified under weaker assumptions in some designs (it needs only to be exchangeable). - In a test with 10 units and 5 treated, what is the smallest possible two-sided Fisher p-value
with the difference in means?
Answer
There are assignments. The observed assignment and its mirror (treated and control swapped) give , so at best 2 of 252 are as extreme: (if no other assignment gives the same absolute value).
What are the potential outcomes and ?
The outcome unit would have with the treatment and without it. The individual effect is .
State the fundamental problem of causal inference.
For each unit we observe only one potential outcome, , so the individual effect is never observed.
What are the two parts of SUTVA?
Consistency (a well-defined treatment: ) and no interference (a unit's outcomes do not depend on other units' treatments).
Decompose the naive difference in means.
: effect on the treated plus selection bias.
Define exchangeability, and say why randomization gives it.
. A random device assigns without looking at the units, so is independent of everything about them, including their potential outcomes.
Compute the ATT and ATE: , units 1–4 treated.
ATT ; ATE .
Give Neyman's variance of the difference in means under complete randomization.
. The last term is not identifiable, so the usual estimate is conservative.
What is Fisher's sharp null, and why does it give an exact test?
for every unit. Under it both potential outcomes equal the observed outcome, so the statistic is known for every possible assignment, and the p-value is the share of assignments at least as extreme.
Why must you not adjust for a post-treatment variable in an experiment?
It can be affected by the treatment. Adjusting removes part of the effect or compares different kinds of units, so it breaks the balance that randomization created.
When do you report the ATE and when the ATT?
ATE for a policy of treating everyone versus no one; ATT for the effect on those who actually took the treatment.
9. Interview angle #
- "Why do we randomize?" — Randomization makes the treatment independent of the potential outcomes (exchangeability), so the difference in means is unbiased for the ATE. It balances unmeasured confounders too, which no adjustment can do.
- "What is SUTVA, and when does it break in a marketplace?" — Consistency plus no interference. In a two-sided marketplace, a price change for treated buyers changes supply for control buyers, so control outcomes are contaminated. Use switchback or cluster (market-level) randomization.
- "Your A/B test shows +2%, but the treatment group has more users than planned. What do you check?" — Sample-ratio mismatch: a chi-square test of the split. If it fails, find the cause (bucketing bug, redirects, bot filtering, a crash that drops users from one arm) before trusting any metric.
- "Can you adjust for covariates in an A/B test?" — Yes, for pre-treatment covariates (CUPED, Lin's interacted regression): unbiasedness stays (asymptotically) and variance falls. Never for post-treatment variables.
- See interview lesson 09 for sample size, power and peeking.
10. Practice #
The notebook for this lesson has five exercises, each with a check cell and a folded solution:
naive_decomposition(Y0, Y1, T)returns the naive difference, the ATT and the selection bias; check .- Enumerate all 70 lotteries; check unbiasedness and Neyman's variance exactly.
fisher_test(y, t, n_perm, seed): the randomization p-value for the sharp null; compare it with a t-test p-value on a larger simulated A/B test.- Blocked versus complete randomization: simulate 2,000 experiments and compare the SD of the estimate; then the Lin regression adjustment on a pre-treatment covariate.
- Bad adjustment: add a post-treatment covariate (affected by ) to the regression and measure the bias against the known truth.
11. Watch and read #
- Miguel Hernán and James Robins, Causal Inference: What If, free book, chapters 1–2 (potential outcomes, randomized experiments).
- Brady Neal, Introduction to Causal Inference, free PDF, chapter 2.
- Scott Cunningham, Causal Inference: The Mixtape, ch. 3 "Potential Outcomes and Randomization", free online (potential outcomes, Fisher's exact test).
- Winston Lin, "Agnostic notes on regression adjustments to experimental data" (Annals of Applied Statistics, 2013), free on arXiv.
- Books to know (not free): Guido Imbens and Donald Rubin, Causal Inference for Statistics, Social, and Biomedical Sciences (2015), chapters 1–6; Ron Kohavi, Diane Tang and Ya Xu, Trustworthy Online Controlled Experiments (2020); Paul Holland, "Statistics and causal inference", JASA 1986.
Runs in your browser with nothing to install. The notebook repeats the key demos and has exercises with checks; solutions are inside, folded.
No Google account needed: Python runs inside your browser. The first start downloads about 40 MB; your changes are saved in this browser only.