Check the split for a sample ratio mismatch before you read any metric
Run the two-proportion z-test with the pooled standard error, build the interval with the unpooled one, and say why they differ
Compute a two-sided p-value and a confidence interval at the same alpha, with only the standard library
Say the lift in points and as a percent, and tell a significant result from one worth shipping
Turn a result into a launch call, including what to say when p = 0.04 on day 2 of a 14-day test
Answer the follow-ups on peeking and sequential tests, many metrics, novelty effects, guardrails and heavy-tailed revenue
Part 1 of 6about 13 min
The split
A two-proportion test, from counts to a launch call
One OpenAI senior data scientist candidate reports a take-home that asked how you'd define success metrics and decide whether the launch was a success (1 report). Airbnb asks it in other words: a prep site lists Airbnb screens that say "Recommend whether to launch based on an experiment you design" (1 source), and that ask you to design and then analyze an experiment for a luggage locker feature (1 source). Our version reads like this:
We split users at random between the current page, A, and a new one, B. A converted 200 of 2,000 users, and B converted 250 of 2,000. Write two_proportion_test(conv_a, n_a, conv_b, n_b, alpha=0.05, share_b=0.5). Return B's rate minus A's, the z statistic, a two-sided p-value, a 1 - alpha confidence interval for the gap, and whether the split itself missed its plan. Then tell me: do we launch?
The practice comes in four levels, each one a key in the dict the function returns. Level 1 returns diff, B's rate minus A's, and z, with the standard error the null predicts. Level 2 adds p_value, two-sided. Level 3 adds ci, the interval, with each group's own standard error. Level 4 adds srm, which flags a split that missed share_b, the share of users the plan sent to B.
You don't write it yet. The lesson reads a test in the order you'd read a real one: check the split, ask what chance alone could do, build the test and the interval, then make the call and answer the follow-ups. At the end you solve the whole problem, level by level, in an interview simulation with a 35-minute timer.
The sample-size lesson comes next. It plans a test before it runs: how many users the test needs to detect the lift you care about.
An A/B test asks whether a gap is bigger than chance could make
The practice hands you two conversion rates. Before any formula, guess what chance alone could do to them.
Predict
A converts 10.0% and B 12.5%, on 2,000 users each. Could chance alone make a gap this big?
The practice problem's example
A, current
10.0%
B, new
12.5%
200 of 2,000 against 250 of 2,000, with users split at random. A gap of 2.5 points: the change, or chance?
Users are split at random between a control, A, and a treatment, B. Each user converts or doesn't, and a group's conversion rate is its conversions over its users: p^A=xA/nA. The hat marks a rate measured from the data, an estimate of A's true rate pA. B's rate p^B works the same way.
Randomization makes the groups alike in everything except the change. So a gap comes from the change or from chance, and your job is to say how much chance could do. Interviewers notice when you can: one Airbnb candidate came out of a hiring manager screen saying "they seem to really care about experiments" (1 report).
In the editor, write rates(conv_a, n_a, conv_b, n_b): each group's rate and the gap, the first three numbers the practice function computes.
Before you compare the rates, check that the groups are still the ones randomization made. A broken split leaves them unalike.
One way a split breaks (an example)Interactive
→
→
users assigned to B.
Randomization promises a ratio, usually 50/50. Sometimes the user counts miss it by more than chance allows. Then something added or removed users on one side: a bug that crashes the treatment on one browser, a redirect that loses people, bot filtering that hits one variant harder.
The users who went missing aren't random. Here B lost its old-browser users and A kept them, so every metric comparison inherits the bias. That's a sample ratio mismatch, or SRM: a split that misses its planned ratio by more than chance allows.
Fabijan and colleagues studied it across four companies, including Microsoft and Booking.com. They put it bluntly: "Sample Ratio Mismatch in most cases completely invalidates experiment results." They found one in "approximately 6% of experiments at Microsoft".
In the editor, users_a and users_b count each group's users by browser, the way a dashboard splits them. Write where_missing(users_a, users_b): the browser where B is shortest against A, which is where to look for the bug.
A whole browser gone from B is easy to spot. Most broken splits are subtler, so the check has to say how far off is too far.
from math import sqrtfrom statistics import NormalDistdef srm_p_value(n_a, n_b, share_b=0.5): n = n_a + n_b z = (n_b - n * share_b) / sqrt(n * share_b * (1 - share_b)) return 2 * (1 - NormalDist().cdf(abs(z)))for n_a, n_b in [(520, 480), (50_600, 49_400), (821_588, 815_482)]: share = max(n_a, n_b) / (n_a + n_b) p = srm_p_value(n_a, n_b) print(f"{n_a:>7,} vs {n_b:>7,} " f"larger share {share:.1%} p = {p:.2g}")
Predict
Which split is the real alarm: 52.0% of 1,000 users, or 50.6% of 100,000?
Pick one to see what it prints.
The first is noise. The second is closer to 50/50, and it's an alarm. The third is the paper's own example, which it says had a chance of "less than 1 in 500k" of happening by luck.
So don't judge a split by eye. Judge it by how far B's count sits from the plan, in standard deviations: the z in the code.
How far each split sits from the plan, in |z|
52.0% of 1,000
1.26: noise
the cutoff, p < 0.001
3.29
50.6% of 100,000
3.79: alarm
50.2% of 1.6 million
4.77: alarm
A bigger test has less noise in its share, so a smaller miss sits further out.
The code is a z-test on B's count:
z=Nπ(1−π)nB−Nπ,N=nA+nB
In words: N is all the users and π is B's planned share, so Nπ is the count the plan expects for B. The bottom is the standard deviation of that count. This is the chi-square goodness-of-fit test with two groups: z2 is its chi-square statistic.
NormalDist() is the standard normal curve from Python's statistics module, and .cdf(x) is the chance that a draw from it lands at or below x. So the last line of srm_p_value is the chance, if the split worked as planned, of a z at least this far from 0 in either direction: a p-value, which the p-value chapter takes apart.
Pick an answer above to see the rest
Predict
The SRM check runs on every experiment. Why use a strict cutoff like p < 0.001 instead of 0.05?
Use a strict cutoff, such as p < 0.001, which is ∣z∣ above 3.29. The check runs on every experiment, and at 0.05 it would flag one healthy test in 20. When it fires, don't read the metrics. Find the cause first.
An on-call dashboard wants the check the other way round: which counts are fine? In the editor, write quiet_range(n, share_b, alpha): the fewest and the most of n users that B can get before the check fires. It takes the planned share, because a 10% ramp plans 10% for B, not half. It prints the range for a 50/50 test of 100,000 users, then for a 10% ramp of 10,000.
The test asks how often chance alone makes a gap this big
With no real difference, the gap still moves from run to run. This code shows how far.
import randomfrom statistics import pstdevrng = random.Random(1)n, rate = 2000, 0.1125gaps = [rng.binomialvariate(n, rate) - rng.binomialvariate(n, rate) for _ in range(100_000)]share = sum(abs(g) >= 50 for g in gaps) / len(gaps)print(f"spread of the gap: {pstdev(gaps) / n:.4f}")print(f"gaps of 50 users or more: {share:.2%}")
Predict
Both pages convert at 11.25%, with 2,000 users each. How often does chance alone make a gap of 2.5 points or more?
Pick one to see what it prints.
This plays the worked example 100,000 times with no real difference. Both pages convert at 11.25%, the rate of all 4,000 users together. rng.binomialvariate(n, p) draws how many of n users convert at rate p. It's new in Python 3.12.
Each run's gap is B's conversions minus A's. A gap of 50 users out of 2,000 is 2.5 points, the worked example's gap.
The gap under the null, in pointsInteractive
-3-2-10123points
Both tails beyond 2.50: 0.62% each, so p = 1.24%.
The 100,000 gaps pile up around 0 in a bell like this one, with a spread of 1 point. A gap of 2.5 points or more, in either direction, showed up in 1.32% of runs. The smooth curve's two shaded tails hold 1.24%.
That is the question a test asks. The null hypothesis says the two versions convert at the same rate, pA=pB. The test asks how often a gap as large as yours would show up if that were true.
In the editor, gaps holds the simulation's first 20 runs. Write share_at_least(gaps, size): the line that counts the gaps at least size users from 0, in either direction.
You don't need 100,000 runs to know how far the gap moves. One rule about variances gives it.
Predict
The variance of a difference of two independent estimates is what?
The last step's simulation put the gap's spread at 0.0100, 1 point. That spread is the gap's standard error: its standard deviation across repeated experiments of this size. You don't need a simulation to get it.
Each rate is an average of 0s and 1s, with variance p(1−p)/n. The variance of a difference of independent estimates is the sum of their variances. So the variance of p^B−p^A is
nApA(1−pA)+nBpB(1−pB)
In words: each group adds its own rate's variance, p times 1−p over its users. The standard error is the square root of the sum.
With dozens of conversions in each group, not a handful, the difference is close to normal. So dividing it by its standard error gives a z score: how many standard errors the gap sits from 0.
In the editor, write null_se(rate, n_a, n_b): the standard error when both groups convert at one rate, as in the simulation.
The test and the interval use different standard errors
What's left is which rates to plug into the standard error. The two halves of the practice function answer that differently, because they ask different questions.
The test centers on 0, and the interval on your gap
0your gap
the test95% of the gaps the null makes: -1.96 to 1.96
the intervalyour gap, give or take: 0.54 to 4.46
-3-2-1012345
points
The test asks: if both pages had one rate, how odd is a 2.5-point gap? Its curve sits on 0, the null's gap.
The interval asks: how big is the gap? It sits on the gap you measured, 2.5 points, and reaches out on both sides.
Each needs a standard error that fits its question.
The test's standard error comes from the null
Predict
Under the null hypothesis, how many conversion rates are there?
Under the null there's one rate. So estimate it once, from everyone:
In words: p^ is the pooled rate, all conversions over all users, 450 / 4,000 = 0.1125 in the worked example. SE0 is the variance formula above with both rates set to p^, under a square root. The 0 says it's the standard error the null predicts. Then z is the gap over it.
Estimated from all the users at once, it stays steady even when one group is small, and that keeps the false positive rate at the 5% you asked for. In simulations with no real difference, from 2,000 users per group to lopsided splits like 300 against 3,000, the pooled z crossed 1.96 in 4.6% to 5.0% of tests.
The pooled z-test is also the chi-square test of the 2 by 2 table of converted and not converted. z2 equals Pearson's chi-square statistic exactly, 6.2598 for both in the worked example. If an interviewer asks for one, you've written the other.
In the editor, write pooled_z(conv_a, n_a, conv_b, n_b): the gap over the standard error the null predicts, from one rate pooled across everyone.
CheckpointThe z statistic, pooled
Write pooled_z(conv_a, n_a, conv_b, n_b): B's rate minus A's, divided by the standard error the null predicts from one rate pooled across all the users. It has to work on lopsided groups too, like a 10% ramp where 1,000 of 10,000 convert in A and 120 of 1,000 in B.
Pick an answer above to see the rest
The interval keeps each group's own rate
The interval measures the difference, so it can't assume the difference is zero. Each group keeps its own rate:
In words: this is the unpooled standard error, the variance formula with each group's measured rate. The interval is the gap, plus or minus a multiplier times that standard error.
α is the significance level, the false positive rate you accept, so α=0.05 gives a 95% interval. z1−α/2 is the multiplier that leaves α/2 of the normal curve in each tail, 1.96 at that α. The next chapter computes it.
This is the Wald interval, the one the practice problem asks for.
In the editor, write unpooled_se(conv_a, n_a, conv_b, n_b): the interval's standard error, with each group's own rate.
CheckpointThe interval's standard error
Write unpooled_se(conv_a, n_a, conv_b, n_b), the standard error the interval uses, where each group keeps its own rate. On the 10% ramp, 1,000 of 10,000 against 120 of 1,000, it comes out larger than the pooled 0.01003, because the small group is the noisy one.
With equal groups and close rates, the two standard errors barely differ
You now have two standard errors for the same gap. Guess how far apart they are on the worked example.
Predict
Equal groups of 2,000, rates of 10% and 12.5%. How far apart are the pooled and unpooled standard errors?
With n users in each group, the pooled variance is never the smaller one. It's larger by exactly (p^A−p^B)2/2n: the gap squared, over twice the users per group. That's tiny when the rates are close. In the worked example the two standard errors are 0.009992 and 0.009984.
In the editor, write variance_gap(conv_a, conv_b, n): the pooled variance minus the unpooled one, to check that formula on rates near and far apart.
With unequal groups, the test and the interval can disagree
With unequal groups the two standard errors can split in either direction. Say the treatment is on a 10% ramp: control converts 1,000 of 10,000 users (10%), and treatment 120 of 1,000 (12%).
Standard error
Result
Pooled z-test
0.01003
z = 1.99, p = 0.046
Unpooled 95% interval
0.01071
-0.10 to 4.10 points, so 0 is inside
The 10% ramp, both results right at their line
0the gap
the pooled testthe null's 95% range: the gap is just outside, p = 0.046
the unpooled interval-0.10 to 4.10: 0 is just inside
-3-2-1012345
points
Predict
On the ramp, the pooled test says p = 0.046 and the unpooled interval takes in 0. Which one is miscomputed?
The test says significant, and the interval says zero is plausible. The small group has the larger variance, and only the unpooled standard error sees it. Say that in the interview, and don't let a launch turn on which side of 0.05 a borderline result lands.
Swapping the two standard errors is a different matter: that's a bug, and the practice tests catch it both ways.
In the editor, pooled_z and unpooled_se are ready. Write disagree(conv_a, n_a, conv_b, n_b): True when the test and the 95% interval reach different verdicts, as they do on the ramp.
The z score says how many standard errors the gap sits from 0. The p-value turns it into a share of the null curve: the area beyond your z, on both sides. two_sided_p is the function you write at the end of this step.
from statistics import NormalDistz = 2.501955print(round(two_sided_p(z), 6))
Predict
z = 2.502 on the worked example. What's the two-sided p-value?
Pick one to see what it prints.
That is the worked example's p-value. The p-value is the probability, if the null is true, of a z at least as far from 0 as yours, in either direction:
p=P(∣Z∣≥∣z∣)=2(1−Φ(∣z∣))
In words: Z is a draw from the standard normal curve and z is yours. Φ is the standard normal CDF, the chance of landing at or below a point, which is NormalDist().cdf. One minus it is the area above ∣z∣, and the 2 adds the matching area below −∣z∣.
On the curve, the two tails beyond 2.5 hold 0.62% each. Switch to one-sided to see one tail:
Two-sided against one-sidedInteractive
-3-2-10123z
Both tails beyond 2.50: 0.62% each, so p = 1.24%.
A two-sided p-value counts both tails. A one-sided p-value counts one tail, chosen before the data.
Two-sided, because a drop matters as much as a gain
The question is whether the versions differ, not whether B is better. You'd act on a treatment that hurts conversion too, by not shipping it and finding out why. So a big drop has to count as evidence against the null just like a big gain.
In the editor, write two_sided_p(z) and one_sided_p(z): both kinds of p-value, from a z.
CheckpointTwo tails, and one
Write two functions. two_sided_p(z) is the chance under the null of a z at least this far from 0, in either direction. one_sided_p(z) is for a test that decided before the data that only B doing better counts. At the worked example's z of 2.502 they're 0.0124 and 0.0062.
Pick an answer above to see the rest
Say what a p-value means, and what it doesn't
Computing a p-value is half the job. Interviewers also ask what one means, and the common answer is wrong.
Predict
p = 0.012 on the worked example. Which statement is right?
A stats question in the same OpenAI report asked how you'd explain a p-value (1 report). Answer with the numbers in front of you: if the two pages converted at the same rate, a gap of 2.5 points or more, in either direction, would show up in about 1.2% of experiments this size.
Then say what it isn't:
It's not the probability that the null is true.
It's not the probability that B is better.
Pick an answer above to see the rest
The interval's multiplier leaves alpha/2 in each tail
The p-value used cdf to turn a point into a share of the curve. The interval needs the reverse, a share in and a point out, and at alpha = 0.05 that point is 1.96. multiplier is the function you write at the end of this step.
for alpha in (0.10, 0.05, 0.01): m = multiplier(alpha) level = f"{1 - alpha:.0%}" print(f"alpha {alpha:.2f} {level} interval multiplier {m:.3f}")
Predict
What multiplier does a 99% interval use?
Pick one to see what it prints.
A 95% interval leaves 2.5% of the normal curve in each tail. So the multiplier is the point with 1−α/2 of the curve below it, 97.5% at α=0.05.
NormalDist().inv_cdf(q) gives that point. It's the quantile function, the inverse of cdf: you give it a share, and it gives the point with that share of the curve below it.
In the editor, write multiplier(alpha): the point that leaves alpha / 2 of the curve above it, for any alpha.
Now put the multiplier to work, at three levels of confidence.
Predict
You ask for 99% confidence instead of 95%. What happens to the interval?
On the worked example, the three multipliers give three intervals around the same gap:
Three intervals around the same gap
0
90%1.645 × SE: 0.86 to 4.14
95%1.960 × SE: 0.54 to 4.46
99%2.576 × SE: -0.07 to 5.07
-1012345
points
The 99% interval just takes in 0, and the p-value, 0.0124, is just above 0.01. They agree. At the same alpha, a test and an interval are two views of one decision: a two-sided test at 0.05 rejects exactly when the 95% interval built from the same standard error leaves out 0.
The practice function uses different standard errors for the two, which is how the ramp example could split.
In the editor, unpooled_se is ready. Write wald_ci(conv_a, n_a, conv_b, n_b, alpha=0.05): the interval at any alpha.
CheckpointThe interval at any alpha
Finish wald_ci(conv_a, n_a, conv_b, n_b, alpha=0.05). Return the 1 - alpha interval for B's rate minus A's, as (low, high). The editor already has unpooled_se, the interval's standard error.
Pick an answer above to see the rest
Part 3 done
Part 4 of 6about 8 min
The worked example
The whole function splits into two branches after the rates
Every piece so far fits in one function. After the rates, it splits into two branches, each with its own standard error.
Branch
The rate it uses
Then
the test
one pooled rate for everyone
the pooled SE, then z, then p_value
the interval
each group keeps its own rate
the unpooled SE, then ci
Both branches start from the two rates and diff, B's rate minus A's. This is levels 1 to 3 of the practice. Level 4 adds the split check from the first chapter as one more key, srm.
from math import sqrtfrom statistics import NormalDistdef two_proportion_test(conv_a, n_a, conv_b, n_b, alpha=0.05): pa, pb = conv_a / n_a, conv_b / n_b diff = pb - pa # the null's one rate pooled = (conv_a + conv_b) / (n_a + n_b) z = diff / sqrt(pooled * (1 - pooled) * (1 / n_a + 1 / n_b)) # both tails p_value = 2 * (1 - NormalDist().cdf(abs(z))) se = sqrt(pa * (1 - pa) / n_a + pb * (1 - pb) / n_b) half = NormalDist().inv_cdf(1 - alpha / 2) * se return {"diff": diff, "z": z, "p_value": p_value, "ci": (diff - half, diff + half)}for counts in [(200, 2000, 250, 2000), (250, 2000, 200, 2000), (100, 1000, 100, 1000)]: r = two_proportion_test(*counts) low, high = r["ci"] print(f"z {r['z']:+.4f} p {r['p_value']:.5f} " f"ci {low:+.5f} to {high:+.5f}")
Predict
The second run swaps the groups: 250 of 2,000 against 200 of 2,000. What happens to z and p?
Pick one to see what it prints.
The first line is the worked example. The second swaps the groups, 250 of 2,000 against 200 of 2,000: z flips its sign and the p-value stays put. The third is two identical groups. The practice tests check all three.
Pick an answer above to see the rest
Every number for 200 of 2,000 against 250 of 2,000
Control converts 200 of 2,000 users and treatment 250 of 2,000. These are the practice problem's known-result numbers, so your function should reproduce every row.
Step
Calculation
Value
Rates
200 / 2,000 and 250 / 2,000
0.100 and 0.125
Difference
0.125 - 0.100
0.025
Pooled rate
450 / 4,000
0.1125
Pooled SE
√(0.1125 × 0.8875 × 0.001)
0.009992
z
0.025 / 0.009992
2.5020
p-value
2 × (1 - Φ(2.5020))
0.01235
Unpooled SE
√(0.1 × 0.9 / 2,000 + 0.125 × 0.875 / 2,000)
0.009984
Multiplier
inv_cdf(0.975)
1.95996
Half-width
1.95996 × 0.009984
0.01957
95% interval
0.025 ± 0.01957
(0.00543, 0.04457)
The 0.001 in the pooled row is 1/2000+1/2000.
Read the result like this. Treatment converted 2.5 points better. If the pages were equally good, a gap that big in either direction would turn up about 1.2% of the time, so it's significant at 5%. The plausible range for the true lift runs from about 0.5 to 4.5 points.
In the editor, write pooled_rate and half_width, two rows of the table, and check them against its values.
The confidence level describes the method, not one interval
The worked example's 95% interval runs from 0.54 to 4.46 points. To see what its 95% promises, run the experiment again and again.
import randomrng = random.Random(5)true_gap = 0.125 - 0.10covered = 0for _ in range(10_000): conv_a = rng.binomialvariate(2000, 0.10) conv_b = rng.binomialvariate(2000, 0.125) low, high = two_proportion_test(conv_a, 2000, conv_b, 2000)["ci"] covered += low <= true_gap <= highprint(f"{covered / 10_000:.1%} of the intervals hold the true gap")
Predict
10,000 experiments, a 95% interval each. What share of them hold the true gap?
Pick one to see what it prints.
This runs the worked example 10,000 times with true rates of 10% and 12.5%, and builds a 95% interval each time. Here are the first 20:
The first 20 of 10,000 simulated 95% intervals
the true gap, 2.5
-202468
points
Each interval moves with its own data. Number 13, in red, misses the true gap.
The 95% is a property of the method: over many experiments, about 95 in 100 intervals hold the truth. At the worked example's sizes and true rates of 10% and 12.5%, the 95% Wald interval covered the true difference in 95.0% of a million simulated experiments.
Pick an answer above to see the rest
Predict
You've built one 95% interval. Is there a 95% chance the true gap is inside it?
Once you have one interval, it either holds the truth or it doesn't, and you can't see which. So call it a plausible range. Don't say there's a 95% chance the truth is inside this one.
In the editor, intervals holds the figure's 20 intervals, in points. Write coverage(intervals, truth): the share that hold the true gap.
A launch call starts with how big the lift is, and there are two ways to say it.
Predict
Conversion goes from 10% to 12.5%. What's the relative lift?
The same 25% relative lift on two bases
10% base, A
10.0%
10% base, B
12.5%
1% base, A
1.00%
1% base, B
1.25%
Both pairs are +25% relative: +2.5 points on the 10% base, +0.25 points on the 1% base.
Both pairs have a 25% relative lift. Only one of them moved much.
Absolute lift is the difference in rates, in percentage points: 12.5% minus 10.0% is 2.5 points.
Relative lift divides that by the control rate: 2.5 over 10 is 25%.
Say which one you mean, every time: conversion went from 10.0% to 12.5%, up 2.5 points, a 25% relative lift. Relative numbers sound bigger and hide the base. A 25% relative lift on a 1% conversion rate is a quarter of a point.
In the editor, write lifts(rate_a, rate_b): both numbers, for any pair of rates.
The relative lift needs an interval too, and the quick way to get one is wrong.
Predict
Can you get the relative lift's interval by dividing the points interval by the control rate?
The relative lift's interval, two ways
25%
divided by 0.105.4% to 44.6%: covered the truth 92.0% of the time
on the log scale4.9% to 49.0%: covered 95.1%
01020304050
%
A delta-method interval on the log of the ratio accounts for both rates. The delta method turns the noise in each rate into the noise of a function of them, here the log of their ratio:
With enough users, even a tiny lift comes out significant.
Predict
10 million users per group, 10.00% against 10.05%, p = 0.0002. Ship it?
Significant means the data rule out zero. It doesn't mean the lift is worth shipping.
With 10 million users per group, 10.00% against 10.05% gives z = 3.72 and p = 0.0002. That's a lift of 0.05 points, which might not pay for the code behind it.
In the editor, write z_for(rate_a, rate_b, n): the pooled z for two equal groups, to see the same lift at two sizes.
Read the interval against zero and against a practical bar
Since significance alone can't make the call, fix a practical bar before the test starts: the smallest lift worth what the change costs to build, ship and maintain. Then read the interval against both zero and the bar:
Predict
The interval runs 0.5 to 4.5 points, and your practical bar is 1 point. What's the call?
Read the interval against 0 and against the bar
0bar
launch, if the guardrails hold
real, maybe too small: depends on cost
too small: don't launch for this metric
can't tell: not a win
it hurts: don't launch, find out why
-2-101234
points
Read each row by where its interval sits. Entirely above the bar is real and big enough. Straddling zero means you can't tell, so it's not a win. If the top end of that one is worth having, run a bigger test.
The worked example's interval, 0.5 to 4.5 points, straddles a bar of 1 point: the second row. The best estimate clears the bar and the low end doesn't. If the change is cheap and nothing else got worse, ship it. If it's expensive, the lower bound is the number to plan around.
In the editor, write call(low, high, bar): the figure's five rows as one function.
A lift that looks too good deserves a hunt for the bug
One more check before any launch call: is the lift believable at all?
Predict
A change lifts conversion 25% on a mature product. What's your first move?
Sanity-check the size. A 25% relative lift on conversion would be enormous for a mature product. Kohavi and colleagues' advice for results like that: "When results seem too good to be true, apply Twyman’s law and investigate deeply before declaring an experiment as a breakthrough; most of the time, you’ll find a bug."
Watch · 8 min
A former Google data scientist runs the validity checks (sample ratio mismatch, novelty), reads a result's p-value and interval, then makes the launch call across five interval-against-threshold cases.
A/B Testing in Data Science Interviews by a Google Data Scientist | DataInterview · DataInterview · Feb 2022YouTube
Pick an answer above to see the rest
Part 5 done
Part 6 of 6about 22 min
Follow-ups
What interviewers ask next
The practice problem lists the follow-ups. Each one is a way a correctly computed test still gives a wrong answer.
Peeking: every extra look at a fixed test is another chance for a false positive
Looks over the test
False positive rate
1, at the end
5%
2
8%
5
14%
14, daily for two weeks
22%
100
37%
1,000
54%
That's how often a test with no real effect gets called significant when you stop at the first p below 0.05, with the looks spread evenly over the test, in simulation.
A fixed-sample test is built for one look. Netflix's experimentation team puts it plainly: "If you apply a fixed-n test more than once, then you forfeit the Type-I error or false positive guarantee" (1 source). Every extra look is another chance for noise to cross 1.96.
Microsoft's pitfall list says the same, and adds the mirror image: "In our experience, stopping early or extending the experiment are both very common mistakes experiment owners make." Running a flat test longer until it crosses 0.05 is the same error.
Three ways to look early and stay honest
You can look early, as long as you plan the looks before the test starts.
Predict
Under an O'Brien-Fleming plan for 14 daily looks, day 2 needs |z| above 5.57. Day 2's p = 0.04 is |z| = 2.05. Can you stop for a win?
The |z| each daily look needs before you may stop
O'Brien-Fleming Pocock, 2.61 day 2's z, 2.05
Each point is one daily look in a 14-day test, and the ∣z∣ that look needs before you may stop.
Look once, and monitor for harm. Fix the sample size in advance (the sample-size lesson shows how). Make the ship call only at the end, and watch the guardrails every day. Stopping early to protect users is fine. Stopping early to declare a win is the problem.
A group sequential design. Plan the looks and split alpha across them. Pocock uses one stricter bar at every look, ∣z∣>2.61 for 14 looks, which is p < 0.009 each time. O'Brien and Fleming's bar starts very strict and relaxes to 2.11 by day 14, so the final look loses little.
Always-valid inference. Johari and colleagues built p-values and intervals that stay valid however often you look. Ordinary ones are "wholly unreliable" when people pick the sample size by watching the results. The price is power: at any fixed sample size, they're less powerful than a test that looks once.
In the editor, write first_stop(zs, bound): the first daily look whose z passes the plan's bar.
Uber's experimentation team on why a daily check breaks the 5% guarantee, and how a boundary that starts strict and relaxes spends the 5% over the life of the test.
Uber Engineering: Sequential Testing Method in A/B Experimentation. · Uber Engineering · Dec 2016YouTube
Pick an answer above to see the rest
Many metrics and variants compound the false positive chance
Peeking gives one metric many chances. Tracking many metrics does the same thing another way.
Predict
You test 20 independent metrics on a change that does nothing. What's the chance at least one comes out significant at 0.05?
Chance that at least one metric comes out significant
1 metric
5.0%
3 metrics
14.3%
5 metrics
22.6%
10 metrics
40.1%
20 metrics
64.2%
The bars are 1−0.95m for m independent metrics on a change that does nothing.
Three treatments against one shared control do it 12.5% of the time in simulation. That's a bit under the 14.3% of three independent tests, because the shared control ties them together.
Segments work the same way. Slice by country, device and platform until something lights up, and something will.
Name one primary metric before the test, the one that decides. The rest are guardrails or diagnostics, read for harm and for understanding, not for a win.
When several metrics or variants could each justify a launch, correct for it. Bonferroni tests each of m comparisons at α/m: 20 metrics at 0.0025 each bring the chance of any false positive back to 4.9%. Benjamini-Hochberg is less strict. It controls the false discovery rate, the expected share of your wins that are flukes.
Treat a segment you found after the fact as a hypothesis for the next test, not a result.
In the editor, write family_rate(m, alpha) and bonferroni(alpha, m): the chance of a false win across m metrics, and the level that brings it back near alpha.
Novelty and primacy: users can react to the change itself
Even one metric, read once at the planned end, can mislead when the effect changes over the test.
Novelty and primacy, the shapes (not data)
novelty, big at first, then fades primacy, worse at first, then wins
Users can react to change itself. A new design can draw clicks because it's new and then fade as people get used to it. That's novelty. Or it can lose at first because people have to relearn it, and win later. That's primacy. Either way, a short test measures the wrong thing.
In one Microsoft experiment, a coach mark on Edge's new tab page lifted clicks on top sites by 2.07%. But splitting by visit showed "the treatment effect did not last beyond the first visit."
Predict
How can you tell whether a lift is novelty?
To check, plot the treatment effect by day of the test, and compare first-time users with returning ones. Users who never saw the old version have nothing to be surprised by. So if the lift holds for them, novelty isn't the story.
Kohavi and colleagues recommend "running experiments for two weeks and looking for such effects", which also covers two full weekly cycles. They add that "In practice, novelty and primacy effects are uncommon": they mostly see them in recommendation systems and in features that use up something finite.
In the editor, write novelty_suspect(daily_lift): a first check on the by-day plot, which flags a lift that fades.
The primary metric says whether the change worked. Guardrails say what it cost.
Page load, treatment minus control (an example)
0+50: the tolerance
small testreaches past the tolerance
big teststays under it
-40-20020406080
ms
Microsoft's experimentation team describes guardrails as metrics "which are not clearly indicative of success of the feature being tested, but which we do not want to significantly harm when making a ship decision."
Page load time, crash and error rates, unsubscribes, support contacts and revenue are typical. Small slips can be acceptable. In their words, "Large degradations, however, are generally not allowed."
Set each tolerance before the test. Page load may rise by up to 50 ms is a rule. It looks fine isn't.
Read the interval, not the p-value. No significant drop on an underpowered guardrail isn't evidence of no drop. Check that the interval's worst end stays inside the tolerance.
Predict
A guardrail shows no significant slowdown, but its interval reaches past your 50 ms tolerance. Is it safe?
In the figure, both intervals take in 0, so neither shows a significant slowdown. The big test's worst end stays under 50 ms. The small test's reaches past it, so it can't rule out a slowdown you said you wouldn't accept.
The SRM check is a guardrail too, on the experiment's trustworthiness rather than the product.
A win on the primary metric isn't the whole decision, even where testing is routine. OpenAI runs "an A/B test with a small number of our users" before it deploys a model update (1 source). After the 2025 sycophancy incident it said launches could be blocked "based on proxy measurements or qualitative signals" (1 source).
In the editor, write guardrail_ok(low, high, tolerance): the rule for a cost such as page load, read at the interval's worst end.
Revenue's heavy tail needs more users, a cap or equal groups
Every test so far counted conversions, a 0 or a 1 for each user. Revenue per user is different: most users spend nothing and a few spend a lot.
20 users' revenue in one week (an example)
14 users
The other 6
Mean
raw
$0 each
$4, 6, 9, 12, 25, 480
$26.80
capped at $10
$0 each
$4, 6, 9, 10, 10, 10
$2.45
One user holds 90% of all the revenue.
So the test changes shape. Compare means, with each group's own sample variance s2. That's Welch's test:
SE=nAsA2+nBsB2
In words: each group's sample variance over its users, added, under one square root. There's no pooled-rate step, because a mean doesn't fix the variance the way p(1−p) does.
The tail is the real problem. A few big spenders dominate the variance, so the test is noisy, and the average needs far more users before it's close to normal.
Predict
Revenue per user has a skewness of 18. A rule of thumb asks for at least 355 × skewness² users per variant. About how many is that?
Kohavi and colleagues' rule of thumb is at least 355s2 users per variant, where s is the metric's skewness. Skewness measures how lopsided a distribution is: 0 for a symmetric one, and large and positive when a long tail of big values stretches it to the right. This s is that number, not the standard deviation in Welch's formula above. At Bing, revenue per user had a skewness of about 18, which puts the floor near 115,000 users per variant.
Cap it. Replace values above a threshold with the threshold, as in the table. Capping revenue at $10 per user per week cut the skewness from about 18 to about 5, and the capped metric could detect a change 30% smaller with the same users. Pick the cap before the test, and count how many values it touches.
Split 50/50. With equal groups, the difference in means is symmetric under the null even when each mean is skewed. Their advice: "ensure that the control and treatment are equally sized." In a simulation of a revenue-like metric, the difference had a skewness of 0.02 with a 500/500 split and -3.5 with 100/900.
Bootstrap the interval when the sample is small, resampling users within each group.
Reduce the variance with pre-experiment data. That's CUPED, which the CUPED lesson covers.
Keep the question. A log transform or a Mann-Whitney test can be more sensitive. But they answer a different question than whether revenue per user went up, and revenue is usually a question about the mean.
In the editor, revenue holds the table's 20 users. Write capped_mean(values, cap) and users_needed(skew): what the cap does to the mean, and the rule of thumb.
That's every piece of the practice problem, and every follow-up it lists. The simulation asks for the whole function under a timer, so rehearse the order once.
Check yourself
5 questions
1.Your function returns p = 0.0062 for 200/2,000 against 250/2,000, and the practice test expects 0.0124. Two identical groups give p = 0.5. What's wrong?
2.At alpha = 0.05 your interval for the worked example is (0.0086, 0.0414). The reference gives (0.0054, 0.0446). How often does yours cover the true difference?
3.Why does the z statistic use the pooled rate while the interval uses each group's own rate?
4.Your z uses the unpooled standard error, so it's 2.5039 on the worked example instead of 2.5020. When does that bug actually hurt?
5.A PM checks a 14-day test every day and stops it the first time p < 0.05. If the treatment does nothing, about how often does the test end on a significant result?
Where this shows up
The reports behind this lesson, each with its source.
Same L5 DS report, take-home prompt: define success metrics and decide whether a launch succeeded.
DS technical screen (posted 2025-10-13): design an experiment and recommend whether to launch.
Prep site·PracHub (prep site question bank)·2025-10-13Source
DS technical screen (posted 2026-02-21): design and then analyze an experiment for a luggage locker feature.
Prep site·PracHub (prep site question bank)·2026-02-21Source
Data scientist candidate (interviewed Aug 2026): the hiring manager screen dwelt on the candidate's experiments.
Candidate report·PracHub (first-person report, curated and edited by the site)·2026-08-25Source
Sequential testing (Feb 2024): looking at a fixed-n test more than once loses its false positive guarantee.
“If you apply a fixed-n test more than once, then you forfeit the Type-I error or false positive guarantee.”
Company source·Netflix Tech Blog, post 'Sequential A/B Testing Keeps the World Streaming Netflix Part 1: Continuous Data' (full text read from the blog's Medium RSS feed; the post page itself returns 403)·2024-02-13Source
Before deploying a model update, OpenAI runs an A/B test with a small number of users.
“In addition to OEC metrics, we have found that there is a set of metrics which are not clearly indicative of success of the feature being tested, but which we do not want to significantly harm when making a ship decision.”
“When a metric has a large skewness, it is sometimes possible to transform the metric or cap the values to reduce the skewness so that the average converges to normality faster.”
“A/B tests are typically analyzed via frequentist p-values and confidence intervals; but these inferences are wholly unreliable if users endogenously choose samples sizes by *continuously monitoring* their tests.”