Sample Size, $n$

Power, $1-\beta$

Type I error rate, $\alpha$



X-axis

min

max


Calculate Sample Size Needed to Other: 1-Sample Binomial


This calculator is useful for tests concerning whether a proportion, $p$, is equal to a reference value, $p_0$. The Null and Alternative hypotheses are

$H_0:p=p_0$
$H_1:p\neq p_0$

Formulas

This calculator uses the following formulas to compute sample size and power, respectively: $$n=p(1-p)\left(\frac{z_{1-\alpha/2}+z_{1-\beta}}{p-p_0}\right)^2$$
$$1-\beta=\Phi\left(\frac{p-p_0}{\sqrt{\frac{p(1-p)}{n}}}-z_{1-\alpha/2}\right)+\Phi\left(-\frac{p-p_0}{\sqrt{\frac{p(1-p)}{n}}}-z_{1-\alpha/2}\right)$$
where

R Code

R code to implement these functions:

p=0.5
p0=0.3
alpha=0.05
beta=0.20
(n=p*(1-p)*((qnorm(1-alpha/2)+qnorm(1-beta))/(p-p0))^2)
ceiling(n) # 50
z=(p-p0)/sqrt(p*(1-p)/n)
(Power=pnorm(z-qnorm(1-alpha/2))+pnorm(-z-qnorm(1-alpha/2)))

References

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