# A 52/48 split can sink your A/B test before anyone wins

> The same imbalance can be harmless or enough to throw out the whole experiment, and a few lines of code tell you which case you are in.

Original: https://fdetimes.net/en/guides/sample-ratio-mismatch-ab-test-check/

MSN once tested a 12-card carousel against a 16-card version, and engagement appeared to fall. The user counts in the variants also failed to match the configured split. Once the cause, which involved bot detection, was fixed, the result reversed.

The fault has a name: sample ratio mismatch, or SRM. It is not rare. An analysis cited by Microsoft in 2020 found that about 6% of the company's A/B tests suffered from it.

On a client site, you are often the last person to look at the numbers before they become a decision. An SRM check takes only a few minutes, but it has to happen before anyone asks, "Which variant won?"

## A 52/48 split can be harmless

Many people's first reflex is to look at the ratio and judge by eye. A 55/45 split tends to raise suspicion, while 52/48 sits closer to half and is easily waved through. Microsoft's Experimentation Platform team warns that this is inadequate, because a ratio carries no information about sample size.

Take a hypothetical example. If 1,000 users are split into 520 and 480, chi-square is 1.6 and p is about 0.21: chance could easily explain it. With 10,000 users, 5,200 and 4,800 give a p of about 0.00006. With 100,000, p is so small it is awkward to write out.

So at the same 52/48 ratio, the 1,000-user experiment can proceed, while the 10,000-user one must stop for investigation. The more times you toss a coin, the closer the result should be to half.

Chi-square measures this directly. It compares the observed counts with those expected from the configuration, then asks how rare a deviation this large would be if the split were working correctly.

The alarm threshold depends on the tool. Microsoft raises an alert only when p is below 0.0005, to limit false alarms, while the SRM Checker extension for Chrome, now discontinued, used 0.01.

A dataset with a p of 0.005 would trigger the extension but pass Microsoft's threshold. Choose one threshold, write it into the plan before the experiment runs and leave it alone once you have seen the numbers.

## Write the check in ten lines

`scipy.stats.chisquare` takes observed and expected counts. The function below therefore always makes you state the configured ratio.

```python
from scipy.stats import chisquare

def check_srm(observed, weights, alpha=0.0005):
    if len(observed) != len(weights):
        raise ValueError("Number of variants and weights must match")
    total = sum(observed)
    expected = [total * w / sum(weights) for w in weights]
    stat, p = chisquare(f_obs=observed, f_exp=expected)
    return {"expected": expected, "chi2": stat, "p": p, "srm": p < alpha}

print(check_srm([520, 480], [50, 50]))        # p is about 0.21
print(check_srm([5200, 4800], [50, 50]))      # p is about 0.00006
print(check_srm([52000, 48000], [50, 50]))    # p is about 1.1e-36
```

Use the middle line as the main example. The total is 10,000 users, so each variant should have 5,000. Each is off by 200, chi-square is 16, and p is below both thresholds above.

Count the unit that was randomized: if you split by user, count distinct users rather than sessions or page views. SciPy's documentation also gives the common rule that every observed and expected frequency should be at least 5, so do not run the check on the first handful of users.

## The absent users decide the result

In the same example, control has 5,200 users and 130 conversions, or 2.50%. Treatment has 4,800 users and 122 conversions, or about 2.54%. On a client slide, that is a win: an increase of about 1.7%.

Now suppose treatment should also have had 5,200 users, and that none of the missing 400 converted. The rate falls to 122 out of 5,200, about 2.35%, or some 6.2% below control. If all 400 had converted, treatment would reach 522 out of 5,200, about 10.04%.

The range from 2.35% to 10.04% is too wide to support a decision, because it contains both a loss and a resounding win. The SRM Checker FAQ says the same of this calculation: in practice, the range is often wide enough to include the possibility that the change had no effect.

Those two numbers show only how easily the result can flip; do not report them as a measured effect.

Why not assume that the 400 resemble everyone else? Because nothing guarantees that they went missing at random. The MSN case shows as much: the cause was tied to bot detection, and fixing it was enough to reverse the result.

**Key point:** In an A/B test, count everyone before you ask which variant won.

## Find the stage that loses users

When the alarm goes off, do not rush to change the formula. Build a table of counts by stage: assigned to a variant, actually exposed to it, remaining after bot filtering, and present in the report. Run `check_srm` at each stage; the first one that is off is where to open the logs.

The first two stages are easy to confuse. Assignment tells you who could be affected, while exposure records when a user actually comes under a variant's influence, in the distinction drawn by Spotify Confidence. That is why Amplitude recommends sending a custom exposure event at the moment the user experiences the variant.

```sql
-- One row per user; flags are normalized to 0/1 and never NULL.
SELECT variant,
       COUNT(*) AS assigned,
       SUM(exposed) AS exposed,
       SUM(CASE WHEN exposed = 1 AND is_bot = 0
                THEN 1 ELSE 0 END) AS after_bot_filter,
       SUM(CASE WHEN exposed = 1 AND is_bot = 0
                 AND in_report = 1
                THEN 1 ELSE 0 END) AS in_report
FROM experiment_users
WHERE experiment_id = 'checkout_test'
GROUP BY variant;
```

