The Wilcoxon Signed-Rank Test, Explained

After reading this you can run the Wilcoxon signed-rank test on paired data by hand, check the output of the calculator, and know when to use it instead of a paired t-test.

What the test does

The Wilcoxon signed-rank test compares two measurements taken on the same subjects, such as a reading before a treatment and a reading after. It asks whether the paired differences are centered at zero, without assuming those differences follow a normal distribution.

Suppose you measure blood pressure on six patients before and after a change in diet. If the diet does nothing, the increases and decreases should roughly balance, and the differences that are largest in size should be split between positive and negative. The Wilcoxon test formalizes that idea. It ranks the differences by their absolute size, then checks whether the large ranks pile up on one side.

Because the test works on ranks rather than raw values, one extreme difference cannot dominate the result. A single difference of +80 counts as the largest rank, whether it is 80 or 800.

When to use it, and when not to

Use this test when you have paired numeric data and you doubt that the differences are normally distributed. Common cases are small samples, skewed differences, or measurements on an ordinal scale where distances between values are not meaningful.

Paired data
Each value in sample A has a natural partner in sample B: the same person, the same machine, the same matched pair.
Symmetry assumption
The test assumes the distribution of differences is symmetric about its median. If it is badly skewed, the test targets the median location but its power drops.

Do not use it for independent groups. If sample A and sample B come from different subjects with no pairing, use the Mann-Whitney U test instead. For three or more related conditions, look beyond this test. If your differences are close to normal, the paired t-test is slightly more powerful, so it is worth checking with the normality test battery first.

For paired binary outcomes (a yes/no result before and after), the signed-rank test is the wrong tool. Use McNemar's test, which is built for that 2x2 case.

The math and the intuition

Start by computing each difference d_i = b_i - a_i. Drop any difference equal to zero, because a tie of exactly zero carries no direction. Let n be the number of nonzero differences.

Rank the absolute values |d_i| from smallest (rank 1) to largest (rank n). Tied absolute values share the average of the ranks they would occupy. Then attach the sign of each difference back to its rank, and add up the ranks on each side.

W^+ = \sum_{d_i \gt 0} R_i, \quad W^- = \sum_{d_i \lt 0} R_i

Here R_i is the rank of |d_i|. The test statistic W is usually the smaller of W^+ and W^-. The two sums always add to the total of all ranks:

W^+ + W^- = \frac{n(n+1)}{2}

If the null hypothesis is true, the positive and negative ranks balance, so W^+ and W^- land near half of that total. A small W means one side is starved of large ranks, which is evidence against the null.

For larger samples you can standardize. Under the null hypothesis, W^+ has mean and standard deviation:

\mu_W = \frac{n(n+1)}{4}, \quad \sigma_W = \sqrt{\frac{n(n+1)(2n+1)}{24}}
z = \frac{W^+ - \mu_W}{\sigma_W}

The z value then feeds a normal approximation for the p-value. For n below about 20, prefer the exact distribution rather than this approximation, because the normal curve is a poor fit for so few ranks.

A worked example with the demo data

Six paired readings

The demo button loads before values a = 140, 155, 160, 138, 145, 150 and after values b = 135, 148, 158, 136, 140, 147. Work through it step by step.

  1. Compute differences d = b - a: -5, -7, -2, -2, -5, -3.
  2. No difference is zero, so n = 6. Take absolute values: 5, 7, 2, 2, 5, 3.
  3. Rank the absolute values. The two 2s tie for positions 1 and 2, so both get rank 1.5. The 3 gets rank 3. The two 5s tie for positions 4 and 5, so both get rank 4.5. The 7 gets rank 6.
  4. Every difference is negative, so W^+ = 0 and W^- = 1.5 + 6 + 1.5 + 4.5 + 3 + 4.5 = 21.
  5. Check the total: W^+ + W^- = 0 + 21 = 21 = \frac{6 \cdot 7}{2}. It matches.
  6. The test statistic is the smaller sum, W = 0.

Every patient dropped, and the ranks all sit on the negative side. For n = 6 the smallest possible two-sided p-value is 2/64 = 0.03125, reached exactly when W = 0. So the calculator reports p = 0.03125, and you reject the null of zero median difference at the 5% level.

All six signed ranks are negative, so the negative sum W^- collects the full rank total of 21.

Explore how one flipped sign changes the result

With all six demo differences negative, W^+ = 0 and the two-sided p-value is 0.03125. If you flip the sign of the largest difference (the 7, rank 6) to positive, then W^+ = 6 and W^- = 15, giving W = 6 and a two-sided exact p-value of about 0.219. One large rank crossing sides is enough to erase significance.

Reading and interpreting the output

The calculator returns W, the two rank sums, and a p-value. Read them together.

A p-value below your chosen threshold (0.05 is common) says the paired differences are unlikely to be centered at zero. It does not tell you the size of the shift. Report the median difference alongside the p-value. In the demo the differences are -5, -7, -2, -2, -5, -3, so the median difference is -4, a drop of about 4 units.

Watch the direction. Because W is the smaller sum, it hides which sample was larger. Look at W^+ versus W^-: here W^- = 21 dominates, confirming that after values are lower than before values.

How the statistic maps to evidence for n = 6, two-sided
WTwo-sided p-valueReading at 5%
00.03125Reject
20.09375Do not reject
40.1563Do not reject
60.2188Do not reject

Common mistakes

Dropping zero differences shrinks n, which weakens the test. If four of ten pairs show no change, you run the test on six values, not ten. Note the discarded pairs when you report results.

Ties in the absolute differences need average ranks, not sequential ranks. In the demo the two 2s each got rank 1.5, not 1 and 2. Getting this wrong changes the rank sums.

With many ties, the exact distribution no longer applies cleanly. Software then uses the normal approximation with a tie correction that shrinks \sigma_W. Check whether the calculator reports an exact or approximate p-value for your data.

A significant Wilcoxon result is not proof that the medians differ in every sense. The test is sensitive to any asymmetry in the differences. If the distribution of differences is strongly skewed, treat the result as a statement about the general shift, not a precise median comparison.

Related tools

If your differences look roughly normal, compare with the t-test calculator, which uses the raw values. For unpaired groups, the Mann-Whitney U test is the matching rank test, and the Kruskal-Wallis H test extends it to three or more groups. To turn a standardized statistic into a probability, use the p-value calculator. Before choosing between rank and parametric methods, the normality test battery gives you a quick read on the differences.

Frequently asked questions

What is the null hypothesis of the Wilcoxon signed-rank test?

The median of the paired differences is zero, meaning the two conditions do not shift the values in a consistent direction. Rejecting it says the differences lean one way.

Why use it instead of a paired t-test?

The t-test assumes the differences are normally distributed. When they are skewed, ordinal, or contain outliers, the rank-based Wilcoxon test is more reliable. With normal differences the t-test is a little more powerful, so the choice depends on your data.

What do I do with differences equal to zero?

Remove them before ranking, and reduce n accordingly. A zero has no sign and no direction, so it cannot contribute to either rank sum.

How small a sample can I use?

The test runs on as few as five or six pairs, but the smallest reachable two-sided p-value grows as the sample shrinks. With n = 5 the minimum is 0.0625, so you cannot reach 0.05 no matter how one-sided the data is.

Is the test one-sided or two-sided?

Both are possible. A two-sided test asks whether the differences shift in either direction. A one-sided test asks about a specific direction and roughly halves the p-value when the data point that way.