Sub topic 13
Pitfalls: sample ratio mismatch, peeking, novelty, and interference
This chapter assumes you can read short Python snippets and know what a p-value and a two-proportion test are. You should also know how sticky assignment works from the earlier chapters on traffic splitting and A/B testing. The A/B test chapter showed how to compare two models. This chapter covers the ways that comparison goes wrong even when the arithmetic is correct.
Each pitfall below is either a validity problem, where the data no longer measures what you think, or an inference problem, where the statistics are used in a way they were not designed for. Check validity first. Statistics on invalid data only give you a precise wrong answer.
Sample ratio mismatch
You configured a 50/50 split. You should see roughly 50/50 in the data. A sample ratio mismatch (SRM) is a statistically significant deviation between the planned and the observed group sizes. It is a symptom, not a cause. It tells you that something between assignment and analysis treated the two groups differently, so the groups are no longer comparable.
Common causes in model rollouts:
- The candidate fails more often. Requests that time out or crash are never logged, so the candidate loses rows. The surviving rows are the "easy" requests, which flatters the candidate.
- Different logging paths. The candidate emits its exposure event from a new code path that drops events under load.
- Bot or retry filtering that applies to only one arm.
- Assignment bugs. A salt reused across experiments correlates assignments. A hash on a field that is empty for some users puts them all in one bucket.
- Triggered analysis. You count only users who reached a feature, but reaching it depends on the variant (for example, the candidate's slower page makes users leave before the model is called).
Test for SRM with a chi-square goodness-of-fit test on the counts. For two arms it has one degree of freedom, so the p-value comes from the normal distribution.
from math import sqrt
from statistics import NormalDist
def srm_check(n_stable: int, n_candidate: int, candidate_share: float = 0.5):
total = n_stable + n_candidate
expected_c = total * candidate_share
expected_s = total * (1 - candidate_share)
chi2 = ((n_candidate - expected_c) ** 2 / expected_c
+ (n_stable - expected_s) ** 2 / expected_s)
p_value = 2 * (1 - NormalDist().cdf(sqrt(chi2)))
return chi2, p_value
chi2, p = srm_check(n_stable=10000, n_candidate=10600)
print(f"chi2={chi2:.2f} p={p:.5f}")This prints a chi-square of about 17.5 and a p-value of about 0.00003. A 3% imbalance looks harmless, but at this sample size it is far too large to be chance.
Use a strict alarm threshold such as p < 0.001. You run this check on every experiment, so a 0.05 threshold would produce many false alarms. When the alarm fires, do not read the metric results. Find the cause, fix it, and restart the experiment.
Peeking
Peeking means checking the p-value repeatedly as data arrives and stopping when it crosses 0.05. A fixed-horizon test guarantees a 5% false positive rate only if you look once, at the planned sample size. Each extra look is another chance for random noise to cross the threshold.
The simulation below runs A/A tests, where both arms have the same 5% conversion rate, so every "significant" result is a false positive. It compares looking once at the end with stopping at the first of five looks that shows p < 0.05.
import random
from math import sqrt
from statistics import NormalDist
def p_value(x_a, n_a, x_b, n_b):
pooled = (x_a + x_b) / (n_a + n_b)
se = sqrt(pooled * (1 - pooled) * (1 / n_a + 1 / n_b))
if se == 0:
return 1.0
z = (x_b / n_b - x_a / n_a) / se
return 2 * (1 - NormalDist().cdf(abs(z)))
def simulate(runs=500, looks=5, per_look=500, rate=0.05, seed=7):
rng = random.Random(seed)
peek_hits = final_hits = 0
for _ in range(runs):
x_a = x_b = n = 0
crossed = False
for _ in range(looks):
x_a += sum(rng.random() < rate for _ in range(per_look))
x_b += sum(rng.random() < rate for _ in range(per_look))
n += per_look
if p_value(x_a, n, x_b, n) < 0.05:
crossed = True
peek_hits += crossed
final_hits += p_value(x_a, n, x_b, n) < 0.05
return peek_hits / runs, final_hits / runs
peek, final = simulate()
print(f"stop at first significant look: {peek:.1%}")
print(f"single look at the end: {final:.1%}")The single look stays near 5%. The peeking rule lands well above that, typically 10% to 15% with five looks, and it grows with more looks.
You have three honest options:
- Fix the horizon. Compute the sample size in advance and look only once. Dashboards may show data, but nobody decides from it.
- Use a sequential method. Group-sequential boundaries or always-valid p-values keep the error rate correct under repeated looks. They cost some power.
- Separate guardrails from the success metric. Watching error rate and latency continuously is fine, because stopping early for harm is a safety action. It does not claim a win.
The canary gate from the canary chapter is safe to evaluate often for the same reason. It decides whether to continue exposing users. It does not declare the candidate better.
Novelty and primacy effects
Users react to change itself. A new ranking model shows unfamiliar items, and users click more at first out of curiosity. This is a novelty effect, and the lift fades. A primacy effect is the opposite: users first stick to old habits, and the benefit of a better model grows as they adapt. Both mean that an early measurement is not the long-run effect.
Ways to detect them:
- Plot the daily treatment effect. A downward or upward trend in the effect points to novelty or primacy. A flat effect is reassuring.
- Compare new users with returning users. New users have no habits to disrupt, so a gap between the two groups suggests a novelty or primacy effect.
- Run for at least one or two full weekly cycles, so weekday and weekend behavior are both covered.
For models there is an additional time effect: a model trained on past data may degrade as the world drifts, so a short test can overstate or understate the effect you will see in month three.
Interference
A/B analysis assumes that one unit's outcome does not depend on which arm other units are in. Interference breaks this assumption. In model deployments it appears in several forms:
- Shared resources. A candidate that is slow or memory hungry raises latency for stable traffic on the same hosts. The stable arm looks worse than it would be alone.
- Shared state. Both arms write to or read from the same cache, feature store, or inventory. A candidate that recommends the last items in stock changes what the stable arm can sell.
- Marketplaces and networks. A pricing model that wins customers in the treatment arm takes them from the control arm. The measured difference overstates the true effect, because the control arm's loss is counted as a treatment gain.
- Feedback loops. Models trained on logged clicks learn from their own exposure. If both arms feed one training set, the arms influence each other's future data.
Mitigations depend on the source. Isolate infrastructure for the arms, or limit the candidate's resource use. Randomize by a larger unit, such as a region, a seller, or a time block, so that interacting units land in the same arm. Keep training data tagged by arm. Larger units reduce interference but lower statistical power, because you have fewer independent units.
Analysis-unit mismatch
If you randomize by user but analyze by request, a heavy user contributes thousands of correlated rows. The z-test then treats them as independent, the standard error is too small, and false positives rise. Analyze at the level of randomization: aggregate to one value per user first, or use cluster-robust standard errors or the delta method for ratio metrics.
Other common errors
Many metrics: if you test 20 metrics at 5%, you expect one false positive. Name one primary metric in advance, treat the rest as secondary, and correct for multiple comparisons when you must act on any of them. Segment fishing is the same problem: slicing by country, device, and plan until something is significant.
Summary table
| Pitfall | Symptom | Detection | Remedy |
|---|---|---|---|
| Sample ratio mismatch | Arm sizes differ from the planned split | Chi-square test, p < 0.001 | Find the logging or assignment bug, then restart |
| Peeking | Many "wins" that vanish later | Compare against a fixed-horizon plan | Fixed horizon or sequential testing |
| Novelty or primacy | Effect trends over time | Daily effect plot, new vs returning users | Longer runs, full weekly cycles |
| Interference | Arms affect each other | Shared-resource audit, cluster-level comparison | Isolate arms or randomize by cluster |
| Unit mismatch | Overconfident p-values | Compare randomization and analysis units | Aggregate to the randomization unit |
| Multiple comparisons | Isolated significant metric | Count the metrics tested | One primary metric, corrections |
A review order
Run the checks in the order below. Each step makes the next one meaningful.
Exercise
An experiment is planned as 90% stable and 10% candidate. After a week you see 904,000 stable users and 96,000 candidate users. The candidate's team notes that the candidate model times out on about 4% of requests and that timed-out requests are not logged. Is this an SRM, what is the likely cause, and should you read the conversion results?
Show answer
Expected counts are 900,000 and 100,000, so the candidate is short by 4,000 users, which is 4%. This matches the timeout rate, and at this sample size the deviation is far beyond chance, so it is an SRM. The likely cause is that timed-out requests are dropped from the candidate's logs, so exposed users are missing from the data. You should not read the conversion results. The missing users are not random, so the candidate's remaining users are biased. Fix the logging so failures are recorded as exposures with a failure outcome, then restart.
Exercise
A teammate runs an A/B test planned for 20,000 users per arm. After 5,000 per arm the dashboard shows p = 0.03, and they propose to stop and ship. Give two reasons not to, and one acceptable way to monitor during the test.
Show answer
First, the plan fixed the horizon at 20,000 per arm, and stopping at the first significant look inflates the false positive rate above 5%, as the A/A simulation shows. Second, a result at a quarter of the planned sample may reflect a novelty effect and has not covered a full weekly cycle. An acceptable way to monitor is to watch guardrail metrics such as error rate and latency continuously and stop early only for harm, or to use a sequential testing method designed for repeated looks.