二项式数据有两个参数,样本量和成功次数。要找到95%的置信区间,我们只需要在R中使用prop.test函数,但是我们需要确保将正确的参数设置为FALSE,以便在不进行连续性校正的情况下计算置信区间。在下面的示例中,我们发现样本大小和成功次数的不同值具有95%的置信区间。
prop.test(x=25,n=100,conf.level=0.95,correct=FALSE)
输出结果
1-sample proportions test without continuity correction 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)
输出结果
1-sample proportions test without continuity correction 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)
输出结果
1-sample proportions test without continuity correction 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)
输出结果
1-sample proportions test without continuity correction 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)
输出结果
1-sample proportions test without continuity correction 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)
输出结果
1-sample proportions test without continuity correction 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)
输出结果
1-sample proportions test without continuity correction 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