Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

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.

By Checked Intermediate1 h 20 min7 steps
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On 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,1101

Export 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.csv

With 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.0203

Read 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:

Compute, do not estimate · ChatGPT with data analysis, or Claude with code execution
Here are the results of an A/B test as a CSV. The control is the first row. The configured split was [SPLIT, E.G. 50/50]. [PASTE THE CSV] Write and run Python code that: 1. Runs a chi-square goodness-of-fit test on the user counts against the configured split, and stops if p < 0.001. 2. Otherwise computes each variant's conversion rate, the difference in percentage points, a 95% confidence interval for the difference (normal approximation, unpooled standard error) and a two-sided p-value (pooled two-proportion z-test). Rules: - Every number in your answer must come from the code output. Do not calculate anything in your head or round before the end. - Show the code and its full output before any explanation. - Do not say whether the test "won". I will decide that.

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.

Sceptical review of an A/B test · Claude or ChatGPT
Act as a sceptical reviewer of this A/B test. Your job is to find reasons the result could be wrong, not to confirm it. Plan: [PASTE THE DECISION RULE FROM STEP 1] Result (computed in code): [PASTE THE SCRIPT OUTPUT] Daily counts: [PASTE THE DAILY CSV, OR "NOT AVAILABLE"] How the test was run: [DURATION, WHETHER IT WAS STOPPED EARLY, HOW MANY METRICS AND SEGMENTS WERE LOOKED AT] Check for, and say yes, no or cannot tell for each: 1. The test was stopped early because it looked good (peeking). 2. Many metrics or segments were compared, so one "winner" is likely by chance. 3. The effect is concentrated in the first days (novelty) or changes direction over time. 4. The test did not cover at least one full weekly cycle. 5. A guardrail metric got worse. 6. The interval includes effects too small to be worth shipping. Rules: do not compute new statistics; if you need a number that is not given, say what I should calculate. End with the one question I most need to answer before deciding.

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.

Decision note · Claude or ChatGPT
Write a decision note for this A/B test, at most 300 words. Use only these inputs: - Decision rule (written [BEFORE / AFTER] the test): [RULE] - Script output: [OUTPUT] - Sceptical review and my answers: [NOTES] - Decision: [SHIP / STOP / EXTEND] and the reason Structure: what was tested and when; the result as "difference X points, 95% CI [A, B]"; the sample ratio check; traps checked and how; the decision and whether it follows the rule; what we would need to see to change it. Rules: copy numbers exactly from the inputs. Do not describe the result as "significant" without the interval next to it. Plain words, no hype.

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.

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
  • From business question to SQL dashboard with AI

    The assistant writes the SQL, you define the metrics and check every number before anyone acts.

    WorkflowIntermediate3 h7 steps

  • 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.

    WorkflowBeginner45 min7 steps

  • 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.

    Article

  • 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.

    Learning pathBeginner9 h10 steps

Back to top