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)

PartCafé app example
HypothesisA bigger "Pay now" button will raise checkout conversion, because users miss the current one.
Primary metricConversion: share of app visitors who complete an order.
Guardrail metricsAverage order value, refund rate, app crash rate: must not get worse.
Unit of randomisationThe user (not the page view), so one person always sees the same version.
Split50/50.
Minimum detectable effectThe smallest lift worth acting on, e.g. a relative +10% (10.0% → 11.0%).
Sample size and durationFrom a power calculation; run at least 1–2 full weeks to cover weekday and weekend behaviour.
Decision ruleShip 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%

09799219598429397639196921221314014,751 per groupMinimum detectable lift (%)Visitors per group
Show the working
  1. p₁ = 0.1, p₂ = 0.11
  2. z for α/2 = 1.96, z for power = 0.842
  3. n = (z_α/2·√(2p̄(1−p̄)) + z_β·√(p₁(1−p₁) + p₂(1−p₂)))² ÷ (p₂ − p₁)²
Halving the lift you want to detect needs about four times the visitors. Small effects on low conversion rates need big samples, which is why tests should run at least one or two full weeks.

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

Question 1

1.Why randomise users instead of comparing this month with last month?

Question 2

2.Why randomise by user, not by page view?

Question 3

3.Why run a test for at least one full week?

Quiz score: 0 of 3

Exercises solved: 0 of 1

Tip: answer every quiz question correctly first.

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.