Tutorials › Introduction to Statistics › The Wilcoxon Signed-Rank Test for Paired Data

Nonparametric Alternatives · Tutorial 953 of 996

The Wilcoxon Signed-Rank Test for Paired Data

Learn to calculate the Wilcoxon signed-rank sums and test statistic from paired differences, and understand what the ranks and signs preserve.

Intermediate 9 min read

What You'll Learn

  • Define paired differences and identify the zero-centered null hypothesis.
  • Rank the absolute nonzero differences from smallest to largest.
  • Restore each difference’s sign after ranking its magnitude.
  • Calculate the positive and negative rank sums and check their total.
  • Form the signed-rank statistic used for directional or two-sided tests.
  • Recognize why symmetry and independent pairs matter for the test’s interpretation.

Why Rank the Paired Differences?

When two measurements are taken on the same person, animal, or other unit, the observations are paired. For example, a measurement might be recorded before and after an intervention. The analysis begins with one difference per unit, calculated in a consistent direction. The Wilcoxon signed-rank test uses both the direction of each difference and the relative size of its magnitude. This distinguishes it from the paired sign test, which uses the directions but not the magnitudes.

The signed-rank calculation is useful when the paired differences are not well described by a normal model but their magnitudes can still be ordered. It does not use the differences in their original measurement units as weights. Instead, it gives larger ranks to larger absolute differences, then attaches each difference’s sign to its rank.

Definition: For paired observations, let \(D_i\) be the difference for pair \(i\), calculated in a stated direction, such as “after minus before.” For each nonzero \(D_i\), rank \(|D_i|\) from smallest to largest. Restore the sign of \(D_i\) to its rank. The positive rank sum, \(W^+\), is the sum of ranks with positive differences; the negative rank sum, \(W^-\), is the sum of ranks with negative differences.

For the basic calculation in this tutorial, assume all paired differences are nonzero and their absolute values are distinct. If there are \(m\) such pairs, the ranks are \(1,2,\ldots,m\). Cases with zero differences or tied absolute differences require adjustments and are treated separately in the course.

Model and Hypotheses

The test concerns the distribution of paired differences. Its usual model assumes that the pairs are independent of one another and that the difference distribution is symmetric about a center. The null hypothesis is that this center is zero. Under the symmetry assumption, this is a test of a zero-centered difference distribution; without symmetry, the signed-rank test should not be casually described as a general test of the median alone.

For instance, a two-sided question asks whether the difference distribution is centered at zero or instead has a nonzero center. A directional alternative asks whether the center is positive or negative, according to the chosen subtraction order. Switching from “after minus before” to “before minus after” reverses every sign, so the direction must be stated before calculating.

Key quantities: If \(m\) differences are nonzero and have distinct absolute values, then \(W^+\) sums the ranks attached to positive differences, \(W^-\) sums those attached to negative differences, and the total rank sum is \(W^+ + W^- = m(m+1)/2\). For a two-sided test, a commonly used signed-rank statistic is \(T=\min(W^+,W^-)\). For a one-sided test, retain the direction in \(W^+\) or \(W^-\), rather than discarding it by taking the minimum.

How to Calculate the Signed Ranks

The calculation has four steps: calculate each paired difference using the stated order; take absolute values; rank the absolute values from smallest to largest; and give each rank the original difference’s sign. The magnitude determines the rank, but it does not determine the sign.

1
Calculate the differences.
Write one difference per pair using a consistent subtraction order, such as \(D_i=\text{after}_i-\text{before}_i\).
2
Rank the absolute differences.
Sort \(|D_i|\) from smallest to largest and assign ranks \(1\) through \(m\), under the no-ties condition used here.
3
Restore the signs.
Attach a plus sign to the rank if \(D_i>0\), and a minus sign if \(D_i<0\).
4
Sum the ranks by sign.
Add positive ranks to obtain \(W^+\) and negative ranks’ magnitudes to obtain \(W^-\). Check that their sum is \(m(m+1)/2\).

Worked Example: Ranking Six Paired Differences

Suppose a hypothetical exercise records change in a measurement as “after minus before” for six independent units. The differences, in measurement units, are \(-2, 5, -1, 8, -4, 3\). Assume the paired-difference model is appropriate and that the absolute differences are distinct and nonzero. Rank the magnitudes and calculate the signed-rank sums.

Difference \(D_i\)Absolute difference \(|D_i|\)RankSigned rank
\(-2\)22\(-2\)
\(5\)55\(+5\)
\(-1\)11\(-1\)
\(8\)86\(+6\)
\(-4\)44\(-4\)
\(3\)33\(+3\)

The positive differences have ranks \(5,6,3\), so \(W^+=5+6+3=14\). The negative differences have ranks \(2,1,4\), so \(W^-=2+1+4=7\). There are \(m=6\) ranks in all, and their total is \(14+7=21\). The two-sided statistic is \(T=\min(14,7)=7\). The calculations show that the negative differences carry a smaller total rank sum in this sample; by themselves, they do not establish a conclusion about statistical significance.

Why the Rank Sum Has a Useful Check

When the assumptions for the basic calculation hold, every rank from 1 through \(m\) appears exactly once. Therefore, the combined positive and negative rank sums must equal the sum of the first \(m\) positive integers:

$$ W^+ + W^- = 1+2+\cdots+m=\frac{m(m+1)}{2}. $$

Here is a justification of the final equality that covers both even and odd \(m\). If \(m\) is even, pair the first and last terms: \(1+m\), \(2+(m-1)\), and so on. There are \(m/2\) pairs, each summing to \(m+1\), so the total is \(\frac{m}{2}(m+1)=\frac{m(m+1)}{2}\). If \(m\) is odd, there are \((m-1)/2\) such pairs, each summing to \(m+1\), and the unpaired middle term is \((m+1)/2\). Thus the sum is \(\frac{m-1}{2}(m+1)+\frac{m+1}{2}=\frac{m(m+1)}{2}\).

