Biostatistics · Intermediate

The Wilcoxon Rank-Sum Test

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

The Wilcoxon Rank-Sum Test is a nonparametric alternative to the independent-samples t-test used when data is not normally distributed or is ordinal. It operates by ranking all observations from two independent groups and comparing the sum of ranks to determine if one distribution is shifted relative to the other. The test relies on a normal approximation for samples where both group sizes are at least 10.

Intuition

Imagine you have two groups of patients, such as those with different genetic types of retinitis pigmentosa, and you want to compare their visual acuity. Since visual acuity might be ordinal or not normally distributed, you cannot simply average the scores. Instead, you combine all patients from both groups and rank them from best to worst vision. If the two groups are truly identical, the ranks should be evenly mixed between them. If one group consistently has higher ranks, it suggests that group has better visual acuity. The test statistic measures how far the observed sum of ranks deviates from what we would expect if the groups were identical, allowing us to assess statistical significance.

Key equations

H0:FD=FSLvs.H1:FD(x)=FSL(x+Δ),Δ≠0
(1)

Null hypothesis that cumulative distribution functions are equal; alternative that they differ by a location shift Δ.

E(R1)=n1(n1+n2+1)2
(2)

Expected rank sum for the first group under the null hypothesis.

Var(R1)=n1n2(n1+n2+1)12
(3)

Variance of the rank sum under the null hypothesis when there are no tied values.

T=R1−n1(n1+n2+1)2n1n2(n1+n2+1)12−∑i=1gti(ti2−1)12(n1+n2)(n1+n2−1)
(4)

Test statistic T when ties are present, where t_i is the number of observations in the i-th tied group and g is the number of tied groups.

p=2×[1−Φ(T)]
(5)

Calculation of the two-sided p-value using the standard normal cumulative distribution function Φ.

Derivation

  1. Combine the data from two independent samples of sizes n_1 and n_2.
  2. Rank all N = n_1 + n_2 observations from lowest to highest.
  3. Handle ties by assigning the average rank to each observation in a tied group.
  4. Calculate the rank sum R_1 for the first group.
  5. Determine the expected rank sum E(R_1) under the null hypothesis.
  6. Calculate the variance Var(R_1), applying a correction factor if ties are present.
  7. Compute the test statistic T using the normal approximation.
  8. Reject the null hypothesis if T exceeds the critical value z1−α/2.

Worked example

Problem

Compare visual acuity between two genetic types of retinitis pigmentosa. Group 1 has n_1=10 patients and Group 2 has n_2=10 patients. The sum of ranks for Group 1 is R_1=130. There are no ties. Is there a significant difference at α=0.05?

  1. Calculate expected rank sum: E(R_1) = 10(10+10+1)/2 = 105.
  2. Calculate variance: Var(R_1) = 10*10*(21)/12 = 175.
  3. Calculate standard deviation: 175≈13.23.
  4. Calculate T: (130 - 105) / 13.23 ≈ 1.89.
  5. Compare T to z_{0.975} ≈ 1.96. Since 1.89 < 1.96, we do not reject H_0.

Answer T ≈ 1.89; Fail to reject H_0.

Common mistakes

  • Using the test when sample sizes are less than 10, as the normal approximation may not be valid.
  • Ignoring ties when calculating the variance, which leads to an incorrect test statistic.
  • Confusing the Wilcoxon Rank-Sum Test (for independent samples) with the Wilcoxon Signed-Rank Test (for paired samples).
  • Assuming the test requires the data to be normally distributed, which is contrary to its purpose.

Animation

Animation coming soon

The animated version of this lesson is being prepared for the web. In the Signals AI app, lessons are drawn step by step.

Code

This is a text lesson: it has no animation code yet.

ccBYNC© 2026 SignalsLab. Lesson text shared as is under CC BY-NC 4.0.