Frank Wilcoxon introduced the rank-sum test in 1945 as a quick way to compare two treatments without assuming that the measurements are normally distributed. The idea is simple: put all observations from both groups in one list, rank them from smallest to largest and add up the ranks that belong to the first group. If both groups come from the same population, that rank sum W should be close to its expected value n₁(N + 1)/2; a much larger or smaller W suggests that one group tends to have higher values.
The test is mathematically equivalent to the Mann–Whitney U test published two years later – U₁ is just W minus the smallest possible rank sum, n₁(n₁ + 1)/2 – so both give the same p-value. Textbooks in medicine and biology often present the rank-sum form, while economics and psychology texts tend to use U.
Because it uses only the order of the data, the rank-sum test is robust to outliers and works with ordinal measurements such as pain scores. Ties receive average ranks and a correction to the variance. Do not confuse it with the Wilcoxon signed-rank test, which is for paired data.
How to use the Wilcoxon Rank-Sum Test Calculator
- Sample 1 (e.g. treatment)
- Sample 2 (e.g. control)
- Alternative hypothesis
- p-value method
- Continuity correction (normal approximation)
- Significance level (α)
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
Enter both samples. The calculator ranks the combined data, sums the ranks of sample 1 to get W, and compares W with its null mean and standard deviation. Without ties and with modest sample sizes the exact null distribution is used; otherwise the normal approximation with tie and continuity corrections.
Worked example
Eight treated patients score 34, 41, 29, 45, 38, 52, 47 and 41; seven controls score 28, 31, 25, 36, 30, 33 and 29. In the combined ranking the two 29s share rank 3.5 and the two 41s share rank 11.5. The ranks of the treated group add up to W = 86.5.
Under H₀, E(W) = 8 × 16 ÷ 2 = 64 and the tie-corrected SD is 8.626. With the continuity correction z = (86.5 − 64 − 0.5) ÷ 8.626 = 2.55 and the two-tailed p-value is 0.011, so the treatment group scores significantly higher. The equivalent U₁ is 86.5 − 36 = 50.5, and the Hodges–Lehmann estimate of the shift is 11 points.
Assumptions
- The two samples are independent of each other, and observations within each sample are independent.
- The outcome is at least ordinal, so values can be ranked.
- To interpret the result as a shift in medians, the two distributions should have a similar shape.
Formula
W = R₁ = sum of the ranks of sample 1 in the combined data · E(W) = n₁(N + 1)/2 · SD(W) = √(n₁n₂/12 × [(N + 1) − Σ(t³ − t)/(N(N − 1))]) · z = (W − E(W) ∓ 0.5) ÷ SD(W) · U₁ = W − n₁(n₁ + 1)/2
Worked example
Inputs — Sample 1 (e.g. treatment): 34, 41, 29, 45, 38, 52, 47, 41; Sample 2 (e.g. control): 28, 31, 25, 36, 30, 33, 29; Alternative hypothesis: The two samples differ (two-tailed); p-value method: Automatic (exact when possible); Continuity correction (normal approximation): Yes; Significance level (α): 0.05.
Results — p-value = 0.01; Rank-sum statistic W (sum of ranks of sample 1) = 86.5; Expected W under H₀ = 64; Standard deviation of W (tie-corrected) = 8.6255; z-score = 2.5506; Decision = Reject H₀ at α = 0.05 – p = 0.0108 ≤ 0.05; the two distributions differ in location..
Key terms
- Rank sum (W)
- The total of the ranks of one sample within the combined, sorted data.
- Combined ranking
- Ranking all observations from both samples together, ties sharing the average rank.
- Tie correction
- The reduction in the variance of W caused by groups of equal values.
- Non-parametric test
- A test that does not assume a specific distribution such as the normal.
Frequently asked questions
What is the difference between the Wilcoxon rank-sum and signed-rank tests?
The rank-sum test compares two independent groups; the signed-rank test compares paired measurements (or one sample against a median).
Is the Wilcoxon rank-sum test the same as Mann–Whitney?
Yes. They use different statistics (W and U) but U₁ = W − n₁(n₁ + 1)/2, so they always give the same p-value.
What is the expected rank sum?
n₁(N + 1)/2. With n₁ = 8 and N = 15 it is 64; the default data give W = 86.5, well above it.
Which sample should be sample 1?
Either. Swapping them changes W but not the two-tailed p-value. For a one-tailed test, make sure the direction matches your hypothesis.
How do ties affect the test?
Tied values share the average rank and the variance of W is reduced. The exact distribution assumes no ties, so with ties the normal approximation is used.
How do I report the result?
For example: "Scores were higher in the treatment group (median 41 vs 30), W = 86.5, z = 2.55, p = 0.011."
What does R's wilcox.test report?
R prints W as the Mann–Whitney U₁ rather than the rank sum. Use the "Equivalent Mann–Whitney U₁" line here to compare.