Wilcoxon rank-sum test • Testing problems and assumptions

Wilcoxon rank-sum test
• Testing problems and assumptions. Suppose that (X1 , . . . , Xn1 ) and (Y1 , . . . , Yn2 )
are two independent random samples, and X1 ∼ µ+Y1 . Two testing problems are of interest:
H0 : µ = 0 versus H1 : µ 6= 0
(1)
H0 : µ ≤ 0 versus H1 : µ > 0.
(2)
and
Note that the assumption X1 ∼ µ + Y1 holds true if X1 and Y1 are normal
random variables.
• Ranks. For a sample (D1 , . . . , Dn ), the rank of Di is its ranking in
(D1 , . . . , Dn ). Ranks are between 1 and n, and small values have small
ranks. When there are ties, the average ranks are used.
– In the sample (1, 4, 2, 6), the ranks of 1, 4, 2, 6 are 1, 3, 2, 4 respectively.
– In the sample (1, 4, 2, 2, 2, 2), the ranks of 1 and 4 are 1 and 6 respectively, and the rank of each 2 is (2 + 3 + 4 + 5)/4 = 3.5.
• Wilcoxon rank-sum test is based on the statistic
W =
n1
X
Ri ,
i=1
where R1 , . . ., Rn1 are the ranks of X1 , . . ., Xn1 in the combined sample
(X1 , . . . , Xn1 , Y1 , . . . , Yn2 ). For testing (1), we reject H0 if
min(W, 2m − W ) ≤ C,
where

1
m=
2
nX
1 +n2
i+
i=n1 +n2 −(n1 −1)
n1
X

