ウィルコクソンの符号付き順位検定(Wilcoxon Signed Rank Test)のメモ。
ノンパラメトリックな対応のある差の検定(2時点)。
【目次】
正規近似、T近似について。exactは記載なし。
帰無仮説、対立仮設
・帰無仮説 2時点に差がない
・対立仮設 2時点に差がある
計算式等
■ 計算の流れ
① 前後差(変化量)を算出する。
② 前後差の絶対値に平均順位を付ける。前後差ゼロの扱いは手法により異なる。
Wilcoxon法:ゼロを除いて平均順位を付ける。
Pratt法 :ゼロを含めて平均順位を付ける。
③ 前後差が正の平均順位和 を用いて検定統計量
を算出し、p値を得る。
■ 期待値・分散
< Wilcoxon法 >
< Pratt法 >
※ n=被験者数、=前後差の絶対値のタイ数、
=前後差ゼロの数
■ 統計量
※ =前後差が正の平均順位和(Rank Sum)
■ t値、z値
※ Correct=連続修正。有:0.5、無:0。
計算例
架空データで計算。
① A列とB列が観測値。C列が前後差。
② 前後差の絶対値に平均順位を付ける。Wilcoxon法はD~I列、Pratt法はJ~O列。
・abs(diff):前後差の絶対値
D列=IF(C5<>0,ABS(C5),"")
J列=ABS(C5)
・RANK.AVG:平均順位
E列=IF(C5<>"",RANK.AVG(D5,D:D,1),"")
K列=IF(C5<>"",RANK.AVG(J5,J:J,1),"")
・Positive RANK.AVG:前後差が正の平均順位
F列=IF(C5>0,RANK.AVG(D5,D:D,1),"")
L列=IF(C5>0,RANK.AVG(J5,J:J,1),"")
・Negative RANK.AVG:前後差が負の平均順位
G列=IF(C5<0,RANK.AVG(D5,D:D,1),"")
M列=IF(C5<0,RANK.AVG(J5,J:J,1),"")
・t:タイの数
H列=IF(D5<>"",IF(COUNTIF($E$4:E5, E5)=1, COUNTIF(E:E,E5),""),"")
N列=IF(COUNTIF($K$4:K5, K5)=1, COUNTIF(K:K,K5),"")
・(t3-t):タイの補正項用
I列=IF(H5<>"", H5^3-H5, "")
O列=IF(N5<>"", N5^3-N5, "")
③ 前後差が正の平均順位和 を用いて検定統計量
を算出し、p値を得る。
今回は前後差ゼロを3つ含めたので各手法で結果が異なる。
Rで検算。
coinパッケージのデフォルトは、Pratt法・Z近似のp値を返す。連続修正はなし。
zero.method="Wilcoxon"
でWilcoxon法。distribution="exact"
でexact。
> library(coin) > ads0 <- data.frame( + before=c(10,13,12,12,20,19,18,13,16,20,10,14,20,17,20,18,20,15,13,20,13,18,17,23,16) + ,after=c(17,18,16,15,13,13,18,20,10,19,10,20,16,13,13,18,14,13,17,11,11,17,11,12,12) + ) > coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Wilcoxon", distribution="asymptotic") Asymptotic Wilcoxon Signed-Rank Test data: y by x (pos, neg) stratified by block Z = 1.4171, p-value = 0.1564 alternative hypothesis: true mu is not equal to 0 > coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Pratt", distribution="asymptotic") #--default Asymptotic Wilcoxon-Pratt Signed-Rank Test data: y by x (pos, neg) stratified by block Z = 1.4988, p-value = 0.1339 alternative hypothesis: true mu is not equal to 0
プログラムコード
library(coin) #-- Z近似 coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Wilcoxon", distribution="asymptotic") coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Pratt", distribution="asymptotic") #--default #-- Exact coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Wilcoxon", distribution="exact") coin::wilcoxsign_test(before ~ after, data=ads0, zero.method="Pratt", 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値を返す。
(ただし、JMPはPratt法のよう。)
参考
SAS Help Center
JMP Help
https://support.sas.com/resources/papers/proceedings-archive/SUGI94/Sugi-94-172%20Tian.pdf
Solved: Wilcoxon signed rank test : Test statistic S - JMP User Community
Wilcoxon Test • Simply explained - DATAtab
https://www.sciencedirect.com/topics/mathematics/wilcoxon-signed-rank-test