Sample Ratio Mismatch (SRM) Check for an Unequal Control/Treatment Split

Quick Overview

Implement a sample ratio mismatch check in Python for an A/B test designed with an unequal split, such as a 90/10 holdout, using a chi-square goodness-of-fit test. It tests deriving expected counts from the designed fraction, choosing a strict alarm threshold, and handling inputs that break the test.

Sample Ratio Mismatch (SRM) Check for an Unequal Control/Treatment Split

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `srm_unequal_split(n_control: int, n_treatment: int, expected_control_frac: float) -> dict` in `solution.py`. Run a chi-square goodness-of-fit Sample Ratio Mismatch (SRM) check of the observed assignment counts against the designed split (`expected_control_frac` to control, remainder to treatment). The implementation must follow these rules: - `total = n_control + n_treatment` and `f_obs = [n_control, n_treatment]`. - `f_exp = [total*expected_control_frac, total*(1 - expected_control_frac)]`. - Call `scipy.stats.chisquare(f_obs, f_exp)`. - Return exactly `{'statistic': float, 'pvalue': float, 'srm_detected': bool}` with `srm_detected = (pvalue < 0.001)`. Example (values rounded): ```python srm_unequal_split(9100, 900, 0.9) # -> {'statistic': 11.1111, # 'pvalue': 0.000858, # 'srm_detected': True} ``` ```hint Designed split The test was not designed as 50/50. Turn the designed fraction into an expected count for each arm, and check what those counts must add up to. ``` ### Constraints & Assumptions - `n_control` and `n_treatment` are non-negative integers counted at assignment. - `expected_control_frac` is the designed share of traffic sent to control, strictly between 0 and 1 (for example 0.9 for a 90/10 holdout). - `scipy` is available. ### What a Strong Answer Covers - Expected counts derived from the designed fraction and scaled to the observed total. - The strict 0.001 threshold and the reason it is much lower than 0.05. - Plain Python `float` and `bool` values in the returned dict. - Inputs that break the test, such as a fraction of 0 or 1, or an experiment with no units. ### Follow-up Questions - Why scale `f_exp` to the observed total instead of using raw probabilities? - Why use a strict threshold of `0.001` rather than the usual `0.05`? - How would you extend the check to an experiment with three or more arms?

Overview: Implement a sample ratio mismatch check in Python for an A/B test designed with an unequal split, such as a 90/10 holdout, using a chi-square goodness-of-fit test. It tests deriving expected counts from the designed fraction, choosing a strict alarm threshold, and handling inputs that break the test.

Nov 25, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement srm_unequal_split(n_control: int, n_treatment: int, expected_control_frac: float) -> dict in solution.py. Run a chi-square goodness-of-fit Sample Ratio Mismatch (SRM) check of the observed assignment counts against the designed split (expected_control_frac to control, remainder to treatment).

The implementation must follow these rules:

  • total = n_control + n_treatment and f_obs = [n_control, n_treatment] .
  • f_exp = [total*expected_control_frac, total*(1 - expected_control_frac)] .
  • Call scipy.stats.chisquare(f_obs, f_exp) .
  • Return exactly {'statistic': float, 'pvalue': float, 'srm_detected': bool} with srm_detected = (pvalue < 0.001) .

Example (values rounded):

srm_unequal_split(9100, 900, 0.9)
# -> {'statistic': 11.1111,
#     'pvalue': 0.000858,
#     'srm_detected': True}

Constraints & Assumptions

  • n_control and n_treatment are non-negative integers counted at assignment.
  • expected_control_frac is the designed share of traffic sent to control, strictly between 0 and 1 (for example 0.9 for a 90/10 holdout).
  • scipy is available.

What a Strong Answer Covers Guidance

  • Expected counts derived from the designed fraction and scaled to the observed total.
  • The strict 0.001 threshold and the reason it is much lower than 0.05.
  • Plain Python float and bool values in the returned dict.
  • Inputs that break the test, such as a fraction of 0 or 1, or an experiment with no units.

Follow-up Questions Guidance

  • Why scale f_exp to the observed total instead of using raw probabilities?
  • Why use a strict threshold of 0.001 rather than the usual 0.05 ?
  • How would you extend the check to an experiment with three or more arms?