prop.test使用什么公式?

时间:2017-01-11 00:27:11

标签: r

prop.test函数显然不使用给定here的公式来创建置信区间,那么使用的公式是什么?以下是使用prop.test计算的置信区间CI和使用给定here的公式计算的置信区间CI.2

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

2 个答案:

答案 0 :(得分:3)

它使用Wilson score interval with continuity correction,即Yates卡方检验。

答案 1 :(得分:0)

我们可以使用下面给出的示例确认Ryan的答案,比较IC.wcprop.test的结果:

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