Compute the minimum detectable effect (MDE) for a two-sample t-test

Quick Overview

Implement a Python function that returns the minimum detectable effect, in the metric's units, for a two-sided two-sample t-test given a standard deviation and a fixed size per arm. It tests statsmodels power analysis, standardized effect sizes, and how t-based and normal power calculations differ.

Compute the minimum detectable effect (MDE) for a two-sample t-test

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: medium

Interview Round: Other

Implement `mde_two_means` in Python. Given a standard deviation `sigma` for the metric (a planning value, assumed equal in both arms) and a fixed number of units per arm, return the minimum detectable effect (MDE) in the metric's own units for a two-sided independent-samples t-test. ```python def mde_two_means(sigma: float, n_per_group: float, alpha: float = 0.05, power: float = 0.8) -> float: ... ``` Requirements: - Solve for the standardized effect `d` with `TTestIndPower().solve_power(effect_size=None, nobs1=n_per_group, alpha=alpha, power=power, ratio=1.0, alternative='two-sided')`. - Use `TTestIndPower` from `statsmodels.stats.power`. Do not use `NormalIndPower`. - Return `d * sigma`, unrounded. The result is a raw difference in means, so do not return `d` itself or a relative lift. Example: ```python mde_two_means(20.0, 500) # 3.547168461448466 ``` With 500 units per arm and a standard deviation of 20, a true difference in means of about 3.55 is the smallest one the test detects with 80% power at a two-sided 5% level. ```hint Units of the solved effect Look at what `solve_power` returns when `effect_size` is the unknown. It is not in the metric's units yet. ``` ```hint A quick sanity check Compare your result with the normal-approximation MDE formula, and think about which of the two should be larger at a finite sample size. ``` ### Constraints & Assumptions - `sigma` is non-negative and in the metric's units; both arms share it. - `n_per_group` is the size of each arm, not the total. It must be greater than 1 so the test has positive degrees of freedom (`2 * n_per_group - 2`). - `0 < alpha < 1` and `alpha < power < 1`. The defaults are `alpha = 0.05` and `power = 0.8`. - The arms are equal in size, so `ratio = 1.0`. ### What a Strong Answer Covers - The exact `solve_power` call with the effect size as the unknown, and what quantity it returns. - The conversion from the solved value to the metric's units. - Why the t-based power analysis gives a different answer from the normal one, and how the gap changes with sample size. - Handling of the return type and of inputs for which no valid MDE exists. ### Follow-up Questions - Why does `TTestIndPower` give a different MDE than `NormalIndPower`, and when does the difference stop mattering? - How would you report the MDE as a relative lift, as a percent of the baseline mean? - How would you extend the function to unequal group sizes? - If you double the number of units per arm, roughly how much smaller does the MDE get?

Overview: Implement a Python function that returns the minimum detectable effect, in the metric's units, for a two-sided two-sample t-test given a standard deviation and a fixed size per arm. It tests statsmodels power analysis, standardized effect sizes, and how t-based and normal power calculations differ.

Nov 24, 2026
mediumData ScientistOtherAnalytics & Experimentation
0
0

Implement mde_two_means in Python. Given a standard deviation sigma for the metric (a planning value, assumed equal in both arms) and a fixed number of units per arm, return the minimum detectable effect (MDE) in the metric's own units for a two-sided independent-samples t-test.

def mde_two_means(sigma: float, n_per_group: float, alpha: float = 0.05,
                  power: float = 0.8) -> float:
    ...

Requirements:

  • Solve for the standardized effect d with TTestIndPower().solve_power(effect_size=None, nobs1=n_per_group, alpha=alpha, power=power, ratio=1.0, alternative='two-sided') .
  • Use TTestIndPower from statsmodels.stats.power . Do not use NormalIndPower .
  • Return d * sigma , unrounded. The result is a raw difference in means, so do not return d itself or a relative lift.

Example:

mde_two_means(20.0, 500)  # 3.547168461448466

With 500 units per arm and a standard deviation of 20, a true difference in means of about 3.55 is the smallest one the test detects with 80% power at a two-sided 5% level.

Constraints & Assumptions

  • sigma is non-negative and in the metric's units; both arms share it.
  • n_per_group is the size of each arm, not the total. It must be greater than 1 so the test has positive degrees of freedom ( 2 * n_per_group - 2 ).
  • 0 < alpha < 1 and alpha < power < 1 . The defaults are alpha = 0.05 and power = 0.8 .
  • The arms are equal in size, so ratio = 1.0 .

What a Strong Answer Covers Guidance

  • The exact solve_power call with the effect size as the unknown, and what quantity it returns.
  • The conversion from the solved value to the metric's units.
  • Why the t-based power analysis gives a different answer from the normal one, and how the gap changes with sample size.
  • Handling of the return type and of inputs for which no valid MDE exists.

Follow-up Questions Guidance

  • Why does TTestIndPower give a different MDE than NormalIndPower , and when does the difference stop mattering?
  • How would you report the MDE as a relative lift, as a percent of the baseline mean?
  • How would you extend the function to unequal group sizes?
  • If you double the number of units per arm, roughly how much smaller does the MDE get?