Workflow recipe
Read an A/B test result with AI without fooling yourself
Analyse A/B test results with AI safely: set the rule first, check for sample ratio mismatch, compute the interval in code, then write a decision note.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
To analyse A/B test results with AI and trust the answer, write down the decision rule before you look, export raw counts per variant, and check the split for a sample ratio mismatch first. Then have the numbers computed in code, not estimated by the model: the conversion rates, the difference and its 95% interval. Ask the assistant to look for the usual traps, apply your rule, and write a short decision note that someone else can check.
Language models are good at explaining statistics and bad at doing arithmetic in their heads. Paste “control 5.0%, variant 5.5%, 20,000 users each, is it significant?” into a chat and you may get a confident p-value that was never calculated. A second, quieter problem is that the assistant answers the question you asked. If you ask “did the new checkout win?”, it looks for reasons it did. This recipe keeps the AI where it helps (writing and running the code, listing traps, drafting the note) and keeps the numbers and the decision rule out of its hands.
Your notesAbout 10 min
1. Write the decision rule before you look
If the test had a written plan, copy it. If not, write it now, before you open the results, and be honest that it is late. Four lines:
- Primary metric: one metric that decides, for example “checkout conversion: users who completed an order divided by users who reached the basket”.
- Smallest change worth shipping: the effect too small to matter even if it is real, for example “less than 0.3 percentage points is not worth the extra code”.
- Guardrails: metrics that must not get worse, such as refund rate or page load time.
- Rule: “Ship if the lower end of the 95% interval for the difference is above the smallest change worth shipping and the guardrails hold. Stop if the upper end is below it. Otherwise the test is inconclusive: extend it if more traffic could settle it, or stop.”
Writing the rule first is the single best protection against reading the result you hoped for.
Your analytics or experiment toolAbout 10 min
2. Export counts, not percentages
Export one row per variant with the number of users assigned and the number who converted. Rates on a dashboard hide the denominator, and the checks below need it. Save it as a CSV with the control first:
variant,users,conversions
control,20112,1006
new_checkout,19947,1101Export the same counts per day as a second file if your tool allows it. You will use them in step 5 to look for early-days effects. Use the analysis unit the test was randomised on: if users were split, count users, not sessions or page views.
Terminal, or an assistant that runs codeAbout 10 min
3. Check for a sample ratio mismatch first
A sample ratio mismatch (SRM) is when the split you got differs from the split you configured by more than chance allows: you asked for 50/50 and got 51/49 on 40,000 users. It means something removed or added users unevenly, such as a redirect that drops some browsers, a bot filter, or a bug that assigns returning users twice. Microsoft’s experimentation researchers published a taxonomy of SRM causes because the problem is common and can make a bad change look good. When there is an SRM, every metric from the test is suspect. Check it before you read anything else.
Save this as ab_check.py next to your CSV. It runs the SRM check (a chi-square goodness-of-fit test) and only then computes the result:
"""Check an A/B test result: sample ratio, conversion rates and a 95% interval.
Usage: python3 ab_check.py results.csv
The CSV has one row per variant: variant,users,conversions
The first row is the control. Standard library only.
"""
import csv
import math
import sys
from statistics import NormalDist
EXPECTED_SPLIT = [0.5, 0.5] # the split you configured, in row order
SRM_THRESHOLD = 0.001 # strict on purpose: this check runs on every test
def main(path):
with open(path, newline="") as f:
rows = [(r["variant"], int(r["users"]), int(r["conversions"])) for r in csv.DictReader(f)]
if len(rows) != 2:
raise SystemExit("Expected exactly two rows: control first, then the variant.")
# 1. Sample ratio mismatch: chi-square goodness of fit, one degree of freedom
users = [r[1] for r in rows]
total = sum(users)
expected = [total * s for s in EXPECTED_SPLIT]
stat = sum((o - e) ** 2 / e for o, e in zip(users, expected))
p_srm = math.erfc(math.sqrt(stat / 2))
print(f"Sample ratio: {users[0]:,} vs {users[1]:,} (expected {EXPECTED_SPLIT})")
print(f" chi-square = {stat:.2f}, p = {p_srm:.2g}")
if p_srm < SRM_THRESHOLD:
print(" SAMPLE RATIO MISMATCH: stop. Find the cause before reading any metric.")
return
# 2. Difference in conversion rate with a 95% interval
(name_a, n_a, x_a), (name_b, n_b, x_b) = rows
p_a, p_b = x_a / n_a, x_b / n_b
diff = p_b - p_a
se = math.sqrt(p_a * (1 - p_a) / n_a + p_b * (1 - p_b) / n_b)
z = NormalDist().inv_cdf(0.975)
lo, hi = diff - z * se, diff + z * se
# 3. Two-sided p-value from a pooled two-proportion z-test
pooled = (x_a + x_b) / (n_a + n_b)
se0 = math.sqrt(pooled * (1 - pooled) * (1 / n_a + 1 / n_b))
p_value = 2 * (1 - NormalDist().cdf(abs(diff / se0)))
print(f"{name_a}: {x_a:,}/{n_a:,} = {p_a:.3%}")
print(f"{name_b}: {x_b:,}/{n_b:,} = {p_b:.3%}")
print(f"Difference: {diff * 100:+.2f} points, 95% CI [{lo * 100:+.2f}, {hi * 100:+.2f}]")
print(f"Relative change: {diff / p_a:+.1%}")
print(f"Two-sided p-value: {p_value:.3g}")
if __name__ == "__main__":
main(sys.argv[1])python3 ab_check.py results.csvWith a split of 20,112 against 19,210 users, the script stops at the first check:
Sample ratio: 20,112 vs 19,210 (expected [0.5, 0.5])
chi-square = 20.69, p = 5.4e-06
SAMPLE RATIO MISMATCH: stop. Find the cause before reading any metric.The threshold is strict because you run this check on every test, and a loose one would raise false alarms. If your test used an uneven split, such as 90/10, set EXPECTED_SPLIT to match.
Terminal, or an assistant that runs codeAbout 10 min
4. Compute the difference and its interval in code
With no mismatch, the same script prints the result. For the example counts:
Sample ratio: 20,112 vs 19,947 (expected [0.5, 0.5])
chi-square = 0.68, p = 0.41
control: 1,006/20,112 = 5.002%
new_checkout: 1,101/19,947 = 5.520%
Difference: +0.52 points, 95% CI [+0.08, +0.95]
Relative change: +10.3%
Two-sided p-value: 0.0203Read the interval, not the p-value. The variant converted 0.52 points better, and the data are consistent with a true difference anywhere from 0.08 to 0.95 points. The lower end is below the 0.3-point threshold from step 1, so the test cannot rule out an effect too small to matter.
If you cannot run Python, use an assistant that executes code, and make it show its work:
Check that its numbers match the script’s on the example CSV before you trust it with yours.
Claude or ChatGPTAbout 15 min
5. Ask for the traps, not for a verdict
An honest interval can still mislead you if the test was run or read badly. Ask the assistant to play the sceptic. If you use an agent, the statistical-analysis skill gives it the background on practical significance, multiple comparisons and Simpson’s paradox.
In our run, with the test described as stopped on day 10 of 14 after the dashboard showed significance, the review answered yes to peeking, yes to multiple comparisons and “cannot tell” to novelty and guardrails, because we gave it no daily data or guardrail numbers. It treated the missing guardrail figures as a missing input rather than a pass, which is what you want.
Answer its question with data, not argument. If it flags novelty, compare the difference in the first week with the last week from your daily file, using the same script on each week’s totals.
Your notesAbout 10 min
6. Apply the rule you wrote in step 1
Go back to your four lines and apply them to the computed interval. Do not rewrite the rule now. For the example:
- The interval [+0.08, +0.95] is entirely above zero, so the change is unlikely to be harmful.
- Its lower end, 0.08, is below the 0.3-point threshold, so a worthwhile effect is not established.
- Its upper end, 0.95, is above the threshold, so a worthwhile effect is not ruled out either.
- Under the example rule, that is “inconclusive”, not “ship”. Whether to extend depends on how much more traffic you can get.
That answer annoys people, and it is the one the data support. If the team wants to ship anyway for other reasons (simpler code, a design refresh), that is a legitimate business decision; write it down as one, not as a test win.
Claude or ChatGPT, then your docAbout 15 min
7. Write the decision note
The note is what people read in six months when they ask why the checkout looks the way it does.
Check every number in the note against the script output, attach the CSV and the script, and file it where the team keeps experiment results.
Check it worked
Verification checklist
0 of 6 done
When it goes wrong
If the sample ratio check fails, do not adjust the numbers or drop the extra users. Look for the cause: compare the split by browser, device, country and day, and check whether a redirect, a bot filter or a late-loading script runs in only one variant. In our second test file, the variant had about 900 fewer users than the control, which the script flagged at p = 5.4e-06; a gap like that usually means the variant loses some users before they are counted.
If a chat assistant gives you numbers without showing code, or its numbers differ from the script’s, do not average them or ask it to try again. Use the script’s numbers. Assistants that cannot run code produce plausible statistics, and the prompt in step 4 is designed to make that visible.
If the relative change looks large and the interval is wide, as with “+10.3%” on a base rate of 5%, report the absolute difference and the interval first. Relative lifts on small base rates sound bigger than they are, and they are what people remember from a meeting.
If someone asks for “just the segments where it won”, say no, or treat those segments as a new hypothesis for a new test. Slicing a finished test until something looks good is the multiple-comparisons trap in step 5.
Variations
For revenue per user or another continuous metric, the interval needs the per-user values, not counts; export them and ask the assistant to compute a bootstrap interval in code. For more than two variants, run the SRM check with all of them and correct for the extra comparisons, or compare each variant only with the control.
If your experiment platform already reports SRM and intervals, use the platform’s numbers and keep steps 1, 5, 6 and 7: the rule, the traps, the decision and the note are where most mistakes happen. To build the dashboard that feeds this, see SQL questions to a dashboard; to tidy a messy export first, clean a messy spreadsheet.
Related data analysis guides
The AI for data analysts path covers the other checks an analyst should run on AI output. Why AI hallucinates explains why a model’s arithmetic needs code behind it.
Outcome and tools
- Outcome
- A one-page decision note for an A/B test with a sample ratio check, the difference and its 95% interval computed in code, the traps you ruled out, and a ship, stop or extend call.
- For
- Data analysts, Product managers
Related
- From business question to SQL dashboard with AI
The assistant writes the SQL, you define the metrics and check every number before anyone acts.
- Clean and analyse a messy spreadsheet with AI
Clean a messy spreadsheet with ChatGPT or Claude without losing rows: profile it, agree the rules, keep a cleaning log and reconcile totals before any chart.
- Why AI hallucinates, and how to reduce it
AI hallucinations are fluent answers that are false. Why language models produce them, which ones you can prevent, and a checklist for work you depend on.
- AI for data analysts
An AI course for data analysts: clean spreadsheets, profile data with skills, go from SQL to a dashboard, extract PDF tables and catch invented numbers.