Sample Ratio Mismatch
Math of Sample Ratio Mismatch (SRM)
Sample Ratio Mismatch (SRM) is a diagnostic test used in Randomized Controlled Trials (RCTs) to detect if the actual distribution of participants between variants (e.g., Control and Treatment) significantly deviates from the intended design. It uses a Pearson’s Chi-square Goodness-of-Fit test.
1. Setup
- Variants: experimental groups (e.g., for Control and Treatment).
- Observed Counts (): The actual number of users assigned to variant .
- Total Sample Size (): The sum of all observed counts, .
- Target Allocation (): The intended probability of assignment for variant (e.g., for a 50/50 split).
2. Expected Counts ()
The number of users we expected to see in each variant if the randomization worked perfectly:
3. Chi-square Statistic ()
We calculate the cumulative squared deviation between observed and expected counts, normalized by the expected counts:
4. Hypothesis Testing
- Null Hypothesis (): The observed counts follow the target distribution (no mismatch).
- Degrees of Freedom (): .
- P-value: The probability of observing a statistic as extreme as the one calculated, assuming is true. It is derived from the Chi-square distribution:
- Decision: If (where is a conservative threshold like ), we reject and flag an SRM.
Example (50/50 split)
If you intended to split 1,000 users evenly but observed 450 in Control and 550 in Treatment:
- With , a of 10 gives , indicating a likely mismatch.
Real Example
CausalData(df=(10000, 6), treatment='d', outcome='conversion', confounders=['platform_ios', 'country_usa', 'source_paid'], user_id='user_id')
| treatment | count | mean | std | min | p10 | p25 | median | p75 | p90 | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.0 | 4955 | 0.198991 | 0.399281 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.0 | 1.0 |
| 1 | 1.0 | 5045 | 0.232904 | 0.422723 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.0 | 1.0 |
SRMResult(status=no SRM, p_value=0.36812, chi2=0.8100)
Using without CausalData
SRMResult(status=no SRM, p_value=0.47778, chi2=0.5039)