All problems
Two-Proportion z-Statistic
Problem
Return the two-proportion z-statistic (p1 - p2) / sqrt(p_pool*(1-p_pool)*(1/n1 + 1/n2)) with p_pool = (x1+x2)/(n1+n2). Return 0.0 when a sample size is not positive or the pooled proportion is 0 or 1.
Hint
The standard error always uses the pooled proportion under the null.
Test cases
case 1
in: [30,100,20,100]
expected: 1.6329931618554518
case 2
in: [50,100,50,100]
expected: 0
case 3
in: [10,50,5,50]
expected: 1.4002800840280096
case 4
in: [0,10,0,10]
expected: 0
case 5
in: [10,10,0,10]
expected: 4.47213595499958
Starter codePython
def two_proportion_z(x1, n1, x2, n2):
# Your code here
pass5 test cases · run your code against them in the editor