如何在 R 中查詢二項分佈的 95% 置信區間?


二項分佈資料有兩個引數,樣本容量和成功次數。要查詢 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

更新時間:2020 年 10 月 10 日

703 次瀏覽

開啟您的事業

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.