【问题标题】:Confidence interval from binomial distribution: different results using `qbinom` and `binom.test`二项分布的置信区间:使用`qbinom`和`binom.test`的不同结果
【发布时间】:2021-06-05 15:19:21
【问题描述】:

我希望使用 qbinombinom.test 计算一个 CI 的结果相同,但它们实际上略有不同:

success <- 360
n <- 1226
lci <- qbinom(0.025, n, success/n)/n
uci <- qbinom(0.975, n, success/n)/n
c(lci, uci)

[1] 0.2683524 0.3189233

binom.test(success, n, success/n)$conf.int

[1] 0.2682571 0.3200123

我在这里错过了什么?

【问题讨论】:

  • 查看bins.test 的来源,使用qbeta() 函数计算置信限。上限为qbeta(1 - alpha, x + 1, n - x)

标签: r binomial-cdf


【解决方案1】:

binom.test 函数的源代码使用qbeta 而不是qbinom,因为这是exact binomial confidence intervals 的公认公式。其中x 是成功次数,binom.test 给出的 lci 和 uci 是:

p.L <- function(x, alpha) {
    if (x == 0) 
        0
    else qbeta(alpha, x, n - x + 1)
}
p.U <- function(x, alpha) {
    if (x == n) 
        1
    else qbeta(1 - alpha, x + 1, n - x)
}

alpha <- (1 - 0.95)/2
lci <- p.L(x, alpha)
uci <- p.U(x, alpha)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    • 2019-07-20
    • 1970-01-01
    • 2014-03-10
    • 2019-12-26
    相关资源
    最近更新 更多