Sample Size, $n$

Power, $1-\beta$

Type I error rate, $\alpha$

X-axis

min

max

Documentation
Test 1 Mean
Compare 2 Means
Compare k Means
Test 1 Proportion
Compare 2 Proportions
Compare Paired Proportions
Compare k Proportions
Test Time-To-Event Data
Test Odds Ratio
Test Relative Incidence in Self Controlled Case Series Studies
Other

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

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\lt p_0$

or
$H_0:p=p_0$
$H_1:p\gt p_0$

### Formulas

This calculator uses the following formulas to compute sample size and power, respectively: $$n=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-\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

### R Code

R code to implement these functions:

p=0.05
p0=0.02
alpha=0.05
beta=0.20
(n=p0*(1-p0)*((qnorm(1-alpha)+qnorm(1-beta)*sqrt(p*(1-p)/p0/(1-p0)))/(p-p0))^2)
ceiling(n) # 191
z=(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.