Given two proportions, p1 and p2,
I want to calculate the necessary samples of p1 I would need to do a Z-test of equivalence if:
1) alpha = .05
2) power = 0.9
3) n1/n2 = r
The Python stats models program gives something like this, but I think it is wrong because it gets drastically different answers from the STATA sampsi program.
The stata code is:
sampsi .01 .1, alpha(0.05) ratio(2)
which gives
Estimated sample size for two-sample comparison o
f proportions
Test Ho: p1 = p2, where p1 is the proportion in p
opulation 1 and p2 is the proportion in p opulation 2 Assumptions:
alpha = 0.0500 (two-sided)
power = 0.9000
p1 = 0.0100
p2 = 0.1000
n2/n1 = 2.00
Estimated required sample sizes:
n1 = 119
n2 = 238
The python code is:
import statsmodels.stats.api as sms
es = sms.proportion_effectsize(0.01, 0.1)
sms.NormalIndPower().solve_power(es, power=0.9, alpha=0.05, ratio=2)
Which gives:
80.25164112946563
As @rawr says in comments above, bsamsize works (you need to set the frac argument to the fraction of samples in group 1)
library("Hmisc")
bsamsize(.01, .1, power=.9, frac=1/3)
n1 n2
102.8526 205.7051
These are not the same numbers as Stata gives, but they're close. ?bsamsize gives details of the algorithm used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With