Wilcoxonの符号付き順位検定のExact法(正確確率検定)のメモ。
【目次】
正規近似とT近似での検定は以下記事。
cochineal19.hatenablog.com
計算例
簡単なデータを準備。
下図は正規近似・T近似での符号付き順位検定の記事で使った表。
ここにSinged Rank列(符号付き順位、前後差がマイナスなら順位にマイナスを付ける)とSinged Rank列の合計を追加(紫色のセル)。
観測値(前後差の絶対値)の順位(今回は1、2.5、2.5、4、5位)を固定した場合に、符号付き順位がとり得る全パターンとその順位和を計算する
(ゼロ処理はWilcoxon法:前後差ゼロは含めない、タイは平均順位)。
下図の25=32パターンが考えられる。
上図の全パターンを順位和別に頻度集計し、生起確率を計算する。
今回、観測値の符号付順位和は7なので、順位和=7とそれより珍しいパターンの確率を足し合わせる。
順位和=7~15が該当し、この確率の和が片側確率、その2倍が両側確率となる。
Rで実行。
coinパッケージの wilcoxsign_test
を使用。
zero.method="Wilcoxon"
でWilcoxon法を指定。
distribution="exact"
で正確確率を指定。
> ads0 <- data.frame( + before=c(10,13,13,13,20,21,21) + ,after=c(19,18,18,15,14,21,21) + ) > coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Wilcoxon", distribution="exact") Exact Wilcoxon Signed-Rank Test data: y by x (pos, neg) stratified by block Z = -0.9482, p-value = 0.4375 alternative hypothesis: true mu is not equal to 0
プログラムコード
library(coin) coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Wilcoxon", distribution="exact")
proc univariate data=ads; var diff; output out=out1 probs=probs; ods output TestsForLocation=out2; run;
SASでは、n<20はExact(正確確率)、n>=20ならWilcoxon法・t近似のp値を返す。