Module 9 · A/B Testing: Proving What Works · Lesson 30 of 51
Analysing the results
Check the data, compute conversion rates, run a two-proportion z-test, build a confidence interval for the lift, analyse revenue per user, and use the simulator to build intuition.
In this lesson · about 45 minutes
- Run a two-proportion z-test by hand and check it with SciPy
- Report the lift with a confidence interval
- Analyse a continuous metric such as revenue per user
Try it · data lab
A/B test simulator
Run a two-week experiment on simulated visitors. See the p-value, the confidence interval, the peeking trap and how often tests with no real effect still 'win'.
The app team tests a new checkout button. Half of visitors see the old one (A), half the new one (B), for 14 days. You set the true effect (which in real life nobody knows), then see what the experiment would report.
A: converted
427/4223
B: converted
507/4177
Observed lift
20%
p-value
0.003
95% confidence interval for B − A: 0.68 to 3.37 percentage points.
The two-proportion z-test
- Rates: p̂_A = conversions_A ÷ n_A, p̂_B likewise.
- Pooled rate (assuming H₀, no difference): p̂ = (conv_A + conv_B) ÷ (n_A + n_B).
- Standard error: SE = √(p̂(1 − p̂)(1/n_A + 1/n_B)).
- z = (p̂_B − p̂_A) ÷ SE; two-sided p-value = 2 × (1 − Φ(|z|)), i.e.
2 * stats.norm.sf(abs(z)).
Confidence interval for the difference uses the unpooled SE: √(p̂_A(1 − p̂_A)/n_A + p̂_B(1 − p̂_B)/n_B), then difference ± 1.96 × SE. Report the relative lift too: (p̂_B − p̂_A) ÷ p̂_A.
Continuous metrics
For revenue per user, use Welch's t-test on the per-user values (zeros included for non-buyers). Revenue is very skewed, so check the result with a bootstrap or Mann–Whitney test, and look for a few huge orders driving the difference.
The checkout button test
Exercise
The z-test, as a function
Write ab_test(cA, nA, cB, nB) that returns a tuple (lift, z, p): the absolute difference p̂_B − p̂_A, the pooled z-statistic, and the two-sided p-value, each rounded to 4 decimals. Then run it on the iOS users only and store the result in ios.
Code that runs before yours
import pandas as pd
import numpy as np
from scipy import stats
ab = pd.read_csv("kc_ab_test.csv")
ios_users = ab[ab["device"] == "iOS"]
g = ios_users.groupby("group")["converted"].agg(["sum", "count"])Exercise
Report the lift with a confidence interval
For the full test, set diff to p̂_B − p̂_A, ci to the 95% interval (low, high) using the unpooled standard error, and rel_lift to diff ÷ p̂_A. Round everything to 4 decimals.
Code that runs before yours
import pandas as pd
import numpy as np
from scipy import stats
ab = pd.read_csv("kc_ab_test.csv")
rates = ab.groupby("group")["converted"].mean()
sizes = ab.groupby("group")["converted"].count()
pA, pB, nA, nB = rates["A"], rates["B"], sizes["A"], sizes["B"]Check your understanding0 of 3 correct
Quiz score: 0 of 3
Exercises solved: 0 of 2
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.