二項検定

実行例

> binom.test(16,18,p=0.95)

Exact binomial test

data: 16 and 18
number of successes = 16, number of trials = 18, p-value = 0.2265
alternative hypothesis: true probability of success is not equal to 0.95
95 percent confidence interval:
0.6528796 0.9862488
sample estimates:
probability of success
0.8888889

#dbinom #1
> dbinom(16 , 18 ,p = 0.95)
[1] 0.1683485
#dbinom #2
> dbinom(1:16 , 18 ,p = 0.95)
[1] 1.304626e-21 2.106972e-19 2.135065e-17 1.521234e-15 8.092963e-14 3.331603e-12 1.085151e-10
[8] 2.834956e-09 5.984907e-08 1.023419e-06 1.414179e-05 1.567382e-04 1.374473e-03 9.326784e-03
[15] 4.725571e-02 1.683485e-01
> dbinom(1:16 , 18 ,p = 0.95) %>% sum()
[1] 0.2264774

binom.test

確率95%が想定される環境で18回試行の結果、16回の成功が得られた。想定された確率が正しいかを検証する。この場合は帰無仮説は「該当環境の確率は95%である」になり、binom.test はp値を0.2265としているので帰無仮説は成立する。

dbinom

確率95%の試行を18回行った時、成功16回となる確率を計算する。結果は16.8%。成功が16回以下を求めたい場合は引数に1:16を与え、その結果を合計すれば良い。この場合、22.65%が答えになる。

この記事が気に入ったらサポートをしてみませんか?