Decide Whether to Raise a Sample Ratio Mismatch (SRM) Alarm for a 50/50 A/B Test

Quick Overview

Write a Python function that runs a chi-square goodness-of-fit sample ratio mismatch check on a 50/50 A/B test and decides whether to raise an alarm at a strict p-value threshold. It tests building expected counts correctly, choosing an alarm threshold for a platform that runs many experiments, and returning clean types.

Decide Whether to Raise a Sample Ratio Mismatch (SRM) Alarm for a 50/50 A/B Test

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `def srm_alarm(n_control: int, n_treatment: int) -> bool` in `solution.py`. For a 50/50-designed A/B test, run a chi-square goodness-of-fit Sample Ratio Mismatch (SRM) check and return whether to raise an alarm. The implementation must follow these rules: - `total = n_control + n_treatment`, `f_obs = [n_control, n_treatment]`, `f_exp = [total * 0.5, total * 0.5]`. - `p = scipy.stats.chisquare(f_obs, f_exp).pvalue`. - Return `True` if and only if `p < 0.0005`. The comparison is strict, and the threshold is `0.0005`, far below the usual `0.05`. - Return a native Python `bool`. Examples: ```python srm_alarm(10000, 9800) # -> False: close to 50/50, p is not below the threshold srm_alarm(9100, 900) # -> True: extreme split, p is astronomically small ``` ```hint Expected counts `f_exp` must hold one expected count per arm, on the same scale as `f_obs`. Watch what Python does when you multiply an integer by a list. ``` ### Constraints & Assumptions - Both counts are non-negative integers and the test was designed as a 50/50 split. - `scipy` is available. ### What a Strong Answer Covers - Expected counts for a 50/50 design, scaled to the observed total. - The strict threshold and why it sits so far below 0.05. - A native `bool` return value, and why the raw comparison result needs converting. - Edge cases such as an experiment with no units yet. ### Follow-up Questions - Why is a strict `0.0005` threshold used instead of `0.05`? - How would you generalize this to non-50/50 designs? - In a 50/50 test with 20,000 units, roughly how large a gap between the arms makes this check fire?

Overview: Write a Python function that runs a chi-square goodness-of-fit sample ratio mismatch check on a 50/50 A/B test and decides whether to raise an alarm at a strict p-value threshold. It tests building expected counts correctly, choosing an alarm threshold for a platform that runs many experiments, and returning clean types.

Nov 25, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement def srm_alarm(n_control: int, n_treatment: int) -> bool in solution.py. For a 50/50-designed A/B test, run a chi-square goodness-of-fit Sample Ratio Mismatch (SRM) check and return whether to raise an alarm.

The implementation must follow these rules:

  • total = n_control + n_treatment , f_obs = [n_control, n_treatment] , f_exp = [total * 0.5, total * 0.5] .
  • p = scipy.stats.chisquare(f_obs, f_exp).pvalue .
  • Return True if and only if p < 0.0005 . The comparison is strict, and the threshold is 0.0005 , far below the usual 0.05 .
  • Return a native Python bool .

Examples:

srm_alarm(10000, 9800)  # -> False: close to 50/50, p is not below the threshold
srm_alarm(9100, 900)    # -> True: extreme split, p is astronomically small

Constraints & Assumptions

  • Both counts are non-negative integers and the test was designed as a 50/50 split.
  • scipy is available.

What a Strong Answer Covers Guidance

  • Expected counts for a 50/50 design, scaled to the observed total.
  • The strict threshold and why it sits so far below 0.05.
  • A native bool return value, and why the raw comparison result needs converting.
  • Edge cases such as an experiment with no units yet.

Follow-up Questions Guidance

  • Why is a strict 0.0005 threshold used instead of 0.05 ?
  • How would you generalize this to non-50/50 designs?
  • In a 50/50 test with 20,000 units, roughly how large a gap between the arms makes this check fire?