Peeking, SRM, and Pitfalls
Lesson opener
In one line: Why peeking inflates false positives.
Why it matters: Each look is another chance to cross alpha by noise.
Before this lesson: Analyzing results
Before you start
| Resource | Link |
|---|---|
| Previous | Analyzing results |
| Next | Capstone — ship or no-ship |
| Prerequisites | Analyzing results |
| Time | ~50 minutes |
What you will learn
- Why peeking inflates false positives
- Novelty / primacy effects and weekday seasonality
- A simple sequential-look penalty intuition (Bonferroni)
- How SRM and instrumentation pitfalls invalidate pretty charts
Pinned libraries for this course
pip install -r docs/abtest/requirements.txtPinned in docs/abtest/requirements.txt:
numpy==2.1.3
scipy==1.14.1
pandas==2.2.3
statsmodels==0.14.4This lesson simulates peeking with numpy and statsmodels proportion tests — offline, no experiment platform required. Keep the trial counts modest on laptops; the qualitative gap between end-of-test and peeking false-positive rates already teaches the lesson without overnight runs.
Peeking simulation
If you check p-values every day and stop at the first "win", your false-positive rate rises above 5% even when the true lift is zero. That is not a vibe; it is optional stopping without a sequential boundary.
WHY Each look is another chance to cross alpha by noise.
WHEN Any time someone opens the BI dashboard "just to see."
A Chennai growth lead refreshing CVR every morning during a two-week test is peeking unless the design used sequential testing (or they only look at ops metrics like volume/SRM).
Demo 1 — False positives under daily peeking
# Offline demo: optional stopping inflates false positives (true lift = 0)
import numpy as np
from statsmodels.stats.proportion import proportions_ztest
def peeking_false_positive_rate(n_days: int = 14, n_per_day: int = 200, trials: int = 300) -> float:
rng = np.random.default_rng(1)
false_wins = 0
for _ in range(trials):
a_s = b_s = 0
a_n = b_n = 0
stopped = False
for _day in range(n_days):
a = rng.binomial(1, 0.10, size=n_per_day)
b = rng.binomial(1, 0.10, size=n_per_day) # no real lift
a_s += int(a.sum())
b_s += int(b.sum())
a_n += n_per_day
b_n += n_per_day
_, p = proportions_ztest([a_s, b_s], [a_n, b_n])
if p < 0.05:
stopped = True
break
if stopped:
false_wins += 1
return false_wins / trials
rate = peeking_false_positive_rate()
print(round(rate, 2))
assert rate > 0.05Demo 2 — Bonferroni look penalty (intuition only)
# Offline demo: crude alpha split across looks (conservative intuition)
def bonferroni_alpha(alpha: float, looks: int) -> float:
return alpha / max(looks, 1)
print(round(bonferroni_alpha(0.05, 10), 4))
assert abs(bonferroni_alpha(0.05, 10) - 0.005) < 1e-12Bonferroni is blunt. Real sequential designs (alpha spending, always-valid inference) are better — but inventing neither and stopping on day 2 is worse.
Demo 3 — Novelty warning
# Offline demo: early novelty / primacy checklist string
def novelty_warning(days_live: int, metric_name: str) -> str:
if days_live < 7:
return f"{metric_name}: early novelty possible — wait for pre-registered horizon"
return f"{metric_name}: past first week — still check weekday seasonality"
print(novelty_warning(3, "cvr"))
print(novelty_warning(14, "cvr"))
assert "novelty" in novelty_warning(3, "cvr")[!important] Pre-register the end date. Optional sequential methods exist — do not invent ad-hoc stop rules.
Novelty, primacy, and weekday mix
New UI often gets a short curiosity bump (novelty) or a short dip while users relearn (primacy). Indian consumer apps also show strong weekday vs weekend and salary-week patterns. Ending a test on a Monday after starting on a Friday can mislead if arms are unbalanced across days — another reason to freeze the window and prefer user-level assignment.
WHY Time effects are confounders when the design is messy.
WHEN Prefer full weeks in the pre-registered horizon when seasonality is strong.
Demo 4 — Weekday balance sketch
# Offline demo: flag uneven weekday exposure between arms
import pandas as pd
def weekday_balance_ok(frame: pd.DataFrame, max_pp_gap: float = 0.05) -> bool:
"""frame columns: variant, exposed_at."""
tmp = frame.copy()
tmp["dow"] = tmp["exposed_at"].dt.dayofweek
shares = tmp.groupby("variant")["dow"].value_counts(normalize=True).unstack(fill_value=0)
if list(shares.index) != ["A", "B"] and set(shares.index) != {"A", "B"}:
return False
gap = (shares.loc["A"] - shares.loc["B"]).abs().max()
return float(gap) <= max_pp_gap
demo = pd.DataFrame({
"variant": ["A", "B", "A", "B", "A", "B"],
"exposed_at": pd.to_datetime([
"2026-09-01", "2026-09-01", "2026-09-02",
"2026-09-02", "2026-09-03", "2026-09-03",
]),
})
print("balanced:", weekday_balance_ok(demo))
assert weekday_balance_ok(demo) is TrueSRM as a pitfall, not a footnote
Peeking is a statistical pitfall. Sample ratio mismatch is an instrumentation pitfall that makes the statistical story moot. Review both before any ship meeting.
Demo 5 — Combined health gate
# Offline demo: refuse primary analysis if SRM or peeking flags fire
from scipy.stats import chisquare
def health_gate(counts: list[int], peeked: bool, srm_alpha: float = 0.01) -> str:
_, srm_p = chisquare(counts, f_exp=[sum(counts) / 2] * 2)
if peeked:
return "STOP: peeking invalidated nominal alpha — use sequential design or wait for end"
if srm_p < srm_alpha:
return "STOP: SRM — fix assignment/logging"
return "OK: proceed to end-of-test primary analysis"
print(health_gate([5000, 5050], peeked=False))
print(health_gate([5000, 3500], peeked=False))
print(health_gate([5000, 5050], peeked=True))
assert health_gate([5000, 5050], peeked=False).startswith("OK")Demo 6 — End-of-test vs peek comparison
# Offline demo: same null data - one peek vs one end look
import numpy as np
from statsmodels.stats.proportion import proportions_ztest
def peeking_false_positive_rate(n_days: int = 14, n_per_day: int = 200, trials: int = 300) -> float:
rng = np.random.default_rng(1)
false_wins = 0
for _ in range(trials):
a_s = b_s = 0
a_n = b_n = 0
stopped = False
for _day in range(n_days):
a = rng.binomial(1, 0.10, size=n_per_day)
b = rng.binomial(1, 0.10, size=n_per_day)
a_s += int(a.sum())
b_s += int(b.sum())
a_n += n_per_day
b_n += n_per_day
_, p = proportions_ztest([a_s, b_s], [a_n, b_n])
if p < 0.05:
stopped = True
break
if stopped:
false_wins += 1
return false_wins / trials
def end_of_test_fpr(n: int = 2800, trials: int = 300, alpha: float = 0.05) -> float:
rng = np.random.default_rng(2)
wins = 0
for _ in range(trials):
a = rng.binomial(1, 0.10, size=n)
b = rng.binomial(1, 0.10, size=n)
_, p = proportions_ztest([int(a.sum()), int(b.sum())], [n, n])
if p < alpha:
wins += 1
return wins / trials
end_rate = end_of_test_fpr()
peek_rate = peeking_false_positive_rate()
print("end FPR~", round(end_rate, 2), "peek FPR~", round(peek_rate, 2))
assert peek_rate > end_rateCultural peeking and how to refuse it politely
Peeking is rarely malicious. A Chennai growth lead opens the dashboard every morning because leadership asks for a "pulse." Each pulse is another chance for noise to cross 0.05 when the true lift is zero. The simulation in this lesson is deliberately boring: identical conversion rates, optional stop on first win, inflated false-positive rate. Show that number in the review when someone proposes stopping early. Bonferroni is a blunt teaching tool; better sequential methods exist, but inventing neither and stopping on day two is the worst option.
Novelty and primacy distort early days: new colour gets curiosity taps, or confusion dips, then settles. Weekday mix matters when assignment or traffic is uneven across days. Prefer full weeks in the horizon when seasonality is strong. SRM remains a hard stop: a green primary with broken bucketing is an incident, not a launch. Health gates that refuse analysis when peeked=True or SRM fails keep the social contract intact.
Write the end date, look policy, and SRM threshold next to the metric. If leadership needs interim reads, give them exposure volume and SRM only — not primary p-values — or adopt a documented sequential design. The capstone combines these gates into a ship / no-ship function so the rule lives in code, not only in memory.
Compare end-of-test false-positive rate to peeking false-positive rate on the same null data. The gap is the cost of optional stopping. Teams that internalise that gap stop asking analysts to "just take a quick look" without changing the design. Festival weeks amplify the temptation to stop early when charts spike; resist unless the sequential plan already allowed that look. Put the look policy in the same ticket as the metric so nobody can claim ignorance mid-flight.
WHY Optional stopping and ignored SRM are the two fastest ways to ship noise.
WHEN Any time someone asks to "just check if we can end early."
Failure modes checklist
- Optional stopping on p < 0.05 mid-window.
- Novelty treated as durable lift.
- SRM ignored because the chart looked green.
- Multiple undeclared slices presented as confirmatory.
- Changing the primary metric after peeking.
Platform docs and stats libraries will not stop a Slack thread from declaring victory on day two — your pre-registered end date will. Print the look policy in the standup notes the day the flag flips so the pulse request has a written answer. The capstone encodes these refusals so the rule is hard to "forget" under launch pressure.
Verified against numpy 2.1.3, scipy 1.14.1, pandas 2.2.3 (+1 more) documentation, September 2026.
Test yourself
- What is peeking?
- Why does peeking raise false positives?
- What does the peeking simulation assume about true lift?
- What is Bonferroni adjusting (in the crude demo)?
- True or false: novelty effects always last a month.
- Name one reason weekday seasonality matters.
- What should you pre-register besides the metric?
- What does SRM have to do with pitfalls?
- True or false: stopping at p<0.05 on day 2 is fine if you planned two weeks but did not use a sequential design.
- Which lesson computes honest end-of-test p-values?