# Statistical Theory of Power Sampling (within R code)

I am curious about the statistical theory behind power.prop.test in R. I have dived into the code behind it and detailed it in Latex format. My question here is:

1. What is the background of and the underlying statistical theory behind power.prop.test?

In a strict two-sided scenario $Power&space;=&space;N_{lower}&space;(\frac{\Delta\sqrt{n}-q_2\sqrt{2\bar{v}}}{\sqrt{v_1+v_2}},\mu&space;=&space;0,&space;\sigma&space;=&space;1)&space;+&space;N_{upper}(\frac{\Delta\sqrt{n}+q_2\sqrt{2\bar{v}}}{\sqrt{v_1+v_2}},\mu,&space;\sigma)$

And in a non-strict one or two-sided scenario

$Power&space;=&space;N_{lower}&space;(\frac{\Delta\sqrt{n}-q_1\sqrt{(p_1+p_2)(1-\frac{p_1+p_2}{2}})}{\sqrt{p_1(1-p_1)+p_2(1-p_2)}},\mu&space;=&space;0,&space;\sigma&space;=&space;1)$

Where…

$p_x&space;=&space;\textup{probability&space;in&space;group&space;x}$

$v_x&space;=&space;p_x(1-p_x)$

$\bar{v}&space;=&space;\frac{p_1+p_2}{2}*(1-\frac{p_1+p_2}{2})&space;=&space;\bar{p}(1-\bar{p})$

$\Delta&space;=&space;\left&space;|&space;p_1-p_2&space;\right&space;|$

n = current sample size

$q_x&space;=&space;qnorm(\frac{sig.level}{\textup{1&space;or&space;2-sided}},&space;lower.tail&space;=&space;FALSE)$