見出し画像

カイ2乗検定(chi-square test)

グラフのコードの出所:

グラフのスクリプト



imanishi$Digit <- factor(imanishi$Digit)

graph <- ggplot(imanishi, aes(x=Digit, y=Frequency)) +
  geom_bar(stat='identity') +
  theme_bw()
graph


カイ2乗検定の結果:

X-squared = 174.37, df = 9, p-value < 2.2e-16


library(ggplot2)
x <- seq(0, +180, 0.1)

dens <- data.frame(x=x, y=dchisq(x, 9))

ggplot(dens,aes(x,y)) +
         geom_line()+
geom_vline(xintercept = 16.92, linetype="dashed")+
geom_vline(xintercept = 21.67, linetype="dashed")+
geom_vline(xintercept = 174.37, linetype="dashed",col="red")

pchisq(q=16.92,df=9)
pchisq(q=21.67,df=9)
pchisq(q=174.37,df=9)
カイ2乗分布(自由度9)
pchisq()関数の出力
chisq.test(imanishi$Frequency,simulate.p.value=T)
simulate.p.value=TRUEと設定した場合

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