Rana Maninder Singh
Lesson 5 of 7A/B Testing

Analyzing Results

Lesson opener

In one line: Chi-square / z-test for conversion rates.

Why it matters: A single end-of-test p-value matches the alpha you planned.

Before this lesson: Running the experiment / Inferential stats

Before you start


What you will learn

  • Chi-square / z-test for conversion rates
  • Reporting lift with a confidence interval
  • Separating statistical significance from business significance
  • Building a small readout dict PMs in Bengaluru can paste into a ticket

Pinned libraries for this course

pip install -r docs/abtest/requirements.txt

Pinned in docs/abtest/requirements.txt:

numpy==2.1.3
scipy==1.14.1
pandas==2.2.3
statsmodels==0.14.4

This lesson uses statsmodels.stats.proportion helpers offline. Confirm SRM and the frozen window from Running the experiment before you trust any p-value here. Pin versions so proportions_ztest and confint_proportions_2indep match what reviewers expect.


Conversion table to p-value

After exposures are clean, summarise successes and totals per arm. A two-proportion z-test (or chi-square on the 2×2 table) answers whether observed rates are compatible with H0 for the pre-registered design.

WHY A single end-of-test p-value matches the alpha you planned.

WHEN Only after n is reached (or the pre-registered end date) — not every afternoon.

Demo 1 — Two-proportion z-test

# Offline demo: two-sided proportions z-test
from statsmodels.stats.proportion import proportions_ztest


def two_proportion_pvalue(successes: list[int], totals: list[int]) -> float:
    stat, p = proportions_ztest(successes, totals, alternative="two-sided")
    return float(p)


p = two_proportion_pvalue([120, 150], [1000, 1000])
print(round(p, 4))
assert 0 < p < 1

Demo 2 — Absolute and relative lift

# Offline demo: absolute (pp) vs relative lift
def absolute_lift(p_a: float, p_b: float) -> float:
    return p_b - p_a


def relative_lift(p_a: float, p_b: float) -> float:
    return (p_b - p_a) / p_a


print(round(absolute_lift(0.12, 0.15), 3), round(relative_lift(0.12, 0.15), 3))
assert abs(absolute_lift(0.12, 0.15) - 0.03) < 1e-12

Demo 3 — Confidence interval for the difference

# Offline demo: CI for treatment − control conversion difference
from statsmodels.stats.proportion import confint_proportions_2indep


def lift_ci(s1: int, n1: int, s2: int, n2: int, alpha: float = 0.05):
    """s1,n1 = control; s2,n2 = treatment; returns CI for p2 − p1."""
    low, high = confint_proportions_2indep(s2, n2, s1, n1, alpha=alpha, compare="diff")
    return float(low), float(high)


ci = tuple(round(x, 4) for x in lift_ci(120, 1000, 150, 1000))
print(ci)
assert ci[0] < ci[1]

[!important] A tiny p-value on a 0.05 pp lift may be statistically significant and still not worth engineering cost.


Statistical vs business significance

A Hyderabad SaaS team can get p < 0.05 on a +0.1 pp lift with huge traffic. Shipping may still lose money after design QA, localisation, and support docs. Always pair the p-value with:

  1. Lift CI — does it clear the MDE / cost hurdle?
  2. Guardrails — errors, refunds, latency.
  3. Implementation cost in eng-weeks and INR.

WHY Alpha controls false positives, not ROI.

WHEN In the readout template, not as a hallway debate after the fact.

Demo 4 — Business hurdle on the CI

# Offline demo: require CI lower bound above a business hurdle (pp)
def clears_hurdle(ci: tuple[float, float], min_lift_pp: float) -> bool:
    low, high = ci
    return low >= min_lift_pp


ci_ok = (0.012, 0.040)
ci_weak = (0.001, 0.028)
assert clears_hurdle(ci_ok, 0.01) is True
assert clears_hurdle(ci_weak, 0.01) is False
print(clears_hurdle(ci_ok, 0.01), clears_hurdle(ci_weak, 0.01))

Demo 5 — Readout dictionary

# Offline demo: one pasteable readout for the PM ticket
from statsmodels.stats.proportion import proportions_ztest, confint_proportions_2indep


def two_proportion_pvalue(successes: list[int], totals: list[int]) -> float:
    _, p = proportions_ztest(successes, totals, alternative="two-sided")
    return float(p)


def lift_ci(s1: int, n1: int, s2: int, n2: int, alpha: float = 0.05):
    low, high = confint_proportions_2indep(s2, n2, s1, n1, alpha=alpha, compare="diff")
    return float(low), float(high)


def clears_hurdle(ci: tuple[float, float], min_lift_pp: float) -> bool:
    low, high = ci
    return low >= min_lift_pp


