Pooled Two-Proportion Power With statsmodels

Quick Overview

Write a Python function that returns the power of a two-sided two-proportion z-test with statsmodels' power_proportions_2indep. It tests whether you can map a baseline rate, an absolute lift and a per-group sample size onto the API, explain the pooled variance convention, and return a plain float.

Pooled Two-Proportion Power With statsmodels

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: medium

Interview Round: Other

You are planning an A/B test on a conversion rate and want to know how likely the test is to detect a given lift. Write a Python function that returns the power of a two-sided two-proportion z-test under the pooled-variance convention, computed with `power_proportions_2indep` from `statsmodels.stats.proportion`. ```python def pooled_power_statsmodels(p_control: float, absolute_lift: float, n_per_group: int, alpha: float = 0.05) -> float: ... ``` The conventions are fixed: - `p_control` is the control (baseline) conversion rate. The treatment rate is `p_control + absolute_lift`, so the lift is absolute: 0.02 moves a 10% baseline to 12%. - `n_per_group` is the number of users in each arm, and the two arms are the same size. - The null hypothesis is that the two rates are equal, and the test is two-sided at level `alpha`. - The function returns a plain Python `float`. As a check, `pooled_power_statsmodels(0.10, 0.02, 3000)` should return about 0.697. ```hint Argument mapping Read which proportion statsmodels treats as the reference and how it builds the other one from `diff`. ``` ```hint Return type Look at what the function returns by default before you hand its result back to the caller. ``` ### Constraints & Assumptions - `0 < p_control < 1` and `0 < p_control + absolute_lift < 1`. - `n_per_group` is a positive integer. - `0 < alpha < 1`. - statsmodels, SciPy and NumPy are installed. ### What a Strong Answer Covers - Maps the baseline rate, the absolute lift and the per-group size onto the statsmodels arguments correctly, including equal allocation and the equality null. - Explains what "pooled" means in this calculation: which variance applies under the null and which under the alternative. - Returns a scalar float, not the library's results object. - Sanity-checks the number, for example power equal to alpha at zero lift, or a recomputation from the normal distribution. - Names the inputs that make the calculation invalid or the normal approximation unreliable. ### Follow-up Questions - How would you find the sample size per group that gives 80% power for the same baseline and lift? - How does the call change for a 70/30 traffic split, and which arm is sample 1? - Write the same power calculation without statsmodels, using only the normal distribution. - When do the pooled and unpooled conventions give noticeably different answers?

Overview: Write a Python function that returns the power of a two-sided two-proportion z-test with statsmodels' power_proportions_2indep. It tests whether you can map a baseline rate, an absolute lift and a per-group sample size onto the API, explain the pooled variance convention, and return a plain float.

Nov 24, 2026
mediumData ScientistOtherAnalytics & Experimentation
0
0

You are planning an A/B test on a conversion rate and want to know how likely the test is to detect a given lift. Write a Python function that returns the power of a two-sided two-proportion z-test under the pooled-variance convention, computed with power_proportions_2indep from statsmodels.stats.proportion.

def pooled_power_statsmodels(p_control: float, absolute_lift: float,
                             n_per_group: int, alpha: float = 0.05) -> float:
    ...

The conventions are fixed:

  • p_control is the control (baseline) conversion rate. The treatment rate is p_control + absolute_lift , so the lift is absolute: 0.02 moves a 10% baseline to 12%.
  • n_per_group is the number of users in each arm, and the two arms are the same size.
  • The null hypothesis is that the two rates are equal, and the test is two-sided at level alpha .
  • The function returns a plain Python float .

As a check, pooled_power_statsmodels(0.10, 0.02, 3000) should return about 0.697.

Constraints & Assumptions

  • 0 < p_control < 1 and 0 < p_control + absolute_lift < 1 .
  • n_per_group is a positive integer.
  • 0 < alpha < 1 .
  • statsmodels, SciPy and NumPy are installed.

What a Strong Answer Covers Guidance

  • Maps the baseline rate, the absolute lift and the per-group size onto the statsmodels arguments correctly, including equal allocation and the equality null.
  • Explains what "pooled" means in this calculation: which variance applies under the null and which under the alternative.
  • Returns a scalar float, not the library's results object.
  • Sanity-checks the number, for example power equal to alpha at zero lift, or a recomputation from the normal distribution.
  • Names the inputs that make the calculation invalid or the normal approximation unreliable.

Follow-up Questions Guidance

  • How would you find the sample size per group that gives 80% power for the same baseline and lift?
  • How does the call change for a 70/30 traffic split, and which arm is sample 1?
  • Write the same power calculation without statsmodels, using only the normal distribution.
  • When do the pooled and unpooled conventions give noticeably different answers?