This identity is a calculation check, not a p-value or a test conclusion. If the two signed sums fail to add to the required total, a rank may have been omitted, counted twice, or assigned to the wrong sign.

Worked Example: A Directional Signed-Rank Calculation

In a hypothetical paired exercise, five independent units have differences, calculated as “after minus before,” of \(2,-3,5,7,-9\) measurement units. Assume all magnitudes are distinct and nonzero and the symmetric difference model is appropriate. Calculate the sums and identify the directional quantity relevant to a positive-center alternative.

The absolute differences are \(2,3,5,7,9\), so their ranks are \(1,2,3,4,5\), respectively. Restoring the original signs gives signed ranks \(+1,-2,+3,+4,-5\). Therefore,

$$ W^+=1+3+4=8,\qquad W^-=2+5=7. $$

The check is \(W^++W^-=8+7=15\), which agrees with \(m(m+1)/2=5(6)/2=15\). For a positive-center alternative under this subtraction order, \(W^+\) is the relevant directional sum: positive differences contribute to it. The value \(T=\min(8,7)=7\) is the two-sided version, not the directional sum to use for that positive alternative.

What the Statistic Keeps—and What It Discards

The signed-rank procedure uses the signs and the ordering of the absolute differences. In contrast, it does not preserve the exact spacing between magnitudes. For example, a difference of 10 units is not treated as five times as influential as a difference of 2 units. It receives a higher rank if its absolute value is larger, but the difference between the two ranks is only the difference in their positions in the ordering.

This is why the procedure is called rank-based. It can be less sensitive to unusually large differences than a procedure based directly on their numerical values, while still using more information than the sign test. That benefit comes with a modeling requirement: the difference distribution should be symmetric about the center being tested if the result is to be interpreted as evidence about that center.

Worked Example: Balanced Positive and Negative Rank Sums

A hypothetical paired exercise gives eight independent differences, in “after minus before” order: \(-0.4, 1.1, -1.8, 2.6, 3.7, -5.2, 6.4, -8.9\) units. Assume distinct nonzero magnitudes and the symmetric difference model. Find both rank sums and the two-sided statistic.

In increasing order, the absolute differences are \(0.4,1.1,1.8,2.6,3.7,5.2,6.4,8.9\), with ranks \(1,2,3,4,5,6,7,8\). Restoring signs yields \(-1,+2,-3,+4,+5,-6,+7,-8\). Hence,

$$ W^+=2+4+5+7=18,\qquad W^-=1+3+6+8=18, \qquad T=\min(18,18)=18. $$

The total is \(18+18=36\), matching \(m(m+1)/2=8(9)/2=36\). Equal rank sums indicate a balance of positive and negative rank weight in this sample. A test’s p-value and formal inference require a reference distribution; the sums alone do not say whether this balance is unusual under the null hypothesis.

From Calculation to Testing

A test uses the signed-rank statistic to compare the observed arrangement of signs and ranks with what would be expected under a zero-centered difference distribution. The exact or approximate reference calculation and p-value are separate steps. Here, the main task is to produce the rank sums accurately and to retain the statistic that matches the alternative hypothesis.

Alternative directionRank sum to retainReason
Positive center\(W^+\)A positive shift tends to place more high ranks among positive differences.
Negative center\(W^-\), or equivalently a small \(W^+\)A negative shift tends to place more high ranks among negative differences.
Nonzero center, either direction\(T=\min(W^+,W^-)\), in the common two-sided conventionA strong imbalance makes the smaller rank sum relatively low.

These descriptions identify which sum represents the observed direction; they are not substitutes for calculating a p-value. A small \(T\), for example, is only interpreted by comparing it with the appropriate null distribution for the sample size and test procedure.

Common Mistakes

  • Ranking signed values instead of absolute values. The ranking step uses \(|D_i|\), so a large negative difference can receive a high rank. Restore its negative sign only after assigning the rank.
  • Adding the original differences. \(W^+\) and \(W^-\) are sums of ranks, not sums of the raw differences. For example, a positive difference of 5 units contributes its rank, not 5, to \(W^+\).
  • Using \(T\) for every alternative. The minimum of the two sums is a common two-sided statistic. For a directional alternative, keep track of which sign matches the direction of interest.
  • Ignoring subtraction order. “After minus before” and “before minus after” reverse all the signs. State the order and interpret positive differences accordingly.
  • Treating a balanced rank sum as proof of no effect. Equality of \(W^+\) and \(W^-\) describes this sample’s rank balance; it is not, by itself, a test result or proof that the center is zero.
Key takeaway: Rank the absolute paired differences, restore their signs, and sum ranks separately to obtain \(W^+\) and \(W^-\). Check that the sums total \(m(m+1)/2\), then choose the directional sum or the two-sided statistic \(T\) to match the stated alternative.

Check Your Understanding

Use the basic procedure, assuming independent pairs and distinct, nonzero absolute differences where needed.

  1. For differences \(-1, 4, -6, 2\), assign signed ranks and calculate \(W^+\), \(W^-\), and \(T\).
  2. Why are the absolute differences ranked before their signs are restored?
  3. If there are seven nonzero differences with distinct magnitudes, what should \(W^++W^-\) equal? Show the formula you use.
  4. For an alternative that the center is positive when differences are “after minus before,” which rank sum retains the direction, and why?
  5. What information does the signed-rank calculation use that the paired sign test does not use?