Sub topic 10
Checking Data Quality and Sample Ratio Mismatch
Prerequisites
You should understand feature flags, random assignment, proportions, and the experiment brief. This chapter assumes that engineering has implemented variant assignment and that data can report assignment events and outcome events.
A trustworthy result needs more than a large sample. You must first check that the right users entered the experiment, received the intended variants, and generated complete events. A broken assignment or missing event can make a real effect look smaller, larger, or even reverse direction.
Start with assignment and eligibility checks
Before reading conversion results, compare the experiment data with the plan:
- Confirm that every assigned user met the eligibility rule.
- Confirm that each user has one assignment for the experiment.
- Check that the assignment timestamp occurs before the measured outcome.
- Check that the user saw the intended experience.
- Check for duplicate assignments, missing assignments, and impossible variant names.
- Confirm that the randomization unit is not split across variants.
For example, if the randomization unit is user_id, the same user should not appear in both control and treatment. If a user can use several devices, check whether the system assigns by user or by device. Mixing these units can create contamination, where one user receives both experiences.
The assignment table and outcome table should also join at the planned unit. A missing join may mean that an event failed to arrive, not that the user failed to convert.
What sample ratio mismatch means
Sample ratio mismatch (SRM) occurs when the observed number of users in each variant differs from the planned allocation more than random variation reasonably explains. A 50/50 experiment with 100,000 eligible users might produce 49,900 control users and 50,100 treatment users. That small difference is usually harmless. A result such as 60,000 versus 40,000 needs investigation.
SRM can result from:
- Incorrect feature-flag rules
- Eligibility filters applied differently by variant
- Assignment events lost for one variant
- Users being counted more than once
- Bot or traffic filters affecting variants differently
- A mismatch between the intended and actual randomization unit
Do not “fix” SRM by deleting users until the counts look balanced. Find and correct the cause. If the cause cannot be explained, pause the experiment or treat its results as unreliable.
Run an SRM test
A chi-square goodness-of-fit test compares observed counts with expected counts. Its p-value estimates how surprising the observed split would be if the planned allocation were correct. Teams often investigate when the p-value is below 0.001, but the threshold should be agreed before analysis.
from scipy.stats import chisquare
def srm_p_value(control_count, treatment_count, treatment_share=0.5):
total = control_count + treatment_count
expected = [
total * (1 - treatment_share),
total * treatment_share,
]
observed = [control_count, treatment_count]
return chisquare(observed, f_exp=expected).pvalue
p_value = srm_p_value(50210, 49790)
print(f"SRM p-value: {p_value:.4f}")An SRM test does not prove that assignment is correct when it passes. It is one health check. Also inspect assignment by browser, country, platform, time, and eligibility pathway. A balanced overall split can hide a broken split in one important segment.
Exercise
A 50/50 experiment has 70,000 control users and 30,000 treatment users. The SRM p-value is below 0.001. What should the team do?
Show answer
Pause interpretation and investigate assignment rules, eligibility filters, duplicate users, and missing assignment events. Do not rebalance the data by deleting users.