繁体   English   中英

R中二项式数据的置信区间?

[英]Confidence interval for binomial data in R?

我知道我需要 mean 和 sd 才能找到间隔,但是,如果问题是:

在对 1,000 名随机选择的工人进行的调查中,其中 520 名是女性。 根据调查为女性工人的比例创建 95% 的置信区间。

我如何找到平均值和标准差?

您还可以使用prop.test从包stats ,或binom.test

prop.test(x, n, conf.level=0.95, correct = FALSE)

        1-sample proportions test without continuity correction

data:  x out of n, null probability 0.5
X-squared = 1.6, df = 1, p-value = 0.2059
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
 0.4890177 0.5508292
sample estimates:
   p 
0.52 

您可能会发现这篇文章很有趣,在第 861 页的表 1 中给出了不同的置信区间,对于单个比例,使用七种方法计算(对于 n 和 r 的选定组合)。 使用prop.test您可以获得在表的第 3 行和第 4 行中找到的结果,而binom.test返回您在第 5 行中看到的结果。

在这种情况下,您有二项式分布,因此您将计算二项式比例置信区间

在 R 中,您可以使用Hmisc包中的binconf()

> binconf(x=520, n=1000)
 PointEst     Lower     Upper
     0.52 0.4890177 0.5508292

或者你可以自己计算:

> p <- 520/1000
> p + c(-qnorm(0.975),qnorm(0.975))*sqrt((1/1000)*p*(1-p))
[1] 0.4890345 0.5509655

或者,使用prevalence包中的函数propCI来获得五个最常用的二项式置信区间:

> library(prevalence)
> propCI(x = 520, n = 1000)
    x    n    p        method level     lower     upper
1 520 1000 0.52 agresti.coull  0.95 0.4890176 0.5508293
2 520 1000 0.52         exact  0.95 0.4885149 0.5513671
3 520 1000 0.52      jeffreys  0.95 0.4890147 0.5508698
4 520 1000 0.52          wald  0.95 0.4890351 0.5509649
5 520 1000 0.52        wilson  0.95 0.4890177 0.5508292

另一个包: tolerance将计算大量典型分布函数的置信度/容差范围。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM