Probability & Statistics

Wilcoxon Signed-Rank Test

Rank paired differences and enumerate sign assignments, including zero removal and tied absolute ranks.

By Riano · Published · Updated · Report a correction

Wilcoxon Signed-Rank Test

The Wilcoxon Signed-Rank Test examines whether independent paired differences have a distribution symmetric about zero. Symmetry is an essential assumption; the statistic is not a general test of a median alone. Under the null hypothesis that the paired differences follow a symmetric distribution around zero, the signs of the differences are equally likely to be positive or negative. The exact conditional sign-randomization distribution enumerates all possible sign assignments, calculating the resulting test statistics, rather than using an asymptotic approximation.

Worked Example

Consider the paired differences below. All five are nonzero.

{ 1, 2, -3, 4, 5 }

First, we sort the absolute differences: 1, 2, 3, 4, 5. Since there are no ties, their ranks are simply 1, 2, 3, 4, and 5. The positive differences are 1, 2, 4, and 5, corresponding to ranks 1, 2, 4, and 5. The negative difference is -3, corresponding to rank 3.

  1. The sum of positive ranks is W+ = 1 + 2 + 4 + 5 = 12.
  2. The sum of negative ranks is W- = 3.
  3. The test statistic T = min(W+, W-) = min(12, 3) = 3.

Under the symmetry null hypothesis, there are 2^5 = 32 equally likely sign assignments for the 5 absolute ranks. We enumerate all 32 combinations and count how many yield a test statistic T <= 3.

SignsW+W-TT <= 3
- - - - -0150Yes
+ - - - -1141Yes
- + - - -2132Yes
+ + - - -3123Yes
- - + - -3123Yes

The five displayed assignments have positive-rank sums 0, 1, 2, 3, and 3. Their five distinct complementary assignments have positive-rank sums 15, 14, 13, 12, and 12. Together these are exactly 10 assignments with T <= 3 out of 32. Thus, the exact two-sided p-value is 10/32 = 5/16 (0.3125).

Experiment

You can explore different tied and signed configurations in the Wilcoxon Signed-Rank Test module.

  1. Set Difference preset to "Mostly positive". Observe that there are 5 nonzero differences with W+ = 13, W- = 2, and T = 2, giving an exact p-value of 3/16.
  2. Set Difference preset to "Tied positive". There are exactly two nonzero absolute differences: 1 and 1. They are tied for ranks 1 and 2, so they both get rank 1.5. Both are positive, making W+ = 3 and W- = 0, giving T = 0. Out of 2^2 = 4 combinations, 2 yield T=0, so p = 0.5.
  3. Set Difference preset to "All zero". All differences are zero. They are discarded, leaving 0 nonzero differences. The module reports T = 0 and a p-value of 1.

Limitations

The conditional model assumes independent paired differences with a distribution symmetric about zero. Conditional on nonzero magnitudes, all sign assignments are equally likely; continuity is not needed for this declared enumeration. Although the exact conditional sign enumeration properly handles observed zeros and ties without asymptotic assumptions, heavy ties can lead to discrete and highly conservative p-values. Furthermore, zero values are discarded by convention, which reduces the effective sample size and can lead to a p-value of 1 for completely matched data.

References

Below are the primary sources used for the module model and algorithms.

  • SciPy wilcoxon Documentation- Details the exact null distribution based on sign permutation, zero-discard convention, and symmetry assumptions.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Wilcoxon Signed-Rank Test module.

Try Wilcoxon Signed-Rank Test on Riano →

More in Probability & Statistics