R で母比率(母集団における割合)の区間推定を行う方法。
目次
母比率の信頼区間(Agresti & Coull)
sを、success 分子(該当数)とする。
nを、number 分母(サンプルサイズ)とする。
Functionは以下の通りだ。
bohiritu.conf <- function(s,n){ p <- s/n p.dash <- (s+2)/(n+4) l.limt <- p.dash-1.96*sqrt((p.dash*(1-p.dash))/(n+4)) u.limt <- p.dash+1.96*sqrt((p.dash*(1-p.dash))/(n+4)) c("prop"=p, "prop.Agresti"=p.dash, "lower.limit"=l.limt, "upper.limit"=u.limt) }
500例のうち175例が陽性だったとする。
この時の区間推定は以下の通り。
> bohiritu.conf(175,500) prop prop.Agresti lower.limit upper.limit 0.3500000 0.3511905 0.3095159 0.3928650
ちなみに、二項分布で推定するとこうなる。
> binom.test(175,500) Exact binomial test data: 175 and 500 number of successes = 175, number of trials = 500, p-value = 1.903e-11 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.3081869 0.3935989 sample estimates: probability of success 0.35
母比率の区間推定(二項分布に基づく方法)
binom.test()で二項分布に基づいて,区間推定の結果が得られる。
100例中3例陽性だった場合の区間推定は以下の通り。
95 percent confidence intervalの項が区間推定範囲。
> binom.test(3,100) Exact binomial test data: 3 and 100 number of successes = 3, number of trials = 100, p-value < 2.2e-16 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.006229972 0.085176053 sample estimates: probability of success 0.03
1000例中30例陽性の場合はどうか?
> binom.test(30,1000) Exact binomial test data: 30 and 1000 number of successes = 30, number of trials = 1000, p-value < 2.2e-16 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.02033049 0.04255140 sample estimates: probability of success 0.03
割合は同じ3%だが、推定範囲は狭くなっている。
分母が大きくなっているため、推定精度が上がっている。
割合の信頼区間エクセル計算機
エクセルファイルを作成した。
良ければどうぞ。
割合の信頼区間計算機【エクセル計算機】 | TKER SHOP
使い方動画を作成した。
こちらもよければ。
まとめ
R で母比率を区間推定する方法として、Agresti-Coull の方法と二項分布による方法を解説した。
参考になれば。
参考文献
Agresti and Coull The American Statistician. 1998;52:119-126.
コメント