19.3 二项检验 binom.test

比例 \(p\) 的检验, 做 \(n\) 次独立试验,样本 \(X_1,\ldots,X_n \sim b(1, p)\),事件发生的总次数 \(\sum_{i=1}^{n}X_i\)

函数 binom.test 用来检验伯努利试验中成功概率 \(p\) 和给定概率 \(p_0\) 的关系,属于精确检验。

编程手动实现一个,再调用函数计算,比较结果

# 模拟一组样本
x <- sample(x = c(0, 1), size = 100, replace = TRUE, prob = c(0.8, 0.2))

二项分布中成功概率的检验

binom.test(sum(x), n = 100, p = 0.5)
## 
##  Exact binomial test
## 
## data:  sum(x) and 100
## number of successes = 16, number of trials = 100, p-value = 2.606e-12
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
##  0.09431029 0.24678760
## sample estimates:
## probability of success 
##                   0.16

检验成功概率 p 是否等于 0.5, P 值 \(6.148 \times 10^{-11}\) 结论是拒绝原假设

binom.test(sum(x), n = 100, p = 0.2)
## 
##  Exact binomial test
## 
## data:  sum(x) and 100
## number of successes = 16, number of trials = 100, p-value = 0.3814
## alternative hypothesis: true probability of success is not equal to 0.2
## 95 percent confidence interval:
##  0.09431029 0.24678760
## sample estimates:
## probability of success 
##                   0.16

检验成功概率 p 是否等于 0.2, P 值 0.7081 结论是不能拒绝原假设

二项检验 (Clopper and Pearson 1934)

usage(binom.test)
binom.test(x, n, p = 0.5, alternative = c("two.sided", "less", "greater"),
    conf.level = 0.95)

参考文献

Clopper, C. J., and E. S. Pearson. 1934. “The Use of Confidence or Fiducial Limits Illustrated in the Case of the Binomial.” Biometrika 26 (4): 404–13. https://doi.org/10.1093/biomet/26.4.404.