Menu

Inputs

Calculate Sample Size Needed to Test 1 Proportion: 1-Sample, 1-Sided

This calculator is useful for tests concerning whether a proportion, pp, is equal to a reference value, p0p_0. The Null and Alternative hypotheses are
H0:p=p0H_0:p=p_0
H1:p<p0H_1:p\lt p_0
or
H0:p=p0H_0:p=p_0
H1:p>p0H_1:p\gt p_0

Formulas

This calculator uses the following formulas to compute sample size and power, respectively: n=p0(1p0)(z1α+z1βp(1p)p0(1p0)pp0)2n=p_0(1-p_0)\left(\frac{z_{1-\alpha}+z_{1-\beta}\sqrt{\frac{p(1-p)}{p_0(1-p_0)}}}{p-p_0}\right)^2
1β=Φ(p0(1p0)p(1p)(pp0np0(1p0)z1α))1-\beta=\Phi\left(\sqrt{\frac{p_0(1-p_0)}{p(1-p)}}\left(\frac{|p-p_0|\sqrt{n}}{\sqrt{p_0(1-p_0)}}-z_{1-\alpha}\right)\right)
where nn is sample size p0p_0 is the comparison value Φ\Phi is the standard Normal distribution function Φ1\Phi^{-1} is the standard Normal quantile function α\alpha is Type I error β\beta is Type II error, meaning 1β1-\beta is power

R Code

1p=0.05
2p0=0.02
3alpha=0.05
4beta=0.20
5(n=p0*(1-p0)*((qnorm(1-alpha)+qnorm(1-beta)*sqrt(p*(1-p)/p0/(1-p0)))/(p-p0))^2)
6ceiling(n) # 191
7z=(p-p0)/sqrt(p0*(1-p0)/n)(Power=pnorm(sqrt(p0*(1-p0)/p/(1-p))*(abs(z)-qnorm(1-alpha))))

References

Chow S, Shao J, Wang H. 2008. Sample Size Calculations in Clinical Research. 2nd Ed. Chapman & Hall/CRC Biostatistics Series. page 85.