Created
July 22, 2018 17:37
-
-
Save marknagelberg/42b3077db573bcce55e00f975b8e4fc5 to your computer and use it in GitHub Desktop.
Code to support post on significance levels required for two sample z test of proportions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample_required(p1, p_diff, alpha): | |
if p_diff <= 0: | |
raise ValueError("p_diff must be > 0") | |
n = 1 | |
while True: | |
z = z_calc(p1, p1+p_diff, n1=n, n2=n) | |
p = 1 - stats.norm.cdf(z) | |
if p < alpha: | |
break | |
n += 1 | |
return n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment