All problems
Sample Size per Variant
Problem
Compute the required sample size per variant for a two-proportion test: ceil((z_alpha + z_beta)^2 * (p1*(1-p1) + p2*(1-p2)) / (p2 - p1)^2).
Return 0 when p1 == p2.
Hint
Smaller effects and lower variances both change required sample size dramatically.
Test cases
case 1
in: [0.1,0.12,1.96,0.84]
expected: 3834
case 2
in: [0.5,0.55,1.96,0.84]
expected: 1561
case 3
in: [0.2,0.1,1.645,0.84]
expected: 155
case 4
in: [0.1,0.1,1.96,0.84]
expected: 0
Starter codePython
import math
def sample_size_per_variant(p1, p2, z_alpha, z_beta):
# Your code here
pass4 test cases · run your code against them in the editor