In the example, if `assigned` is 5,200 and 5,200 while `exposed` is 5,200 and 4,800, the split is fine and 400 users dropped out between the two stages. The first suspects are then load speed, redirects and tracking events.

If `assigned` is already off, examine the split and the assignment logging. If the counts diverge only after bot filtering, compare the users removed from each variant, as the MSN case teaches.

When the mismatch begins at assignment, three hypotheses deserve an early test. The table below pairs each with the first check to run.

| Hypothesis | Sign to look for | First step |
|---|---|---|
| Assignment logging fault | Users in the assignment system but not in the warehouse | Reconcile IDs between the two |
| Split changed midway | Daily ratio shifts in steps | Compare with configuration history |
| One variant started first | Only one variant in the first hours | Check the earliest assignment times |

Only then slice by day, browser, device and country. Each slice adds another chance of a false alarm, so treat them as clues and look for evidence in the logs before drawing a conclusion.

## What to say to a client waiting for good news

Do not open with "p-value." Say what you have seen, which decision is not yet safe and what happens next. For the example above, a serviceable message might read:

> The experiment was set to split evenly, but control has 5,200 users and treatment only 4,800. This gap is far beyond what chance would produce, so the 1.7% increase cannot yet be used to decide on a release.

Then give the faulty stage, the plan and what you need from the client:

> Treatment users are being lost between assignment and the recording of exposure; the cause is under investigation. The proposal is to find and fix the fault, recount and rerun. A frontend engineer and read access to the event logs are needed to begin.

If the client asks, "So did it win or lose?", the honest answer is that nobody knows yet. Microsoft advises against trusting the results until the root cause is diagnosed. Datadog's documentation likewise says that, until then, lift and confidence intervals are not a sufficient basis for a causal conclusion.

There is one exception. Statsig allows for accepting a decision based on affected data if the SRM is mild enough and the experiment low-risk enough, although investigating, fixing and restarting is usually still best. If the client takes that route, record who decided and why the risk was considered low.

## Four traps for people in a hurry

The easiest trap to fall into is deleting users from the larger variant or reweighting to match the ratio; Spotify Confidence advises against both. The counts will look tidy, but the missing users are still missing and the calculation does not know what they did.

The second trap is checking only when the result is bad. Make SRM a gate in the reporting pipeline and run it on wins and losses alike. The next is applying the current configured ratio to old data: if the client has just moved from 90/10 to 50/50, compare each period with its own configuration.

The last trap is treating a "pass" as a certificate. Georgi Georgiev gives the example of the flicker effect, when the original content flashes up: there are cases where the SRM check raises no alarm even though the results are badly skewed. Balanced counts do not tell you what users saw, so you still need to open the real page and reconcile events and metric definitions.

On a job application, "experience with A/B testing" says very little. Show a small repo with the check function, the stage-by-stage counts and an incident write-up; if you have ever stopped a report because the data was wrong, put that on your résumé explicitly. In job postings, phrases such as "experimentation," "data quality" or "measure impact" are the place to bring up that story.

And if an interviewer hands you a results table and asks which variant won, ask for the configured split and the number of users in each variant. Being willing to say "I don't know yet" in front of attractive numbers is a skill as worthy of practice as chi-square.

**Try this week:**

- Take a concluded A/B test, count the users in each variant and run check_srm with the configured ratio. If you have no data of your own, use the figures 5200 and 4800 from this article.
- Recount after each stage: assigned, actually exposed to the variant, past the bot filter, in the report. Write three sentences for the client: what you saw, what cannot be concluded yet, what happens next.

## Sources

- [Diagnosing Sample Ratio Mismatch in A/B Testing](https://www.microsoft.com/en-us/research/articles/diagnosing-sample-ratio-mismatch-in-a-b-testing/)

- [SRM Checker: FAQ](https://lukasvermeer.nl/srm/docs/faq/index.html)

- [What is Exposure Logging? (Spotify Confidence glossary)](https://confidence.spotify.com/glossary/exposure-logging)

- [Does Your A/B Test Pass the Sample Ratio Mismatch Check?](https://blog.analytics-toolkit.com/2019/does-your-a-b-test-pass-the-sample-ratio-mismatch-test/)

- [Datadog Docs: Experiment Diagnostics](https://docs.datadoghq.com/experiments/diagnostics/)

- [What is a Sample Ratio Mismatch? (Spotify Confidence glossary)](https://confidence.spotify.com/glossary/sample-ratio-mismatch)

- [Statsig Docs: Managing SRM](https://docs.statsig.com/guides/srm)

- [scipy.stats.chisquare — SciPy Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html)

- [Amplitude Docs: Sample Ratio Mismatch](https://amplitude.com/docs/experiment/troubleshooting/sample-ratio-mismatch)
