Power Curve Over Relative Lifts

Quick Overview

Implement a Python function that returns the two-sided power of an A/B test for each of several relative lifts over a baseline conversion rate. It tests converting relative lifts to rates, using Cohen's h with statsmodels' NormalIndPower, and returning a correctly shaped NumPy array.

Power Curve Over Relative Lifts

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `power_curve(p_control, relative_lifts, n_per_group, alpha=0.05)` in `solution.py`. For each relative lift `L`, compute the two-sided power of a fixed-traffic A/B test and return the results as a NumPy array. Requirements: - Lifts are relative: `p_treatment = p_control * (1 + L)`, not absolute additions. - Effect size: `h = proportion_effectsize(p_treatment, p_control)` (arcsine). - Power: `NormalIndPower().power(effect_size=h, nobs1=n_per_group, alpha=alpha, ratio=1.0, alternative='two-sided')`. - Return a 1-D `float64` `np.ndarray` with the same length and order as `relative_lifts` (not a list, dict or DataFrame), unrounded. Example: ```python power_curve(0.10, np.array([0.01, 0.02, 0.05, 0.10, 0.20]), 5000) # -> array([0.053174, 0.062710, 0.130733, 0.371434, 0.892354]) (approx) ``` ```hint Vectorize Check whether the two statsmodels functions accept an array of rates and effect sizes before you write a loop, and look at the type each one returns. ``` ### Constraints & Assumptions - `0 < p_control < 1`, and every `p_control * (1 + L)` must also stay strictly between 0 and 1. - `relative_lifts` is a 1-D array of floats of any length. - `n_per_group` is the number of users in each arm, and the arms are the same size. ### What a Strong Answer Covers - Converts each relative lift to a treatment rate multiplicatively. - Computes Cohen's h with the treatment rate first and passes it with the per-group size, equal allocation and a two-sided alternative. - Returns an unrounded 1-D `float64` array in the same order as the input lifts. - Sanity-checks the curve, for example power equal to alpha at zero lift and rising with the lift. - Names the inputs that break the calculation, such as a lift that pushes the treatment rate above 1. ### Follow-up Questions - How would you find the minimum `n_per_group` to reach 80% power for a given lift? - Why does the calculation use the arcsine effect size, and what would go wrong if you passed the raw difference in proportions to `NormalIndPower`? - How would the curve change with a 90/10 traffic split at the same total traffic?

Overview: Implement a Python function that returns the two-sided power of an A/B test for each of several relative lifts over a baseline conversion rate. It tests converting relative lifts to rates, using Cohen's h with statsmodels' NormalIndPower, and returning a correctly shaped NumPy array.

Nov 24, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement power_curve(p_control, relative_lifts, n_per_group, alpha=0.05) in solution.py. For each relative lift L, compute the two-sided power of a fixed-traffic A/B test and return the results as a NumPy array.

Requirements:

  • Lifts are relative: p_treatment = p_control * (1 + L) , not absolute additions.
  • Effect size: h = proportion_effectsize(p_treatment, p_control) (arcsine).
  • Power: NormalIndPower().power(effect_size=h, nobs1=n_per_group, alpha=alpha, ratio=1.0, alternative='two-sided') .
  • Return a 1-D float64 np.ndarray with the same length and order as relative_lifts (not a list, dict or DataFrame), unrounded.

Example:

power_curve(0.10, np.array([0.01, 0.02, 0.05, 0.10, 0.20]), 5000)
# -> array([0.053174, 0.062710, 0.130733, 0.371434, 0.892354])  (approx)

Constraints & Assumptions

  • 0 < p_control < 1 , and every p_control * (1 + L) must also stay strictly between 0 and 1.
  • relative_lifts is a 1-D array of floats of any length.
  • n_per_group is the number of users in each arm, and the arms are the same size.

What a Strong Answer Covers Guidance

  • Converts each relative lift to a treatment rate multiplicatively.
  • Computes Cohen's h with the treatment rate first and passes it with the per-group size, equal allocation and a two-sided alternative.
  • Returns an unrounded 1-D float64 array in the same order as the input lifts.
  • Sanity-checks the curve, for example power equal to alpha at zero lift and rising with the lift.
  • Names the inputs that break the calculation, such as a lift that pushes the treatment rate above 1.

Follow-up Questions Guidance

  • How would you find the minimum n_per_group to reach 80% power for a given lift?
  • Why does the calculation use the arcsine effect size, and what would go wrong if you passed the raw difference in proportions to NormalIndPower ?
  • How would the curve change with a 90/10 traffic split at the same total traffic?