Per-group sample size for a two-proportion test with the arcsine (Cohen's h) effect size
Quick Overview
Implement a Python function that returns the per-group sample size for a two-sided two-proportion test using the statsmodels arcsine (Cohen's h) effect size. It tests power analysis, effect size conventions, equal allocation, and choosing the right rounding so the design still meets its target power.
Per-group sample size for a two-proportion test with the arcsine (Cohen's h) effect size
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `def sample_size_arcsine(p_control: float, p_treatment: float, alpha: float = 0.05, power: float = 0.8) -> int` in `solution.py`. It returns the sample size needed in each group (the total is twice the returned value) for a two-sided two-proportion test, using the `statsmodels` arcsine (Cohen's h) convention.
The function must follow these conventions exactly:
- Compute the effect size with `effect_size = proportion_effectsize(p_treatment, p_control)`. The textbook pooled or unpooled normal-approximation formula gives a different number and will not match.
- Solve for the sample size with `n = NormalIndPower().solve_power(effect_size=effect_size, nobs1=None, alpha=alpha, power=power, ratio=1.0, alternative='two-sided')`.
- Return `math.ceil(n)` as a Python `int`. Rounding to the nearest integer or flooring is wrong.
Example:
```python
sample_size_arcsine(0.10, 0.12) # returns 3835
```
```hint Rounding direction
`solve_power` returns a fractional sample size. Ask which way you can round it and still be sure the design reaches the requested power.
```
### What a Strong Answer Covers
- Calls `proportion_effectsize` with the arguments in the specified order and explains what Cohen's h measures
- Solves for `nobs1` with equal allocation and a two-sided alternative, and states that the result is per group
- Justifies the rounding direction and returns a plain Python `int`
- Explains why the arcsine result differs from the textbook two-proportion formula
- Handles edge cases such as equal proportions or a treatment rate below the control rate
### Follow-up Questions
- How would the function change if the treatment group were twice the size of the control group?
- How does the same one-point lift translate into Cohen's h at a 2% baseline versus a 50% baseline, and what does that do to the sample size?
- How would you invert the calculation to report the minimum detectable effect for a fixed sample size?
- How does the required sample size change for a one-sided test?
Overview: Implement a Python function that returns the per-group sample size for a two-sided two-proportion test using the statsmodels arcsine (Cohen's h) effect size. It tests power analysis, effect size conventions, equal allocation, and choosing the right rounding so the design still meets its target power.
Implement def sample_size_arcsine(p_control: float, p_treatment: float, alpha: float = 0.05, power: float = 0.8) -> int in solution.py. It returns the sample size needed in each group (the total is twice the returned value) for a two-sided two-proportion test, using the statsmodels arcsine (Cohen's h) convention.
The function must follow these conventions exactly:
Compute the effect size with
effect_size = proportion_effectsize(p_treatment, p_control)
. The textbook pooled or unpooled normal-approximation formula gives a different number and will not match.
Solve for the sample size with
n = NormalIndPower().solve_power(effect_size=effect_size, nobs1=None, alpha=alpha, power=power, ratio=1.0, alternative='two-sided')
.
Return
math.ceil(n)
as a Python
int
. Rounding to the nearest integer or flooring is wrong.
Example:
sample_size_arcsine(0.10, 0.12) # returns 3835
What a Strong Answer Covers Guidance
Calls
proportion_effectsize
with the arguments in the specified order and explains what Cohen's h measures
Solves for
nobs1
with equal allocation and a two-sided alternative, and states that the result is per group
Justifies the rounding direction and returns a plain Python
int
Explains why the arcsine result differs from the textbook two-proportion formula
Handles edge cases such as equal proportions or a treatment rate below the control rate
Follow-up Questions Guidance
How would the function change if the treatment group were twice the size of the control group?
How does the same one-point lift translate into Cohen's h at a 2% baseline versus a 50% baseline, and what does that do to the sample size?
How would you invert the calculation to report the minimum detectable effect for a fixed sample size?
How does the required sample size change for a one-sided test?