n1 (n1 + n2 + 1)
i =
.
2
i=1
For testing (2), we reject H0 if W ≥ C.
• A statistic equivalent to W is
S=
n1 X
n2
X
I(Yj ≤ Xi ) = W −
i=1 j=1
n1 (n1 + 1)
.
2
For testing (1), we reject H0 if
min (S, n1 n2 − S) ≤ C.
For testing (2), we reject H0 if S ≥ C.
1
• Below we will assume that Xi ’s and Yj ’s are continuous random variables
so that the ranks of X1 , . . . , Xn1 , Y1 , . . . , Yn2 are distinct integers.
• The exact distribution of W under µ = 0 can be computed by listing
possible values of W and computing the corresponding probabilities.
• Example 1.
Suppose that (X1 , X2 ) and Y1 are two independent random samples, and X1 ∼ Y1 . Suppose that X1 has a probability density
function. Let R1 , R2 be the ranks of X1 , X2 in (X1 , X2 , Y1 ). Let
W = R1 + R2 .
List the possible values for W and compute the corresponding probabilities.
Ans. Possible values: 3, 4, 5. Probabilities: 1/3 each.
• The distribution of W under µ = 0 can be approximated using N (µ1 , σ 2 ),
where
n1 n2 (n1 + n2 + 1)
n1 (n1 + n2 + 1)
and σ 2 =
.
µ1 =
2
12
– For testing (2), the test rejects H0 at level a if Z > za . The p-value
is P (N (0, 1) > observed Z).
– For testing (1), the test rejects H0 at level a if |Z| > za/2 . The
p-value is 2P (N (0, 1) > observed |Z|).
• Example 2. Suppose that (X1 , . . . , X9 ) and (Y1 , . . . , Y8 ) are two independent random samples and X1 ∼ µ + Y1 . The observed (X1 , . . . , X9 )
are
11, 15, 10.5, 18, 12, 20, 24, 22, 25
and the observed (Y1 , . . . , Y8 ) are
13, 14, 10, 8, 16, 9, 17, 21
Can we conclude that µ > 0 at level 0.07? Use normal approximation for
the distribution of the rank-sum test statistic.
The ranks for 11, 15, 10.5, 18, 12, 20, 24, 22, 25 in the combined sample
11, 15, 10.5, 18, 12, 20, 24, 22, 25, 13, 14, 10, 8, 16, 9, 17, 21 are
5, 9, 4, 12, 6, 13, 16, 15, 17,
so W = 5 + 9 + 4 + 12 + 6 + 13 + 16 + 15 + 17 = 97. Compute
µ1 =
n1 (n1 + n2 + 1)
9(9 + 8 + 1)
=
= 81
2
2
2
and
σ2 =
n1 n2 (n1 + n2 + 1)
9 · 8(9 + 8 + 1)
=
= 108,
12
12
then
W − 81
Z= √
= 1.539601
108
The p-value is P (N (0, 1) > 1.539601), from the table for N (0, 1) probabilities, we have
P (N (0, 1) > 1.53) = 0.5 − 0.4370 = 0.063
and
P (N (0, 1) > 1.54) = 0.5 − 0.4382 = 0.0618,
so the p-value is between 0.063 and 0.0618 and we can conclude that µ > 0
at level 0.07.
• R commands. Suppose that the values for (X1 , . . . , Xn1 ) and (Y1 , . . . , Yn2 )
are stored in two vectors x and y in R respectively.
– For testing (1) using R, run
wilcox.test(x,y, alternative = "two.sided")
– For testing (2) using R, run
wilcox.test(x,y, alternative = "greater")
The R output after running wilcox includes the p-value and the value for
S = W − n1 (n1 + 1)/2.
• The probabilities that P (S ≤ 0), . . ., P (S ≤ n1 n2 ) can be found using the
R command
pwilcox((0:n1*n2), n1, n2)
where n1 and n2 are n1 and n2 respectively.
• Example 3. Consider the testing problem in Example 2. The R output
after running pwilcox((0:72), 9, 8) is
[1]
[6]
[11]
[16]
[21]
[26]
[31]
[36]
[41]
4.113534e-05
7.815714e-04
5.553270e-03
2.320033e-02
6.939531e-02
1.606335e-01
3.029206e-01
4.812834e-01
6.635130e-01
8.227067e-05
1.234060e-03
7.610037e-03
2.961744e-02
8.358700e-02
1.851913e-01
3.364870e-01
5.187166e-01
6.970794e-01
3
1.645413e-04
1.851090e-03
1.032497e-02
3.722748e-02
9.979432e-02
2.117236e-01
3.714932e-01
5.558206e-01
7.292884e-01
2.879473e-04
2.756067e-03
1.369807e-02
4.635952e-02
1.179350e-01
2.403538e-01
4.074044e-01
5.925956e-01
7.596462e-01
4.936240e-04
3.948992e-03
1.797614e-02
5.697244e-02
1.382970e-01
2.707116e-01
4.441794e-01
6.285068e-01
7.882764e-01
[46]
[51]
[56]
[61]
[66]
[71]
8.148087e-01
9.164130e-01
9.703826e-01
9.923900e-01
9.987659e-01
9.999177e-01
8.393665e-01
9.306047e-01
9.767997e-01
9.944467e-01
9.992184e-01
9.999589e-01
8.617030e-01
9.430276e-01
9.820239e-01
9.960510e-01
9.995064e-01
1.000000e+00
8.820650e-01
9.536405e-01
9.863019e-01
9.972439e-01
9.997121e-01
9.002057e-01
9.627725e-01
9.896750e-01
9.981489e-01
9.998355e-01
Can we conclude that µ > 0 at level 0.07?
Sol 1. Under µ = 0, P (S ≤ 50) = 0.9164130 and P (S ≤ 51) = 0.9306047,
so P (S ≥ 52) < 0.07 < P (S ≥ 51) so we can conclude that µ > 0 at level
0.1 if and only if S ≥ 52. From the calculation in Example 2, W = 97
and S = W − 9(9 + 1)/2 = 97 − 45 = 52, so we can conclude that µ > 0
at level 0.07.
Sol 2. The observed S is 52, so we compute P (S ≥ 52) under µ = 0. Since
P (S ≥ 52) = 1 − P (S ≤ 51) = 1 − 0.9306047 = 0.0693953 < 0.07,
we can conclude µ > 0 at level 0.07.
4