Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What formula does prop.test use?

Tags:

r

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
like image 954
Ryan Avatar asked Jan 11 '17 00:01

Ryan


2 Answers

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

like image 190
Ryan Avatar answered Sep 21 '22 12:09

Ryan


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
like image 21
Freddy Avatar answered Sep 22 '22 12:09

Freddy