裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

マクネマー検定

2011年12月13日 | ブログラミング

「マクネマー検定についてのページ」で epibasix パッケージに mcNemar 関数があるのを知った。
しかし,この関数の実装は余り良くない。

(1) P 値が 0.001 より小さい場合,
McNemar's Chi^2 Statistic (corrected for continuity) = 12.345 which has a p-value of: 0
などと,表示され吃驚する。digit=3 になっているため 0.001 未満は 0 と表示されてしまうのだ。which has a p-value of less than 0.001 とか,せめて 0.000 とでも表示すればいかが?あるいは,デフォルトを digits=7 程度にしておくとか。

(2) "the number of discordant pairs exceeds 30" ということで,30 未満のときには force=TRUE などとやらねば,
以下にエラー mcNemar(data1, digits = 7) :
  The number of discordant pairs, must be greater than 30 to ensure validity.

などと,惨めな結果を思い知らされる。「なんにも計算しない」のではなく,警告メッセージと共に結果を表示すれば良いではないか。

さらにいえば,30 未満のときには二項検定を行ってその結果を表示すべき。さらにさらに,別に 30 未満に限らず,常に二項検定を行えばよいだけ。

> (x <- matrix(c(21, 3, 26, 72), 2))
     [,1] [,2]
[1,]   21   26
[2,]    3   72

> mcNemar(x)
 以下にエラー mcNemar(x) :
  The number of discordant pairs, must be greater than 30 to ensure validity.

> mcNemar(x, force=TRUE)

Matched Pairs Analysis: McNemar's Chi^2 Statistic and Odds Ratio
 
McNemar's Chi^2 Statistic (corrected for continuity) = 16.69 which has a p-value of: 0
 
McNemar's Odds Ratio (b/c): 8.667
95% Confidence Limits for the OR are: [3.319, -41.595]

> mcNemar(x, force=TRUE, digits=5)

Matched Pairs Analysis: McNemar's Chi^2 Statistic and Odds Ratio
 
McNemar's Chi^2 Statistic (corrected for continuity) = 16.68966 which has a p-value of: 4e-05
 
McNemar's Odds Ratio (b/c): 8.66667
95% Confidence Limits for the OR are: [3.31909, -41.59499]

> mcnemar.test(x)

    McNemar's Chi-squared test with continuity correction

data:  x
McNemar's chi-squared = 16.6897, df = 1, p-value = 4.402e-05

> binom.test(3, 29)

    Exact binomial test

data:  3 and 29
number of successes = 3, number of trials = 29, p-value = 1.524e-05
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.02186374 0.27351520
sample estimates:
probability of success
             0.1034483

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PVアクセスランキング にほんブログ村

PVアクセスランキング にほんブログ村