Module 9 · A/B Testing: Proving What Works · Lesson 29 of 51
Designing an experiment
Why randomised experiments prove cause, the parts of a test plan (hypothesis, primary and guardrail metrics, unit, split, duration), and how to size a test before it starts.
In this lesson · about 40 minutes
- Explain why random assignment makes cause and effect clear
- Write a test plan with a hypothesis, a primary metric and guardrails
- Calculate the sample size and duration a test needs
The test plan (write it before you start)
| Part | Café app example |
|---|---|
| Hypothesis | A bigger "Pay now" button will raise checkout conversion, because users miss the current one. |
| Primary metric | Conversion: share of app visitors who complete an order. |
| Guardrail metrics | Average order value, refund rate, app crash rate: must not get worse. |
| Unit of randomisation | The user (not the page view), so one person always sees the same version. |
| Split | 50/50. |
| Minimum detectable effect | The smallest lift worth acting on, e.g. a relative +10% (10.0% → 11.0%). |
| Sample size and duration | From a power calculation; run at least 1–2 full weeks to cover weekday and weekend behaviour. |
| Decision rule | Ship B if conversion is significantly higher at α = 0.05 and no guardrail is significantly worse. |
Writing the plan first stops you moving the goalposts after seeing the data.
Sample size
Four things decide it: the baseline rate, the MDE, the significance level α and the power (1 − β). Small effects on rare events need big samples. Halving the MDE needs roughly four times the users. If the traffic can't support the test in a sensible time, test a bolder change, pick a more frequent metric, or don't test.
Try it · data lab
How many visitors do you need?
Plan an A/B test before running it: set the baseline, the smallest lift worth finding, the significance level and the power.
Per group
14,751
Total
29,502
Days needed
30
Detects
10% → 11%
Show the working
- p₁ = 0.1, p₂ = 0.11
- z for α/2 = 1.96, z for power = 0.842
- n = (z_α/2·√(2p̄(1−p̄)) + z_β·√(p₁(1−p₁) + p₂(1−p₂)))² ÷ (p₂ − p₁)²
Exercise
Size the checkout test
Write n_per_group(p1, p2, alpha=0.05, power=0.8) using the formula below, rounding up with math.ceil. Then set n for a baseline of 10% and a target of 11.5%.
n = (zα/2 × √(2 p̄ (1 − p̄)) + zβ × √(p₁(1 − p₁) + p₂(1 − p₂)))² ÷ (p₂ − p₁)², with p̄ = (p₁ + p₂) ÷ 2, zα/2 = norm.ppf(1 - alpha / 2) and zβ = norm.ppf(power).
Sorting drill
Primary metric or guardrail?
The test: a 'Suggested add-on' prompt at checkout, hoping to raise revenue per visitor.
- Revenue per visitor
- Checkout completion rate
- App crash rate
- Number of times the prompt was shown
- Refunds and complaints
- Total company revenue this quarter
0 of 6 sorted
Check your understanding0 of 3 correct
Quiz score: 0 of 3
Exercises solved: 0 of 1
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.