## Tuesday, 3 September 2013

### Wilcoxon Signed Rank Test

The Wilcoxon Signed Rank test is a non-parametric test for paired/matched samples, and can be regarded as the non-parametric counterpart to the Paired Student's  t-test.  A worked example follows.

Suppose we have two groups of matched samples:

Group 1: 1,2,4,5,6,7,8,3

Group 2: 2,5,1,3,9,10,3,3

We first find the difference between these matched samples (Group 1 sample - Group 2 sample)

Group 1     Group 2      Difference
1                  2                     -1
2                  5                     -3
4                  1                    +3
5                  3                    +2
6                  9                     -3
7                10                     -3
8                  3                      5
3                  3                      0

We discard the case where there is 0 difference (the last pair), so that the sample size $N_r$ is $7$. Then, we sort the difference by absolute value and rank them, and highlight where there are ties (i.e. the same absolute values of the difference).

Rank      Difference
1               -1
2              +2
3               -3
4               -3
5               -3
6              +3
7              +5

The ranks for the ties are averaged out, resulting in

Rank      Difference
1               -1
2              +2
4.5            -3
4.5            -3
4.5            -3
4.5           +3
7              +5

Next we sum the ranks for the negative difference (which is $14.5$), and the sum of the positive difference can be found by subtracting 14.5 from the total rank ($7\times 8 \times 0.5=28$), which is $13.5$.

The value of $W$ (the Wilcoxon Signed-Rank statistic) is the lower of the (positive/negative) sum of the ranks, hence $13.5$.

We need to find the critical value of $W$, $Wcrit$, as there are only 7 samples, so that a z-score will be highly inaccurate. We do this by referring to a table for a two-tailed test at 5% level, and obtain $Wcrit=2$. As $W$ is greater than $Wcrit$, the result is not significant.

Even though the z-score will be inaccurate (on SciStatCalc, if the number of samples exceeds 25, the z-score is considered accurate enough, and the $Wcrit$ value is no longer used, to limit the size of the table storing $Wcrit$), it is nevertheless worth evaluating this as an exercise. The z-score is given by equation
$\Large \frac{W-\mu}{\sigma}$

where $\mu$ is the mean and $\sigma$ is the standard deviation.

The $\mu$ value is $\frac{Nr\times (N_r+1)}{4}$, and so will be $7\times 8\times 0.25 = 14$ for our example.

The $\sigma$ is given by $\sqrt{\frac{N_r(N_r+1)(2N_r+1)}{24}}$, and will be $\sqrt{7\times 8 \times 15 \times (1/24)}=5.9169$.

The z-score is thus $(13.5 - 14)/5.9169=-0.084515$, resulting in a p-value of 0.93, which is considerably larger than  the critical 0.05 value. The result is not significant by quite some margin.

Below is a screenshot of SciStatCalc with the results of the Wilcoxon signed rank test.