如何在 R 中查找二项式数据的 95% 置信区间?
r programmingserver side programmingprogramming更新于 2025/4/13 8:22:17
二项式数据有两个参数,即样本大小和成功次数。要查找 95% 置信区间,我们只需要使用 R 中的 prop.test 函数,但我们需要确保将正确的参数设置为 FALSE,这样就可以计算出置信区间而无需进行连续性校正。在下面的例子中,我们找到了不同样本大小和成功次数的 95% 置信区间。
示例
prop.test(x=25,n=100,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 25 out of 100, null probability 0.5 X-squared = 25, df = 1, p-value = 5.733e-07 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.1754521 0.3430446 sample estimates: p 0.25
示例
prop.test(x=5,n=100,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 5 out of 100, null probability 0.5 X-squared = 81, df = 1, p-value < 2.2e-16 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.02154368 0.11175047 sample estimates: p 0.05
示例
prop.test(x=5,n=1000,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 5 out of 1000, null probability 0.5 X-squared = 980.1, df = 1, p-value < 2.2e-16 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.002137536 0.011650955 sample estimates: p 0.005
示例
prop.test(x=5,n=10,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 5 out of 1000, null probability 0.5 X-squared = 980.1, df = 1, p-value < 2.2e-16 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.002137536 0.011650955 sample estimates: p 0.005
示例
prop.test(x=50,n=100,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 50 out of 100, null probability 0.5 X-squared = 0, df = 1, p-value = 1 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.4038315 0.5961685 sample estimates: p 0.5
示例
prop.test(x=500,n=1125,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 500 out of 1125, null probability 0.5 X-squared = 13.889, df = 1, p-value = 0.0001939 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.4156458 0.4736212 sample estimates: p 0.4444444
示例
prop.test(x=5000,n=9874,conf.level=0.95,correct=FALSE)
输出
未进行连续性校正的单样本比例检验 data: 5000 out of 9874, null probability 0.5 X-squared = 1.6079, df = 1, p-value = 0.2048 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.4965185 0.5162373 sample estimates: p 0.5063804