def readout(
    successes: list[int],
    totals: list[int],
    alpha: float = 0.05,
    min_lift_pp: float = 0.0,
) -> dict:
    p_a = successes[0] / totals[0]
    p_b = successes[1] / totals[1]
    pval = two_proportion_pvalue(successes, totals)
    ci = lift_ci(successes[0], totals[0], successes[1], totals[1], alpha=alpha)
    return {
        "cvr_a": round(p_a, 4),
        "cvr_b": round(p_b, 4),
        "abs_lift": round(p_b - p_a, 4),
        "pval": round(pval, 4),
        "lift_ci": (round(ci[0], 4), round(ci[1], 4)),
        "sig_at_alpha": pval < alpha,
        "clears_hurdle": clears_hurdle(ci, min_lift_pp),
    }


print(readout([120, 150], [1000, 1000], min_lift_pp=0.01))
assert readout([120, 150], [1000, 1000])["sig_at_alpha"] in {True, False}

Chi-square on the 2×2 table

Some teams prefer chi2_contingency on counts. For 2×2 conversion tables it answers the same association question; pick one primary test in the brief and stick to it.

Demo 6 — Chi-square alternative

# Offline demo: 2×2 chi-square p-value for conversion counts
import numpy as np
from scipy.stats import chi2_contingency


def chi2_pvalue(successes: list[int], totals: list[int]) -> float:
    table = np.array([
        [successes[0], totals[0] - successes[0]],
        [successes[1], totals[1] - successes[1]],
    ])
    _, p, _, _ = chi2_contingency(table)
    return float(p)


print(round(chi2_pvalue([120, 150], [1000, 1000]), 4))
assert 0 < chi2_pvalue([120, 150], [1000, 1000]) < 1

Reporting norms that travel well

In a Pune product review, paste rates, lift CI, p-value, SRM status, guardrail deltas, and the pre-registered decision rule. Avoid screenshots of a BI tool with seven undeclared segments. If someone asks for "Android-only," treat it as exploratory unless multiplicity was planned.

WHY Confirmatory vs exploratory is a social contract.

WHEN Before the review meeting; do not invent rules live.

Demo 7 — Segment label as exploratory

# Offline demo: mark unplanned slices as exploratory
def slice_label(name: str, pre_registered_slices: set[str]) -> str:
    return "confirmatory" if name in pre_registered_slices else "exploratory"


registered = {"overall"}
assert slice_label("overall", registered) == "confirmatory"
assert slice_label("android_only", registered) == "exploratory"
print(slice_label("android_only", registered))

Readouts that survive a product review

At analysis time you already have clean exposures, a frozen window, and a pre-registered primary. The z-test or chi-square gives a p-value for that design. The confidence interval for the difference tells you whether the lift clears a business hurdle, not only whether it differs from zero. A Bengaluru D2C team with huge traffic can achieve p < 0.05 on a +0.1 pp lift that does not pay for design QA and localisation. Pair significance with the CI lower bound and implementation cost in eng-weeks and INR.

Keep absolute and relative language straight in the readout. "+10% relative" on a 10% baseline is +1 pp absolute; stakeholders mix them constantly. Paste CVR by arm, lift CI, p-value, SRM status, and guardrail deltas into the ticket. Label any Android-only or city slice as exploratory unless it was pre-registered with a multiplicity plan. Exploratory cuts are allowed for learning; they are not allowed to flip a confirmatory no-ship into a ship.

Prefer two-sided tests unless the brief locked a one-sided alternative before looking. Choosing the side after seeing the sign of the lift is another form of peeking. If primary and CI disagree awkwardly, re-check success/total inputs and whether control is in the first slot of your helpers. The next lesson shows how optional stopping destroys the meaning of a 0.05 threshold even when every individual look used a "valid" z-test.

Statistical significance answers "is this compatible with noise under H0?" Business significance answers "is this worth shipping given cost and risk?" Both belong on the same page. A NO-SHIP with a narrow positive CI below your cost hurdle is still a successful experiment: you learned the change is small. Record that learning so the next colour test does not restart from opinions alone.

WHY Decision quality needs interval + cost + guardrails, not a lone star next to p.

WHEN On the end date, with the rule quoted verbatim in the readout.

Failure modes

  1. Shipping on p < 0.05 with CI covering zero (depending on test vs CI mismatch) or CI below the cost hurdle.
  2. One-sided p-value after seeing the sign.
  3. Ignoring guardrails because primary looked fine.
  4. Peeking — next lesson shows how false positives explode.

Official statsmodels docs describe the estimators; your brief describes the decision rule.

Verified against numpy 2.1.3, scipy 1.14.1, pandas 2.2.3 (+1 more) documentation, September 2026.

Test yourself

  1. What does proportions_ztest return (conceptually)?
  2. Absolute vs relative lift — which is in percentage points here?
  3. Why report a confidence interval?
  4. True or false: p < 0.05 always means ship.
  5. What inputs does lift_ci need?
  6. Name one business cost of shipping a tiny lift.
  7. Which variant is control in lift_ci(s1,n1,s2,n2) as written?
  8. What prerequisite covers p-values?
  9. Why prefer two-sided tests unless pre-registered?
  10. True or false: peeking mid-test does not affect how you should interpret p-values.