CalculatorsToolsGuides 日本語
BenchFig › Guides › How to do a Wilcoxon signed-rank test (paired data)
Statistics

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.

Updated: BenchFig日本語

When to use it

Key points
  • 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

  1. Compute the difference for each pair (before − after, etc.)
  2. Drop pairs with a zero difference (Wilcoxon’s original method; Pratt’s method is explained below)
  3. Rank the absolute differences from smallest (ties get the average rank)
  4. Sum the ranks of positive differences (R+) and of negative differences (R−)
  5. 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.

AnimalBeforeAfterDifference (before − after)Rank of |difference|Signed rank
1142131+116.5+6.5
2155148+74+4
31381380(dropped)—
4160149+116.5+6.5
5149145+42+2
6151139+128.5+8.5
7147150−31−1
8158146+128.5+8.5
9144137+74+4
10153146+74+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 approximationP = 0.010
Effect size (matched-pairs rank-biserial r)r = 0.96
For comparison: paired t testt(9) = 4.17, P = 0.0024
130135140145150155160BeforeAfterSystolic BP (mmHg)
Before and after values joined for each animal (made up, n = 10). Blue = decreased, orange = increased, gray dashed = no change (difference 0). For paired data, lines per subject say more than group means.

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

MethodWhat it doesThis example
Wilcoxon (SciPy default, BenchFig)Drop zero differences, then rankW = 1, P = 0.0078
PrattRank including zeros, then leave the zeros’ ranks out of the sumsW = 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.

SoftwareStatistic shownThis example
SciPy (scipy.stats.wilcoxon, two-sided)W = min(R+, R−)1
BenchFigW = min(R+, R−) (same as SciPy), plus R+ and R−1
GraphPad PrismSum 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 = number of non-zero differences. Significant if the observed T = min(R+, R−) is less than or equal to this value. — = cannot be significant at this n.
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
50———
620——
7320—
85310
98531
1010853
11131075
12171397
132117129
1425211512
1530251915
1635292319
1741342723
1847403227
1953463732
2060524337
2167584942
2275655548
2383736254
2491816961
25100897668
26110988475
271191079283
2813011610191
29140126110100
30151137120109
31163147130118
32175159140128
33187170151138
34200182162148
35213195173159
36227208185171
37241221198182
38256235211194
39271249224207
40286264238220
41302279252233
42319294266247
43336310281261
44353327296276
45371343312291
46389361328307
47407378345322
48426396362339
49446415379355
50466434397373
Run a Wilcoxon signed-rank test in the free calculatorPaste the before and after columns: W, R+, R−, P (exact or normal approximation), effect size and a results sentenceCalculate →
Match a two-group sample and run the signed-rank testChoose “Match by row” and Nonparametric to get the Wilcoxon signed-rank test with W, R+, R−, the effect size and a ready-to-paste sentence.
Open for free →

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.

Try a signed-rank test on sample dataOpen a two-group sample on the Graph screen, set Matching to “Match by row” and Test type to Nonparametric to see W, R+, R−, how P was computed and the effect size.
Open for free →
Your own data, all the way to the final figure.Loading your files, saving, and journal-ready export (PDF, TIFF, PNG, SVG) are in BenchFig Pro for Windows, updated based on researchers’ requests: ¥3,980/year (2 PCs), with lab and perpetual licenses too.
About the app →

Related guides

Product and journal names are trademarks or registered trademarks of their respective owners.