WILCOXON SIGNED-RANK TEST CALCULATOR

Wilcoxon signed-rank test calculator

Paste paired samples, get the ranks, W+ and W− and the p-value.

Separate numbers with commas, spaces or new lines. Differences are sample 1 − sample 2, as in R and SciPy.

What does the Wilcoxon signed-rank test do?

It tests whether the differences within pairs (or the distances of one sample from a hypothesised median) are centred on zero, without assuming a normal distribution. Each difference is dropped into a ranking by its size alone, ignoring the sign; the ranks are then added up separately for the positive differences (W+) and the negative ones (W−). If the null hypothesis is true, the two sums should be about equal. In R’s wilcox.test the statistic V is W+, and the null hypothesis is that the differences are symmetric about the hypothesised value. It is the rank-based counterpart of the paired t-test and the one-sample t-test.

Worked example: depression scores before and after a tranquilizer

R’s documentation for wilcox.test uses data from Hollander and Wolfe (1973): Hamilton depression scores of nine patients at a first visit, 1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30, and at a second visit after treatment began, 0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29. The first-minus-second differences are 0.952, −0.147, 1.022, 0.43, 0.62, 0.59, 0.49, −0.08 and 0.01. Ranked by size they are 8, 3, 9, 4, 7, 6, 5, 2 and 1, so W+ = 40 and W− = 5. Of the 2⁹ = 512 equally likely sign patterns, 10 give W− of 5 or less, so the one-sided exact p-value that scores fell is 10 ÷ 512 = 0.01953 (R’s documentation shows the call but not its printed result; this number follows from the count). The two-sided p-value is 0.0391.

When is the p-value exact and when is it a normal approximation?

The exact p-value comes from all 2ⁿ ways of attaching plus and minus signs to the observed ranks, so it stays valid with tied differences and zeros. This calculator uses it when there are fewer than 50 differences (R’s rule, “less than 50 finite values”), otherwise the normal approximation z = (W+ − n(n + 1) ÷ 4 − c) ÷ SD, where SD² = n(n + 1)(2n + 1) ÷ 24 − Σ(t³ − t) ÷ 48 with no zero differences, t is the size of each group of tied differences, and c is the continuity correction of 0.5 towards the mean, which R applies and SciPy leaves off by default. R before version 4.6.0 and SciPy (beyond 13 differences) use the approximation when there are ties or zeros, so choose “Normal approximation” to reproduce them. SciPy’s documentation example, Darwin’s corn-plant height differences 6, 8, 14, 16, 23, 24, 28, 29, 41, −48, 49, 56, 60, −67, 75, gives W− = 24 with an exact two-sided p-value of 0.04126 and a normal-approximation p-value of 0.04089 (no continuity correction).

What happens to zero differences?

There are two conventions. Wilcoxon (1945) discards pairs with zero difference before ranking, which is the SciPy default and what R did before version 4.6.0. Pratt (1959) ranks them together with the other differences, then drops the ranks that belong to the zeros, which is a more conservative rule and the one R 4.6.0 and later follow; the normal approximation is adjusted for it (Cureton, 1967). The calculator offers both. Wikipedia’s example of 10 pairs has one pair with no difference, leaving nine non-zero differences with W+ = 27 and W− = 18. For those data the calculator’s two-sided exact p-value is 0.633 when the zero is dropped and 0.645 under Pratt’s rule.

What effect size should I report?

The matched-pairs rank-biserial correlation, r = (W+ − W−) ÷ (W+ + W−), which runs from −1 to +1 and is the difference between the proportion of rank sum favouring positive differences and the proportion favouring negative ones (Kerby, 2014). In the depression example r = (40 − 5) ÷ 45 = 0.78; for Darwin’s corn data r = (96 − 24) ÷ 120 = 0.60; in the Wikipedia example r = (27 − 18) ÷ 45 = 0.20. Report it together with the median of the differences, and with the p-value.

Wilcoxon signed-rank test or paired t-test?

The paired t-test compares the mean of the differences and works best when they are roughly normal. The signed-rank test is the safer choice with small samples, outliers or ordinal scores, because large differences count only through their rank. It still assumes that the pairs are independent and that the differences are distributed symmetrically about their centre. For two separate groups use the Mann–Whitney U test instead, and for a single sample against a target mean with roughly normal data use the one-sample t-test.

Sources: F. Wilcoxon, “Individual comparisons by ranking methods,” Biometrics Bulletin 1 (1945) 80–83; J. W. Pratt, “Remarks on zeros and ties in the Wilcoxon signed rank procedures,” Journal of the American Statistical Association 54 (1959) 655–667; E. E. Cureton, JASA 62 (1967) 1068–1069; M. Hollander and D. A. Wolfe, Nonparametric Statistical Methods (1973); documentation of R 4.6 (stats::wilcox.test and its NEWS) and SciPy 1.18 (scipy.stats.wilcoxon); Wikipedia, “Wilcoxon signed-rank test”; D. S. Kerby, “The simple difference formula,” Comprehensive Psychology 3 (2014). Related: paired t-test calculator, one-sample t-test calculator, Mann–Whitney U test calculator and p-value calculator.