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
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 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))))
Chow S, Shao J, Wang H. 2008. Sample Size Calculations in Clinical Research. 2nd Ed. Chapman & Hall/CRC Biostatistics Series. page 85.