Sample Ratio Mismatch (SRM) Check
Background
Sample Ratio Mismatch (SRM) is the #1 silent failure of online experiments. You expect a 50/50 traffic split; you see 48.7/51.3. With enough users, that 2.6% drift is wildly statistically significant - and it means something is broken upstream (assignment bug, caching, redirect-loss bias). Production experimentation platforms run an SRM chi-square on every experiment automatically; if it fires, the experiment is invalid and the metric numbers are not to be trusted.
Problem statement
Implement srm_check(arm_counts, expected_proportions, alpha=0.001) running a chi-square goodness-of-fit test:
with arms, observed counts, expected counts. Return (chi2, p_value, srm_detected).
Input
arm_counts- sequence ofint, observed user counts per arm.expected_proportions- sequence offloatsumming to , the planned split.alpha- significance level (default ; SRM is treated as serious, so a tight ).
Output
(chi2, p_value, srm_detected)- chi-square statistic (float), p-value (float in ), boolean.
Examples
Example 1 - clean 50/50
Input: arm_counts=[5000, 5000], expected_proportions=[0.5, 0.5]
Output: (0.0, 1.0, False)
Example 2 - SRM fires
Input: arm_counts=[4870, 5130], expected_proportions=[0.5, 0.5]
Output: chi2 ~ 6.76, p ~ 0.0093, srm_detected = True at alpha=0.05
Constraints
arm_countsandexpected_proportionsmust have the same length and arms.expected_proportionsmust sum to (within ).- Use
scipy.stats.chi2.sf(stat, df=K-1)or the closed-form viamath.expetc; for a numpy-only implementation is also OK. - Return Python
floats and abool.
Notes
- Why SRM matters more than a "small effect." If users are assigned to the wrong arms, every metric on the experiment is biased - including the metrics you're trying to read. SRM is an integrity check, not a power check.
- Alpha is tight. Production platforms use because false-positive SRMs are very expensive (you re-investigate the platform every time).
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: clean 50/50 split
- •Sample: drift fires at alpha 0.05
- •Example: three-arm balanced, no mismatch