Skip to content

Instantly share code, notes, and snippets.

@marknagelberg
Created July 22, 2018 17:37
Show Gist options
  • Save marknagelberg/42b3077db573bcce55e00f975b8e4fc5 to your computer and use it in GitHub Desktop.
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.
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