In [1]:
from scipy.stats import norm, zscore

def sample_power_probtest(p1, p2, power=0.8, sig=0.05):
    z = norm.isf([sig/2]) 
    zp = -1 * norm.isf([power]) 
    d = (p1-p2)
    s =2*((p1+p2) /2)*(1-((p1+p2) /2))
    n = s * ((zp + z)**2) / (d**2)
    
    return int(round(n[0]))
In [4]:
p0 = 100/1000
p20 = 80/1000
p30 = 70/1000
p40 = 60/1000
p50 = 50/1000

Power for detecting 20% decrease in infections

In [5]:
sample_power_probtest(p0, p20)
Out[5]:
3214

Power for 30%

In [6]:
sample_power_probtest(p0, p30)
Out[6]:
1357

Power for 40%

In [7]:
sample_power_probtest(p0, p40)
Out[7]:
722

Power for 50%

In [8]:
sample_power_probtest(p0, p50)
Out[8]:
436