マクネマー検定 mcnemar.test *機能 行と列の対称性についての検定(マクネマー検定)を行う。~ 狭義のマクネマー検定は 2×2 分割表の場合である。~ R ではそれを 3×3 以上の分割表に拡張した対称性の適合度検定(goodness of fit test of symmetry)をカバーしている。~ なお,SPSS がサポートしているのは R とは別の拡張である。 *使用法 mcnemar.test(x, y = NULL, correct = TRUE) *引数 x 二次元行列の分割表,または factor オブジェクト y factor オブジェクト(x が行列の場合には無視される) correct 2×2分割表のときにのみ有効であり,連続性の補正を行うかどうかを指定する デフォルトは TRUE(連続性の補正を行う)である *戻り値 **関数からの出力 $ statistic : 検定統計量(カイ二乗分布に従う) $ parameter : カイ二乗分布の自由度 $ p.value : P 値 $ method : 検定の種別 $ data.name : データの記述 *例1 狭義のマクネマー検定 狭義のマクネマー検定は 2×2 分割表についてのものである > x <- c(2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2, 1, 2) > y <- c(2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1) > mcnemar.test(x, y) # 2 つのデータベクトルを与える場合 McNemar's Chi-squared test with continuity correction data: x and y McNemar's chi-squared = 0.3636, df = 1, p-value = 0.5465 > z <- table(x, y) > z y x 1 2 1 3 7 2 4 6 > mcnemar.test(z) # 行列として与える場合 McNemar's Chi-squared test with continuity correction data: z McNemar's chi-squared = 0.3636, df = 1, p-value = 0.5465 > binom.test(4, 11) # 2×2 分割表のときのマクネマー検定は近似検定なので, # 常に binom.test を行うのがよい Exact binomial test data: 4 and 11 number of successes = 4, number of trials = 11, p-value = 0.5488 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.1092634 0.6920953 sample estimates: probability of success 0.3636364 *例2 拡張されたマクネマー検定 > x <- matrix(c(9, 3, 1, 4, 12, 5, 2, 4, 13), 3, 3) > x [,1] [,2] [,3] [1,] 9 4 2 [2,] 3 12 4 [3,] 1 5 13 > mcnemar.test(x) McNemar's Chi-squared test data: x McNemar's chi-squared = 0.5873, df = 3, p-value = 0.8993