Wilcoxon Signed-Rank Calculator

Signed ranks, exact p-values and the Hodges-Lehmann shift.

  • Exact up to n = 150
  • Ties and zeros handled
  • Hodges-Lehmann shift
A small rounded clay table with two rows of soft clay beads graded from small to large, joined by soft clay arches, with a small clay see-saw tilting down on one side.

The guide

The signed-rank test ranks the sizes of the differences, and its zero and tie rules decide the p-value

A paired test that uses the order of the differences, counts every sign pattern when the sample is small, and means little until you say how zeros and ties were handled.

  • 27 and 18 T+ and T- for the ten-pair example, so W = 9
  • 81/128 exact two-sided p for those ten pairs, 0.6328
  • 0.5936 normal approximation for the same pairs, no correction
  • 7.5 not 7 T+ for 3, -3, 1, 5, -7 with midranks, not an input-order break
  • 7/2 Hodges-Lehmann shift from 45 Walsh averages
Read the full guide Fold the guide 8 min · 13 sources

Ten subjects, each measured twice. The question is whether the changes lean one way. A paired difference test starts by turning each pair into one number, the difference, and then asks about those differences. The paired t test and the Wilcoxon signed-rank test are both methods of that kind. The sign test is a third, and it keeps only the direction of each change. It makes very few assumptions, which is its strength, and it may lack the power of the alternatives, which is its price.

What the test asks that a sign test and a t test do not

The signed-rank test keeps the direction and adds the size order. Take the absolute differences and rank them from 1, smallest first. T+ is the sum of the ranks of the positive differences, T- is the sum for the negative ones, and together they equal n (n + 1) / 2 when n values are ranked. W, the signed-rank sum, is T+ minus T-.

Ranks are why one wild value cannot take over. A difference of 20 and a difference of 2,000 both become the last place in line. A t test listens to every value at full size, so it can be dragged. The signed-rank test hears only who came first, second and third, which makes it steadier and a little blunter.

What does it test? Whether the differences come from a symmetric population centred on a stated value, usually zero. That symmetry is a real assumption, not a courtesy. A skewed set of differences can give a small p-value without any shift of the centre. A neighbour with a similar name is for another job: the rank-sum test, also called Mann-Whitney, compares two independent samples. Here every x belongs with one y.

A worked example: ten pairs, one zero, one tie

The page opens on ten pairs, x then y: (125, 110), (115, 122), (130, 125), (140, 120), (140, 140), (115, 124), (140, 123), (125, 137), (140, 135), (135, 145). Subtract y from x and you get 15, -7, 5, 20, 0, -9, 17, -12, 5, -10. One difference is exactly zero. Two are tied in absolute value, both 5.

Drop the zero and nine values remain, with absolute sizes 5, 5, 7, 9, 10, 12, 15, 17, 20. The two 5s would hold positions 1 and 2, so each gets rank 1.5. The positive differences 15, 5, 20, 17 and 5 take ranks 7, 1.5, 9, 8 and 1.5, which sum to 27. The negative ones, -7, -9, -12 and -10, take ranks 3, 4, 6 and 5 and sum to 18. So T+ and T- come to 27 and 18. Check: 27 plus 18 is 45, and 9 times 10 divided by 2 is 45. W is 9.

Is 27 unusual? Nine non-zero differences give 2 to the power 9, or 512 sign patterns, all equally likely if nothing shifts. Of those, 162 give T+ of 27 or more, so the smaller tail is 81/256 and the two-sided p-value, twice that, is 81/128, or 0.6328.

The normal approximation says something close. The mean of T+ is 45/2, the variance is 71.125 (the plain 71.25 minus a small amount for the tie), so the standard deviation is 8.4335 and z is 0.5336. The two-sided p-value is 0.5936, or 0.6353 with a continuity correction of one half. No reading of these ten pairs is anywhere near significant.

Why midranks, and why zeros need a rule

Ties break the plain recipe, because ranks are no longer unique. The common answer, and the one Wilcoxon recommended, gives tied values the average of the ranks they would have had. The Ranking page notes a useful property of this fractional ranking: the sum of the ranks is the same as under ordinary ranking, so T+ plus T- still adds up to the same total.

Breaking ties by the order you typed the data feels harmless, and it is not. Take the differences 3, -3, 1, 5, -7. With midranks, the two values of absolute size 3 share rank 2.5, so T+ is 7.5, not 7, and T- is 7.5 too, a perfect balance. Give rank 2 to the first 3 and rank 3 to the -3 because that is the order they appeared in, and T+ becomes 7 and T- becomes 8. Type them the other way round and the result flips. A statistic that depends on typing order is not a statistic.

Zeros are a different kind of trouble. A zero has no sign, so it cannot add to T+ or T-. Wilcoxon’s later advice was to remove zeros, the reduced sample procedure. Pratt noticed that this can behave oddly and proposed ranking the zeros with everything else, then leaving them out of the sums.

The size of the effect is easy to see. Pratt’s example has thirteen observations: 0, 2, 3, 4, 6, 7, 8, 9, 11, 14, 15, 17 and -18. Dropping the zero leaves ranks 1 to 12 with the last one negative, T- is 12, and the exact one-sided p-value is 70/4096, or 0.0171. Ranking the zero and leaving it out of the sums gives T- of 13 and a p-value of 49/4096, or 0.0120. Shrink the zero a little below zero and the signed ranks become -1, 2 to 12 and -13, which gives 109/8192, or 0.0133.

