I am using prop.test() to calculate the confidence interval of a proportion. I found that prop.test() result differs from the z-score confidence interval when $\hat p$ is small, but coincide otherwise. In particular, with $\hat p=0.916$ it works well:
n = 500
p_hat = 0.916
alpha = 0.1
se = sqrt(p_hat*(1-p_hat)/n)
z = -qnorm(alpha/2)
IC = c(p_hat-z*se,p_hat+z*se); IC
## [1] 0.8955953 0.9364047
prop.test(p_hat*n,n=n,alternative="two.sided", conf.level=1-alpha, correct=FALSE)
## 0.8932886 0.9342336
But with $\hat p = 0.016$ the results differ:
IC = c(p_hat-z*se,p_hat+z*se); IC
## [1] 0.006770041 0.025229959
prop.test(p_hat*n,n=n,alternative="two.sided", conf.level=1-alpha, correct=FALSE)
## 0.009038314 0.028171427
Do you know how in particular prop.test() calculates the confidence interval?
prop.testinverts the test to give a generally more accurate CI than the 'Wald score' CI $\hat p \pm 1.96\sqrt{\hat p(1-\hat p)/n},$ in which SE is estimated by using $\hat p$ instead of $p.$ See documentation from R console window at? prop.test. // The Wald interval is asymptotically correct as promised, but can fail badly even for moderately large $n.$ Difficulties are that it uses a normal approximation to binomial along with an estimated SE. (Google 'Agresti' for more accurate 95% CI.) – BruceET Nov 18 '17 at 05:02