How to do a Wilcoxon signed-rank test (paired data)
The Wilcoxon signed-rank test compares two paired conditions, such as before and after in the same animal, or control and treatment run side by side, using the ranks of the differences. It is the nonparametric alternative to the paired t test when the differences are not close to normal. Zero differences and the different definitions of W in each program trip people up, so this guide works through a numerical example.
When to use it
- Two paired conditions (before/after in the same subject, control and treatment in the same run)
- Rank the differences and compare the rank sums of positive and negative differences
- If the differences are close to normal, use the paired t test; if skewed or outlier-prone, the signed-rank test
- For three or more paired conditions, use the Friedman test
It is a different test from the Mann–Whitney U test for unpaired data (how to do it). It assumes the differences are symmetric around their center, but not that they are normal.
The steps
- Compute the difference for each pair (before − after, etc.)
- Drop pairs with a zero difference (Wilcoxon’s original method; Pratt’s method is explained below)
- Rank the absolute differences from smallest (ties get the average rank)
- Sum the ranks of positive differences (R+) and of negative differences (R−)
- The more lopsided R+ and R−, the more consistently the pairs move one way. Get P from W = min(R+, R−)
Example: blood pressure before and after (10 animals)
Systolic blood pressure in 10 mice before and after a drug (made up). Animal 3 has the same value twice (difference 0); only animal 7 goes up.
| Animal | Before | After | Difference (before − after) | Rank of |difference| | Signed rank |
|---|---|---|---|---|---|
| 1 | 142 | 131 | +11 | 6.5 | +6.5 |
| 2 | 155 | 148 | +7 | 4 | +4 |
| 3 | 138 | 138 | 0 | (dropped) | — |
| 4 | 160 | 149 | +11 | 6.5 | +6.5 |
| 5 | 149 | 145 | +4 | 2 | +2 |
| 6 | 151 | 139 | +12 | 8.5 | +8.5 |
| 7 | 147 | 150 | −3 | 1 | −1 |
| 8 | 158 | 146 | +12 | 8.5 | +8.5 |
| 9 | 144 | 137 | +7 | 4 | +4 |
| 10 | 153 | 146 | +7 | 4 | +4 |
Drop the one zero difference and rank the other 9. Three pairs have |difference| = 7 and share ranks 3, 4, 5 (average 4); 11 gets 6.5 and 12 gets 8.5.
R+ = 44, R− = 1 (they add up to 9 × 10 / 2 = 45), so W = min(44, 1) = 1.
| Result | |
|---|---|
| Wilcoxon signed-rank test (exact P) | W = 1, P = 0.0078 |
| Same, normal approximation | P = 0.010 |
| Effect size (matched-pairs rank-biserial r) | r = 0.96 |
| For comparison: paired t test | t(9) = 4.17, P = 0.0024 |
The P value counts all 2⁹ = 512 ways of assigning signs to the 9 ranks. Only two give R− ≤ 1 (all positive, or only rank 1 negative), so the two-sided P = 2 × 2 / 512 = 0.0078. The same counting works with ties and zeros, as long as there are few pairs. Like SciPy’s wilcoxon, BenchFig uses the exact distribution for up to 50 pairs without ties or zeros; with ties or zeros and 13 pairs or fewer, it counts all sign flips; otherwise it uses the normal approximation. The method used is shown with the result.
Handling zero differences
| Method | What it does | This example |
|---|---|---|
| Wilcoxon (SciPy default, BenchFig) | Drop zero differences, then rank | W = 1, P = 0.0078 |
| Pratt | Rank including zeros, then leave the zeros’ ranks out of the sums | W = 2, P = 0.0078 |
Here P is the same, but with many zeros the results can differ. Pratt’s method lets the unchanged pairs affect the ranks. In SciPy, use zero_method='pratt'.
W means different things in different software
The same test shows a different “W” or statistic depending on the software. The P value is the same, so make clear which definition you report.
| Software | Statistic shown | This example |
|---|---|---|
| SciPy (scipy.stats.wilcoxon, two-sided) | W = min(R+, R−) | 1 |
| BenchFig | W = min(R+, R−) (same as SciPy), plus R+ and R− | 1 |
| GraphPad Prism | Sum of signed ranks W = R+ − R− (sign depends on column order) | 43 (or −43) |
| R (wilcox.test) | V = R+ (rank sum of pairs where first − second is positive) | 44 |
If in doubt, report both “R+ = 44, R− = 1” so any reader can check it.
Wilcoxon signed-rank table of critical values (n = 5–50)
Use this table when you work by hand or want to check software output. How to read it: find the row for n, the number of pairs with a non-zero difference. The result is significant if T = min(R+, R−) is less than or equal to the table value. In the example, n = 9 after dropping the zero difference; the two-tailed critical value is 5 at 0.05 and 1 at 0.01. T = 1 is within both, so the difference is significant even at the 1% level (consistent with the exact P = 0.0078). A “—” means that no outcome can be significant at that n, even if every pair moves the same way (as noted in the FAQ, n = 5 cannot reach two-tailed 0.05).
The table comes from the exact distribution without zeros or ties (all 2n sign assignments): the largest T with two-tailed P = 2 × P(T ≤ value) ≤ α. For a one-tailed test, use the one-tailed α shown under each column (half the two-tailed value). Every cell was checked against SciPy’s exact P. With ties, as in this example, the table is a guide only. With many ties or zeros, or n above 50, use the normal approximation (R+ has mean n(n + 1)/4 and variance n(n + 1)(2n + 1)/24; with ties, subtract Σ(t³ − t)/48 from the variance) or software. The free calculator picks the exact P or the normal approximation automatically when you choose “Wilcoxon”.
| n (pairs) | Two-tailed 0.1 one-tailed 0.05 | Two-tailed 0.05 one-tailed 0.025 | Two-tailed 0.02 one-tailed 0.01 | Two-tailed 0.01 one-tailed 0.005 |
|---|---|---|---|---|
| 5 | 0 | — | — | — |
| 6 | 2 | 0 | — | — |
| 7 | 3 | 2 | 0 | — |
| 8 | 5 | 3 | 1 | 0 |
| 9 | 8 | 5 | 3 | 1 |
| 10 | 10 | 8 | 5 | 3 |
| 11 | 13 | 10 | 7 | 5 |
| 12 | 17 | 13 | 9 | 7 |
| 13 | 21 | 17 | 12 | 9 |
| 14 | 25 | 21 | 15 | 12 |
| 15 | 30 | 25 | 19 | 15 |
| 16 | 35 | 29 | 23 | 19 |
| 17 | 41 | 34 | 27 | 23 |
| 18 | 47 | 40 | 32 | 27 |
| 19 | 53 | 46 | 37 | 32 |
| 20 | 60 | 52 | 43 | 37 |
| 21 | 67 | 58 | 49 | 42 |
| 22 | 75 | 65 | 55 | 48 |
| 23 | 83 | 73 | 62 | 54 |
| 24 | 91 | 81 | 69 | 61 |
| 25 | 100 | 89 | 76 | 68 |
| 26 | 110 | 98 | 84 | 75 |
| 27 | 119 | 107 | 92 | 83 |
| 28 | 130 | 116 | 101 | 91 |
| 29 | 140 | 126 | 110 | 100 |
| 30 | 151 | 137 | 120 | 109 |
| 31 | 163 | 147 | 130 | 118 |
| 32 | 175 | 159 | 140 | 128 |
| 33 | 187 | 170 | 151 | 138 |
| 34 | 200 | 182 | 162 | 148 |
| 35 | 213 | 195 | 173 | 159 |
| 36 | 227 | 208 | 185 | 171 |
| 37 | 241 | 221 | 198 | 182 |
| 38 | 256 | 235 | 211 | 194 |
| 39 | 271 | 249 | 224 | 207 |
| 40 | 286 | 264 | 238 | 220 |
| 41 | 302 | 279 | 252 | 233 |
| 42 | 319 | 294 | 266 | 247 |
| 43 | 336 | 310 | 281 | 261 |
| 44 | 353 | 327 | 296 | 276 |
| 45 | 371 | 343 | 312 | 291 |
| 46 | 389 | 361 | 328 | 307 |
| 47 | 407 | 378 | 345 | 322 |
| 48 | 426 | 396 | 362 | 339 |
| 49 | 446 | 415 | 379 | 355 |
| 50 | 466 | 434 | 397 | 373 |
Effect size and how to report it
Use the matched-pairs rank-biserial correlation r = (R+ − R−)/(R+ + R−) (0.96 here). It runs from −1 to 1; ±1 means every pair changed in the same direction.
Methods: “Values before and after treatment were compared using a two-tailed Wilcoxon signed-rank test.” Results: give the median difference with the statistic and P, e.g. “Systolic blood pressure decreased after treatment (median difference 7 mmHg; W = 1, P = 0.008, r = 0.96, n = 10).” If there were zero differences, say how they were handled. For general formats see how to report statistics.
FAQ
Is it the same as the Wilcoxon rank-sum test?
No. The rank-sum test (= Mann–Whitney U test) is for two independent groups; the signed-rank test is for paired data. In a paper, write “Wilcoxon signed-rank test” or “Wilcoxon matched-pairs signed-rank test” so readers know which one.
What if many pairs have a zero difference?
Wilcoxon’s original method drops them, so the effective number of pairs shrinks and power falls. Check that the measurement resolution is not too coarse, or consider Pratt’s method (zeros are ranked) or the sign test (only counts increases vs decreases). State the method in the Methods.
How many pairs do I need?
With 5 non-zero differences, even if all go the same way the two-sided P is 2/32 = 0.0625, so it cannot reach 0.05. With 6, the smallest P is 0.031. Pairs with zero difference do not count.
How do I read a Wilcoxon signed-rank table?
Find the row for n, the number of pairs with a non-zero difference. If T = min(R+, R−) is less than or equal to the table value, the result is significant. The table on this page covers n = 5–50 at two-tailed 0.10, 0.05, 0.02 and 0.01 (one-tailed 0.05, 0.025, 0.01, 0.005), computed from the exact distribution without zeros or ties, and is available as a printable PDF.
Should I log-transform before the test?
The signed-rank test ranks the size of the differences, so log-transforming can change the ranks and the result (unlike Mann–Whitney or Friedman, which are unchanged). If the effect is multiplicative, test the differences of logs and say so.
Related guides
Product and journal names are trademarks or registered trademarks of their respective owners.