On the ten pairs the Pratt rule moves T+ to 32 and T- to 22, the exact two-sided p-value to 165/256, or 0.6445, and the normal approximation to 0.6096. One input, two defensible rules, different numbers. A result without the rule beside it cannot be checked.

Counting every sign pattern

Under the null hypothesis each non-zero difference is as likely to be negative as positive. For n of them that is 2 to the power n equally likely sign patterns, and the exact p-value is just a count. Listing them all is hopeless beyond small n, but a recursion does the job: the number of patterns giving T+ of t equals the number for the first n - 1 ranks with T+ of t, plus the number with T+ of t - n. Each rank either sits among the positives or it does not.

The page runs that same recursion on doubled midranks, which are whole numbers, so a tie never causes rounding. When ties or zeros are present the counted distribution is the one belonging to the actual midranks of this data. That makes it a conditional exact test, and the page says so beside the number. The counts live in BigInt, because 2 to the power 150 is about 1.4 times 10 to the power 45, far past the 9,007,199,254,740,991 that an ordinary number holds exactly. Anything past 40 differences is counted in a worker so the page stays responsive.

For large samples a normal curve takes over. The mean of T+ is n (n + 1) / 4 and the variance is n (n + 1) (2n + 1) / 24. Ties lower the variance by the sum of (t cubed minus t) over each tied group of non-zero values, divided by 48, and zeros under the Pratt rule change the mean and variance again. Those corrections were checked here against the exact variance of the full enumeration, for every case tested.

How good is the curve for a small sample? Take eight differences: 1.2, -0.4, 2.6, 3.1, 0.8, -1.9, 4.4 and 2.2. T+ is 31 and T- is 5. The exact two-sided p-value is 5/64, or 0.0781. The normal approximation says 0.0687, about 12 percent too small, and on the wrong side of a line that someone may be waiting to cross.

Software defaults add their own wrinkle. SciPy discards zeros unless told otherwise. Its automatic mode uses the exact method up to 50 values when nothing is tied or zero, and for ties and zeros it enumerates permutations up to 13 values, then switches to the asymptotic method. That is why it reproduces 0.6328 for the ten pairs. Ask for the exact method by name and it returns 0.6523, because that path does not model the ties.

A published number that would not reproduce, and the shift estimate

The Wikipedia page for this test works the same ten pairs and quotes a p-value of 0.6113. Here, neither the exact count (0.6328) nor the asymptotic value (0.5936) gives it, nor does the Pratt rule (0.6096), splitting the zero rank (0.6101) or the continuity correction (0.6353). Its W of 9 and its ranks do reproduce. Its table also prints one difference as -5 where the pair 130 and 125 gives +5.

The same page prints 55/2 to the power 12 for the first Pratt example, which is the count for T- of 11 or less. For T- of 12 the count is 70. The lesson is not about one page. A lone p-value, without its zero rule, tie rule, tail and method, is a number you cannot check, so this calculator prints those four things beside every figure.

Now the shift. A Walsh average is half the sum of two observations, and the Hodges-Lehmann estimate is the median of all n (n + 1) / 2 of them, taken over pairs with i at most j. The self-pairs belong in the list, a detail the source page says many secondary sources omit. For the nine non-zero differences there are 45 averages and their median is 7/2, or 3.5. T+ equals the number of positive Walsh averages, and here 27 of the 45 are positive.

What does 3.5 estimate? The pseudomedian: the median of the average of two independent draws from the population. For a symmetric population it equals the median. It is also robust, with a breakdown point of 0.29, meaning it stays bounded even when nearly 30 percent of the data are contaminated. Two thousand differences make 2,001,000 averages, so that sort runs in a worker too.

It does not test two independent samples, give power, or produce a confidence interval for the shift. It assumes independent pairs on a scale where differences can be ordered, and symmetry about the centre. A small p-value says the signs and ranks are lopsided, not what caused it.

To reproduce the example, paste 125 115 130 140 140 115 140 125 140 135 into the x box and 110 122 125 120 140 124 123 137 135 145 into the y box. You should see T+ of 27, T- of 18, an exact p of 81/128 and a normal p of 0.5936. Every figure was also checked outside the page with Python’s exact fractions, a brute-force pass over sign patterns, and SciPy where its method applies.

Sources

Every source consulted for this guide. Links checked November 10, 2026.

  1. Wilcoxon signed-rank test Wikipedia
  2. Hodges-Lehmann estimator Wikipedia
  3. Pseudomedian Wikipedia
  4. Sign test Wikipedia
  5. Paired difference test Wikipedia
  6. Ranking Wikipedia
  7. Permutation test Wikipedia
  8. Mann-Whitney U test Wikipedia
  9. scipy.stats.wilcoxon SciPy documentation
  10. DLMF: 7.2 Definitions NIST Digital Library of Mathematical Functions
  11. BigInt MDN Web Docs
  12. Web Workers API MDN Web Docs
  13. fractions - Rational numbers Python Software Foundation