I am comparing two power functions in R, a base function stats::power.prop.test
, and the function pwr::power.2p.test
in the pwr
package.
I would think that they would give the same answer, but they are slightly different. And the equations being solved in the source code are different. Why are they different, and in what circumstances should I use one over the other?
If I understand the source code right, here is the power formula when the alternative hypothesis is that $p_1 < p_2$ for pwr
:
$$ \Phi \left( \Phi^{-1}\left( \alpha \right) - 2 \left( \arcsin \sqrt{p_1} - \arcsin \sqrt{p_2} \right) \sqrt{\frac{n}{2}}\right) $$
and for stats
:
$$ \Phi \left( \frac{ \sqrt{n} \left| p_1 - p_2 \right| + \Phi^{-1} \left( \alpha \right) \sqrt{ \left( p_1 + p_2 \right) \left( 1 - \left( p_1 + p_2 \right) \right)} } { \sqrt{p_1 \left( 1 - p_1 \right) + p_2 \left( 1 - p_2 \right)} }\right) $$
Below is some code comparing the output for the two functions.
require(pwr)
stats::power.prop.test(p1 = .50, p2 = .75, power = .90,
sig.level = 0.05, alternative = "two.sided")
## gives n = 76.71
pwr::pwr.2p.test(h = ES.h(0.50,0.75), power = .90,
sig.level = 0.05, alternative = "two.sided")
## gives n = 76.65