元データ(有意差なし)
x <- matrix(c(12, 9, 8, 11), ncol=2, byrow=T)
rownames(x) <- c("Word.X", "Word.Y")
colnames(x) <- c("Corpus.A", "Corpus.B")
# 分割表の確認
x
## Corpus.A Corpus.B
## Word.X 12 9
## Word.Y 8 11
# Pearson's Chi-squared Test
chisq.test(x, correct=F)
##
## Pearson's Chi-squared test
##
## data: x
## X-squared = 0.9023, df = 1, p-value = 0.3422
# Yates' Continuity Correction
chisq.test(x)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: x
## X-squared = 0.401, df = 1, p-value = 0.5266
# オッズ比
library(vcd)
OddsRatio <- oddsratio(x, log = F)
# オッズ比の信頼区間 (下限値,上限値) の計算
CI <- confint(oddsratio(x, log = F))
CI.lower <- CI[1]; CI.upper <- CI[2]
# オッズ比のp値
p <- summary(vcd::oddsratio(x))
# 結果表示
cat("\n", "Odds Ratio [95%CI] =", OddsRatio, "[", CI.lower, ",",CI.upper,"]", "\n")
##
## Odds Ratio [95%CI] = 1.833333 [ 0.522362 , 6.434448 ]
p # p値の確認
## Log Odds Ratio Std. Error z value Pr(>|z|)
## [1,] 0.60614 0.64059 0.9462 0.344
セルの値をすべて10倍にした場合(有意差ありになり信頼区間が狭くなる)
x <- matrix(c(120, 90, 80, 110), ncol=2, byrow=T)
rownames(x) <- c("Word.X", "Word.Y")
colnames(x) <- c("Corpus.A", "Corpus.B")
# 分割表の確認
x
## Corpus.A Corpus.B
## Word.X 120 90
## Word.Y 80 110
# Pearson's Chi-squared Test
chisq.test(x, correct=F)
##
## Pearson's Chi-squared test
##
## data: x
## X-squared = 9.0226, df = 1, p-value = 0.002667
# Yates' Continuity Correction
chisq.test(x)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: x
## X-squared = 8.4311, df = 1, p-value = 0.003689
# オッズ比
library(vcd)
OddsRatio <- oddsratio(x, log = F)
# オッズ比の信頼区間 (下限値,上限値) の計算
CI <- confint(oddsratio(x, log = F))
CI.lower <- CI[1]; CI.upper <- CI[2]
# オッズ比のp値
p <- summary(vcd::oddsratio(x))
# 結果表示
cat("\n", "Odds Ratio [95%CI] =", OddsRatio, "[", CI.lower, ",",CI.upper,"]", "\n")
##
## Odds Ratio [95%CI] = 1.833333 [ 1.232571 , 2.726911 ]
p # p値の確認
## Log Odds Ratio Std. Error z value Pr(>|z|)
## [1,] 0.60614 0.20257 2.9922 0.00277 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
【まとめ】セルの値をすべて10倍にした場合,信頼区間に1を含んでおらず「有意差あり」となる。元データでは信頼区間に1が含まれているので(CI [0.522362, 6.434448]),「有意差なし」になっていることがわかる。