Sub topic 6
Estimating sample size and duration
This chapter assumes you know what a baseline conversion rate is. It also assumes you can read a short Python function. You should have already chosen a primary metric and a randomization unit. Those two choices feed straight into the calculation here.
Why estimate before launch
An experiment that is too small cannot tell you anything. If the real effect is one percentage point and you only have a few thousand users, the result will usually be "no significant difference". That does not mean there is no effect. It means you could not see it.
Estimating sample size before launch gives you three things:
- A run time you can put in the roadmap, so stakeholders know when to expect an answer.
- A check that the test is feasible at all. Sometimes the traffic needed would take a year, and you should pick a different approach.
- A stopping point agreed in advance, which protects you from ending the test the first day the chart looks good.
The four inputs
Every standard sample size calculation for a conversion metric uses the same four inputs.
| Input | Meaning | Typical value |
|---|---|---|
| Baseline | Current value of the primary metric in the eligible population | Measured from recent data |
| Minimum detectable effect (MDE) | Smallest change worth detecting | Set by product judgment |
| Significance level (alpha) | Chance of a false positive when there is no real effect | 0.05, two-sided |
| Power | Chance of detecting an effect of at least the MDE if it exists | 0.8 or 0.9 |
The baseline comes from data, so ask your data partner for it from the same eligible population and a recent period. A baseline taken from all users will mislead you if the experiment only includes logged-in users with a saved address.
The MDE is a product decision. It is not a prediction of what the feature will do. Ask: what is the smallest lift that would justify the engineering cost and the maintenance of the new code path? If a 0.2 point lift would not change your decision, there is no reason to pay for a test that can detect it.
Absolute and relative MDE
State the MDE in one form and say which. An absolute MDE of 1 point on a 10% baseline means moving from 10% to 11%. A relative MDE of 10% means the same thing here, but on a 40% baseline a relative 10% is 4 points. The checkout brief uses the absolute form, minimum_detectable_effect_abs: 0.01. Mixing the two forms is a common source of plans that are off by a factor of several.
The calculation
For a metric that is a proportion, such as checkout completion, the normal approximation gives the users needed in each variant:
import math
from statistics import NormalDist
def sample_size_per_variant(baseline, mde_abs, alpha=0.05, power=0.8):
"""Approximate users per variant for a two-sided test of two proportions."""
p1 = baseline
p2 = baseline + mde_abs
z = NormalDist().inv_cdf
z_alpha = z(1 - alpha / 2)
z_beta = z(power)
variance = p1 * (1 - p1) + p2 * (1 - p2)
return math.ceil((z_alpha + z_beta) ** 2 * variance / (p2 - p1) ** 2)
# Baseline 10% conversion, detect an absolute lift of 1 percentage point.
print(sample_size_per_variant(0.10, 0.01))For a 10% baseline and a one point lift this gives roughly 14,750 users per variant. That is the number written into the brief as planned_sample_per_variant: 14750. With a 50/50 split, the experiment needs about 29,500 users in total.
You do not need to memorize the formula. You need to know how the answer moves when you change an input.
How the inputs move the answer
The MDE sits in the denominator, squared. Halving the MDE roughly quadruples the sample. This is the most important relationship in the chapter.
| MDE (absolute) | Variant rate | Users per variant (approx.) |
|---|---|---|
| 2.0 points | 10% to 12% | 3,840 |
| 1.0 point | 10% to 11% | 14,750 |
| 0.5 points | 10% to 10.5% | 57,760 |
Power and alpha matter less but are not free. Raising power from 0.8 to 0.9 increases the sample by about a third, to roughly 19,700 per variant in the same example. Lowering alpha from 0.05 to 0.01 raises it too.
The baseline matters in a way people miss. Variance is largest near 50% and shrinks toward 0% and 100%. For a given absolute MDE, a rare event such as a 1% conversion needs fewer users than a 10% one. For a given relative MDE, it needs far more.
From sample size to duration
Duration depends on how many eligible users arrive each day, not on total site traffic. Count only people who meet the eligibility rule and who reach the point where they are assigned.
import math
def days_needed(n_per_variant, variants, daily_eligible, traffic_share=1.0, min_days=14):
"""Calendar days to reach the planned sample, rounded up to full weeks."""
total = n_per_variant * variants
daily = daily_eligible * traffic_share
raw_days = math.ceil(total / daily)
full_weeks = math.ceil(raw_days / 7) * 7
return max(full_weeks, min_days)
# 14,750 per variant, 2 variants, 2,500 eligible users a day, all traffic in the test.
print(days_needed(14750, 2, 2500))The raw answer is 12 days (29,500 divided by 2,500, rounded up). The function rounds up to 14 days, which is two full weeks. Here is why the rounding matters:
- Behavior differs by day of week. A test that runs Monday to Thursday over-represents weekday shoppers.
- Full weeks make each weekday appear equally often in both variants.
- Many teams also set a minimum run time, such as two weeks, so a short-lived novelty effect is less likely to drive the result.
If only part of the traffic enters the test, for example a 20% ramp, set traffic_share accordingly. The sample takes five times longer to collect.
Choosing a split
A 50/50 split gives the fastest route to a given power. An uneven split, such as 90/10, needs a larger total sample and takes longer. Use an uneven split when risk calls for it, such as a change that could hurt payments. Accept the longer run time as the price of lower exposure.
More than two variants cost more. Each extra arm needs its own sample, and comparing several arms to control raises the false positive rate unless you adjust alpha. The simplest adjustment is to divide alpha by the number of comparisons. Decide this before you launch.
Metrics that are not proportions
For a metric such as revenue per user, the variance comes from the data, not from a formula based on the rate. The approximate sample per variant is:
n = 2 × (zalpha + zbeta)² × σ² / δ²
Here σ is the standard deviation of the metric and δ is the MDE in the same units. Revenue is usually skewed by a few very large buyers, so σ is large and the sample needed is often much bigger than for conversion. Ask the data team for σ from a recent period. They may also propose variance reduction, such as adjusting for each user's pre-experiment behavior, which can shorten the test.
Randomization unit and sample size
The sample size above counts independent units. If you randomize by user but measure by session, sessions from the same user are correlated. Treating them as independent makes the test look more precise than it is. If you randomize by group, such as a store or a team account, the effective sample is closer to the number of groups than the number of users. Agree with data on the unit before calculating, as covered in the earlier chapter on randomization.
Common planning errors
- Using total traffic instead of eligible traffic. This makes the test look faster than it will be.
- Choosing the MDE to fit the calendar. Setting a large MDE so the test ends in a week means you only detect big effects. Report this trade-off openly.
- Ignoring guardrails. A guardrail such as payment error rate may need its own sample size. A rare error rate can take far longer to estimate than the primary metric.
- Recomputing power from the observed effect after the test. This adds no information. It restates the p-value in different words.
- Stopping early on a good-looking result. Repeated looks at the data inflate false positives. The plan you write now defines the stopping point.
What goes into the brief
Write these items in the brief, next to the hypothesis and the metrics:
- The baseline, its source, and the period it covers.
- The MDE, stated as absolute or relative.
- Alpha, power, and whether the test is two-sided.
- The planned sample per variant and the total.
- The expected daily eligible traffic and the resulting run time, rounded to full weeks.
- The earliest and latest dates at which you will read results.
Exercise
A checkout test has a 10% baseline and needs 14,750 users per variant to detect a 1 point lift. Product asks to detect a 0.5 point lift instead. Roughly how many users per variant are needed? If 2,500 eligible users arrive each day and the split is 50/50, about how many days of data are needed before rounding to full weeks?
Show answer
Halving the MDE roughly quadruples the sample, so about 57,760 users per variant, or 115,520 in total. At 2,500 users a day that is about 46.2 days, so 47 days of data. Rounded up to full weeks, the test would run 49 days (seven weeks). Product should decide whether a 0.5 point lift is worth that wait.