カテゴリカルデータ解析読書メモ(第3章)

第3章の内容は大体知ってる事なのでささっと。

二項検定

> binom.test(405, 765)

	Exact binomial test

data:  405 and 765
number of successes = 405, number of trials = 765, p-value =
0.1116
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.4933327 0.5652633
sample estimates:
probability of success 
             0.5294118 

pのデフォルトは0.5なのでテキストの例では省略できる。
ついでに95%信頼区間が分かる。

多項分布

多項分布用に*multinom()関数シリーズが用意されている。

> p <- c(0.382, 0.219, 0.305, 0.094)
> x <- c(39, 16, 27, 15)
> dmultinom(x, prob = p)
[1] 0.0001047239

カイ二乗検定

> x <- c(62, 52, 53, 38, 46, 49)
> chisq.test(x)

	Chi-squared test for given probabilities

data:  x
X-squared = 6.36, df = 5, p-value = 0.2727

chisq.test()のpの初期値は等確率なのでこちらもテキストの例だと省略出来る。