Ryan
Ryan

Reputation: 934

What formula does prop.test use?

The prop.test function apparently doesn't use the formula given here to create a confidence interval, so what formula is being used? Below is a confidence interval CI computed with prop.test and a confidence interval CI.2 computed using the formula given here.

CI <- prop.test(5,10)$conf.int

se.hat <- 0.5/sqrt(10)
z <- qnorm(0.975)
CI.2 <- 0.5 + c(-1,1)*z*se.hat

CI
CI.2 # not the same

Upvotes: 7

Views: 3247

Answers (4)

kmonk_gun
kmonk_gun

Reputation: 1

For single proportion - it's the Wilson score test. For 2 proportions - it's the Rao score test, but the CI are Wald's

You can find more details in this question I asked on Cross Validated

Upvotes: 0

Pai
Pai

Reputation: 41

I figure out a way to get a CI exactly the same as by formula:

library(BSDA) 
x=35
n=50
phat=x/n
xvar=c(rep(1,x),rep(0,n-x))## replicate the original variable!
s=sqrt(phat*(1-phat))
z.test(xvar,sigma.x=s)

Upvotes: 0

Freddy
Freddy

Reputation: 421

We can confirm Ryan's answer comparing the results from IC.wc and prop.test using the example given below:

IC.wc <- function(x, n, conf.level=0.95){
  p <- x/n ; q <- 1-p
  alpha <- 1- conf.level
  z <- qnorm(p=alpha/2, lower.tail=F)
  const1 <- z * sqrt(z^2 - 2 - 1/n + 4*p*(n*q+1)) 
  const2 <- z * sqrt(z^2 + 2 - 1/n + 4*p*(n*q-1)) 
  L <- (2*n*p + z^2 - 1 - const1) / (2*(n+z^2))
  U <- (2*n*p + z^2 + 1 + const2) / (2*(n+z^2))
  c(L, U)
}

IC.wc(x=35, n=50)
prop.test(x=35, n=50, correct=TRUE)$conf.int

Upvotes: 2

Ryan
Ryan

Reputation: 934

It uses the Wilson score interval with continuity correction, i.e. the Yates chi-squared test.

Upvotes: 8

Related Questions