UK-based online statistics and data analysis support for USA, UK, and international clients. No exams, no impersonation, no fabricated data.

Nonparametric two-independent-sample location test

Wilcoxon Rank Sum Test: 7 Essential Steps, Formula and Worked Example

The Wilcoxon rank sum test compares two independent groups by pooling their observations, assigning midranks and evaluating whether one group tends to occupy higher ranks than the other. This complete guide separates the rank-sum statistic from the Mann–Whitney U statistic, explains ties and continuity correction, reports effect size and probability superiority, and provides verified workflows in Python, R, SPSS, Excel, MATLAB, SAS and Stata.

Two independent samples
W and U explained
Tie-adjusted inference
Effect size included
Python + R + SPSS + Excel
Sample sizes423 vs 226
GP rank sum154,877
Two-sided p1.424 × 10−14
Probability GP > MS68.20%
Quick answer

First-period grades were significantly higher in GP than in MS.

In this worked Wilcoxon rank sum test example, first-period grade (G1) was compared between GP school students (n = 423) and MS school students (n = 226). GP had median G1 = 12, whereas MS had median G1 = 10. The pooled rank sum for GP was WGP = 154,877, equivalent to UGP = 65,201. With a tie-adjusted variance and continuity correction, z = 7.694 and the verified two-sided probability was p = 1.423958 × 10−14.

The effect is not only statistically significant. The probability-superiority estimate is 0.6820: when one GP observation and one MS observation are selected at random, the GP grade is higher with ties counted as one-half in approximately 68.20% of pairwise comparisons. The rank-biserial correlation is 0.3641, and the Hodges–Lehmann point estimate of the GP-minus-MS shift is 2 grade points.

Correct conclusion: reject the equal-distributions null. GP observations tend to be higher than MS observations. A simple “median difference” interpretation is strongest when the group distributions have reasonably similar shapes.
1

What does the Wilcoxon rank sum test measure?

A two-sample comparison based on pooled order rather than raw measurement distances.

The Wilcoxon rank sum test evaluates whether observations from one independent population tend to be larger or smaller than observations from another independent population. It is also called the Mann–Whitney–Wilcoxon test, the Wilcoxon–Mann–Whitney test, or the Mann–Whitney U test. These names describe equivalent inferential procedures but software can report different raw statistics.

The general distributional question

At its broadest, the null hypothesis says that the two population distributions are the same. The procedure combines all observations, replaces their original values with ranks and asks whether one group receives a systematically larger rank total. Because the calculation depends on order, it can be used with ordinal outcomes and with numeric outcomes whose spacing may not support a comfortable mean-based analysis.

A significant result means that the ordering of the two samples is inconsistent with identical distributions. The difference can arise from location, spread, skewness, tail behavior or a mixture of these features. Calling every significant result a “median difference” is therefore too strong unless the distribution shapes are similar and a location-shift model is reasonable.

The pairwise probability view

The equivalent Mann–Whitney statistic has a useful interpretation. After ties receive half credit, U/(n1n2) estimates the probability that a randomly chosen observation from the first group exceeds a randomly chosen observation from the second group. This quantity is also called the common-language effect, probability of superiority or area under the ROC curve for a two-group ordering problem.

In the school example, the value is 0.6820. The result is therefore more informative than “p < .05”: GP has the higher G1 grade in 63.72% of strict pairwise comparisons, the grades tie in 8.96%, and half of the tied comparisons raises the probability-superiority estimate to 68.20%.

Ranks do not test means. The procedure ignores the exact numerical distance between scores once their order is known. A change from 8 to 9 affects the ranks in the same general way as a change from 8 to 18 if both changes move an observation past the same number of other observations.

Location-shift interpretation

If both distributions have the same shape and spread but differ only by a horizontal shift, the test can be interpreted as evidence about a difference in population location or median.

Stochastic-order interpretation

A one-sided alternative can ask whether values from GP are more likely to exceed values from MS. This is stronger and clearer than automatically claiming that means differ.

Equal-distribution interpretation

Without the equal-shape condition, the safest two-sided statement is that the two population distributions differ in their ordering pattern.

2

When should you use the Wilcoxon rank sum test?

Match the method to two independent groups and an orderable outcome.

Use the Wilcoxon rank sum test when there are exactly two independent samples, the outcome can be meaningfully ordered, and the research question concerns relative location or stochastic ordering rather than a paired change, a mean difference alone, or a comparison across three or more groups.

Two groups?

The design must contain exactly two samples for the basic rank-sum procedure.

Independent units?

Each student or experimental unit belongs to one group and contributes one observation.

Orderable outcome?

The response must be ordinal, interval or ratio scaled so pooled observations can be ranked.

Location or ordering?

The estimand should concern which group tends to have higher observations.

Shape checked?

Similar shapes are needed before translating the result into a pure median shift.

Appropriate applications

Comparing pain ratings from two independently assigned treatments.
Comparing examination scores between two schools or teaching approaches.
Comparing waiting times between two service systems when the data are skewed.
Comparing an ordered satisfaction scale between two independent customer groups.
Providing a robust sensitivity analysis when a few extreme observations influence the two-sample t test.

Choose another procedure when

The measurements are paired or repeated; use the Wilcoxon signed rank test or a paired model.
There are three or more independent groups; use the Kruskal–Wallis test or an appropriate model.
The target is a mean difference and mean-based assumptions are defensible; use a Welch two-sample t test.
The outcome is nominal and cannot be ordered; use a categorical-data procedure.
The groups are clustered by school, classroom or site and independence is not plausible; use a design-aware mixed or marginal model.
Do not choose the test only because Shapiro–Wilk is significant. With large samples, normality tests detect small departures that may not threaten Welch’s t test. The research estimand, outliers, skewness, scale, sample sizes and distribution shapes should be considered together.
3

Wilcoxon rank sum test assumptions: seven conditions

Nonparametric does not mean assumption-free.

The Wilcoxon rank sum test assumptions include independent observations, independent groups, an orderable outcome, a meaningful sampling design and a clearly defined treatment of ties. Comparable distribution shapes are additionally required for the familiar median-difference interpretation.

1. Independent groups

GP and MS are nonoverlapping school groups. No observation can appear in both samples. Matching the same student across time would violate this condition.

2. Independent observations

One student’s response should not determine another student’s response. Classroom, family or school clustering can reduce effective independence and should be modeled when it is part of the design.

3. Ordered response

G1 is numeric and can be ranked from lower to higher. Purely nominal categories such as eye color cannot be analyzed with this rank procedure.

4. Random or justified sampling

Population inference requires random sampling, random assignment or another defensible design. A p-value does not repair convenience sampling or uncontrolled selection.

5. Comparable shape for medians

If the groups have similar shape and spread, a rank shift can be discussed as a median or location difference. With different shapes, use the broader distributional interpretation.

6. Ties handled correctly

Equal G1 scores must receive averaged midranks. The large-sample variance must include the cubic tie correction rather than the no-tie formula.

7. Prespecified direction

A one-sided alternative should be chosen before inspecting the observed direction. Changing to a one-sided test after seeing the data invalidates the claimed error rate.

Shape is the most commonly omitted condition. The rank-sum test can detect a distributional difference even when the medians are equal, and it can be nonsignificant despite visibly different medians if shape and overlap behave differently. Inspect histograms, ECDFs, boxplots and group-specific spread before writing “the medians differ.”

What ties change

The 649 grades contain many repeated integer values. Midranks preserve the total rank identity, but ties reduce the null variance because multiple orderings are indistinguishable. The worked calculation uses the tie term ∑(t3 − t) = 3,336,300, giving Var(U) = 5,115,025.6003.

What unequal sample sizes change

Unequal sizes are allowed. GP contributes 423 observations and MS contributes 226. The formulas incorporate both sizes directly. The important issue is not equality of sample sizes but whether the smaller group adequately represents its target population and whether extreme imbalance accompanies different shapes or variances.

4

Wilcoxon rank sum test hypotheses and data dictionary

State the broad null first, then add a location-shift interpretation only when justified.

The null hypothesis for the Wilcoxon rank sum test is commonly stated as equality of the two population distributions. Under a common-shape location model, the same procedure tests whether the location shift is zero. The one-sided alternatives describe stochastic ordering.

General two-sided hypotheses

H0: FGP(x) = FMS(x) for all x

The two independent populations have the same distribution.

H1: FGP(x) ≠ FMS(x) for at least one x

The distributions differ in location, spread, shape or another ordering feature.

Location-shift version

H0: Δ = 0    versus    H1: Δ ≠ 0

If the distributions have a common shape, Δ is the horizontal shift. The Hodges–Lehmann point estimate in the worked data is GP − MS = 2 grade points.

Variables and coding

OutcomeG1, the first-period numeric grade.
Grouping variableschool, coded GP or MS.
Group 1GP, n = 423, median = 12, IQR = 4.
Group 2MS, n = 226, median = 10, IQR = 4.
DirectionPositive UGP departure indicates higher GP ranks.
AlphaTwo-sided α = .05.

Both groups have IQR = 4, but the standard deviations differ: 2.418 for GP and 2.980 for MS. The similar IQRs support a location-focused reading, while the different tails and ranges still justify careful distributional wording.

GP greater than MS

H1: P(GP > MS) + ½P(GP = MS) > .5

GP less than MS

H1: P(GP > MS) + ½P(GP = MS) < .5

Two-sided

H1: the probability-superiority parameter differs from .5.

Why the school result rejects the null

Under H0, the expected Mann–Whitney statistic for GP is E(U) = nGPnMS/2 = 47,799. The observed value is 65,201, a departure of 17,402 pairwise units. After a 0.5 continuity correction, the standardized value is z = 7.694188. The two-sided probability is approximately 1.424 × 10−14, far below .05.

The direction is also coherent with the descriptive evidence. GP has median 12 and mean rank 366.139, whereas MS has median 10 and mean rank 248.000. The inferential result is therefore accompanied by a clear and practically interpretable ordering difference.

5

Wilcoxon rank sum test formula: ranks, W, U, ties and z

The same inference can be expressed with a rank sum or a pair-count statistic.

The Wilcoxon rank sum test formula begins by ranking all N observations together. The raw rank sum W for one group converts exactly to a Mann–Whitney U statistic. Large-sample inference uses a null mean, tie-adjusted variance and optional continuity correction.

Step 1: pool and rank

Combine the GP and MS grades, sort them from lowest to highest and assign ranks 1 through N. If several observations have the same grade, give each observation the average of the ranks it would occupy. For example, all observations tied at a particular score share the same midrank.

W1 = ∑i∈group 1 Ri

W1 is the sum of pooled ranks assigned to the first group.

Step 2: convert W to U

U1 = W1 − n1(n1 + 1)/2

The subtraction removes the minimum rank total that group 1 would receive if its observations occupied the first n1 positions.

U2 = n1n2 − U1

The two U statistics sum to the number of cross-group pairs. In the worked data, UGP = 65,201 and UMS = 30,397; their sum is 95,598 = 423 × 226.

Step 3: expected value and tie-adjusted variance

E(U) = n1n2/2
Var(U) = [n1n2/12] × [(N + 1) − ∑(t3 − t)/(N(N − 1))]

Each t is the size of one pooled tie group. Without ties, the summation is zero and the familiar n1n2(N + 1)/12 formula is recovered.

Step 4: standardized statistic

z = [U − E(U) − 0.5·sign(U − E(U))] / √Var(U)

The 0.5 term is the continuity correction. It moves the discrete U statistic toward its null mean before the normal tail probability is evaluated.

Worked identity for GP

Rank sumWGP = 154,877
Rank offset423 × 424 / 2 = 89,676
U equivalent154,877 − 89,676 = 65,201
Expected U423 × 226 / 2 = 47,799
Standard error√5,115,025.6003 = 2,261.6422
Corrected z(65,201 − 47,799 − 0.5) / 2,261.6422 = 7.694188

Rank-sum identities used for quality control

IdentityVerified value
WGP + WMS = N(N + 1)/2154,877 + 56,048 = 210,925
UGP + UMS = nGPnMS65,201 + 30,397 = 95,598
Probability superiority = UGP/(nGPnMS)65,201 / 95,598 = 0.682033
Rank-biserial = 2A − 12(0.682033) − 1 = 0.364066
W is not standardized across software. A textbook may call 154,877 the Wilcoxon W, R may print an offset statistic labeled W = 65,201, and SPSS may print the smaller Mann–Whitney U = 30,397 together with Wilcoxon W = 56,048. These values are mathematically consistent once group order and offset conventions are stated.
6

Wilcoxon rank sum test example: G1 grades at GP and MS

A complete worked analysis using 649 independent student records.

This Wilcoxon rank sum test example compares first-period grades across two schools. It includes the raw group summaries, pooled ranks, test statistic, tie correction, normal approximation, practical effect size and the distinction between statistical and causal conclusions.

Research question

Do first-period grades tend to be higher at GP than at MS? The outcome G1 ranges from 0 to 19 in the combined data. School membership creates two independent samples: GP with 423 observations and MS with 226 observations.

The two-sided analysis is appropriate when the goal is to detect any ordering difference. A one-sided GP-greater alternative would be justified only if that direction had been specified before examining the observed grades.

Descriptive comparison

StatisticGPMS
n423226
Mean11.985810.3009
SD2.41832.9796
Median1210
Q1 / Q310 / 148 / 12
IQR44
Minimum / maximum0 / 184 / 19
GP mean rank366.1395Rank sum = 154,877
MS mean rank248.0000Rank sum = 56,048
Median shift2 pointsHodges–Lehmann estimate
Probability superiority68.20%GP over MS, ties half

How the pairwise interpretation is formed

There are 423 × 226 = 95,598 possible GP–MS pairs. GP is strictly higher in approximately 63.72% of these pairs, equal in 8.96% and lower in 27.32%. The Mann–Whitney convention gives half credit to ties:

0.637220 + 0.5(0.089625) = 0.682033

This calculation makes the effect interpretable without relying on arbitrary “small, medium, large” labels. A value of .50 would indicate no tendency for either school to have higher grades; .682 indicates a clear GP advantage in the pairwise ordering.

Causal limitation: school membership was not randomly assigned for this comparison. The test establishes an association in the observed data, not that attending GP causes higher grades. School composition, prior attainment, curriculum, family characteristics and other variables may explain part of the difference.
7

Wilcoxon rank sum test results, p-value and effect size

Report statistical evidence and practical ordering together.

The Wilcoxon rank sum test results show an extremely small p-value, but the effect-size estimates are equally important. The probability-superiority estimate, rank-biserial correlation, z-based effect and Hodges–Lehmann shift describe the magnitude and direction of the observed difference.

Primary inference

p = 1.424 × 10−14

Reject H0

GP and MS G1 distributions are not equal. GP receives substantially higher pooled ranks and has the higher location in the observed data.

Calculation audit

WGP154,877
UGP65,201
E(U)47,799
Var(U), ties adjusted5,115,025.6003
z, continuity corrected7.694188
Magnitude measureValueInterpretation
Probability superiority / AUC0.682033A random GP grade exceeds a random MS grade, ties counted half, 68.20% of the time.
Rank-biserial correlation0.364066The pairwise ordering favors GP by 36.41 percentage points beyond the .50 null baseline.
z/√N effect0.302023A standardized rank-based effect commonly described as moderate, though context matters more than universal cutoffs.
Hodges–Lehmann shift2 G1 pointsThe median of all GP-minus-MS pairwise differences is two grade points.
Observed median difference2 G1 pointsGP median = 12 and MS median = 10.

Continuity correction sensitivity

Without the 0.5 continuity correction, the two-sided asymptotic p-value is approximately 1.42150 × 10−14. With the correction, it is 1.42396 × 10−14. The numerical difference is tiny and the scientific conclusion is unchanged.

Workbook and independent verification

The workbook formula reports approximately 1.42109 × 10−14, while the independently verified SciPy-style calculation gives 1.42396 × 10−14. The absolute difference is 2.87 × 10−17, caused by implementation and floating-point details rather than a substantive discrepancy.

Do not report p = 0.000. The p-value is extremely small but positive. Report p < .001 in conventional prose and preserve the scientific-notation value in technical tables or downloadable output.
8

Wilcoxon rank sum test in Python: SciPy, ties and effect size

Use mannwhitneyu for tie-aware independent-sample inference.

For a Wilcoxon rank sum test in Python, scipy.stats.mannwhitneyu is preferable to scipy.stats.ranksums when ties are present because the Mann–Whitney implementation supports tie-corrected asymptotic inference and explicit continuity correction.

Python / SciPy core analysisimport numpy as np
import pandas as pd
from scipy.stats import mannwhitneyu, rankdata

df = pd.read_csv("dataset.csv")
gp = df.loc[df["school"].eq("GP"), "G1"].dropna().to_numpy()
ms = df.loc[df["school"].eq("MS"), "G1"].dropna().to_numpy()

fit = mannwhitneyu(
gp, ms,
alternative="two-sided",
method="asymptotic",
use_continuity=True
)

n1, n2 = len(gp), len(ms)
u_gp = float(fit.statistic)
w_gp = u_gp + n1 * (n1 + 1) / 2
probability_superiority = u_gp / (n1 * n2)
rank_biserial = 2 * probability_superiority - 1

print(f"W_GP = {w_gp:.0f}")
print(f"U_GP = {u_gp:.0f}")
print(f"p = {fit.pvalue:.12g}")
print(f"A = {probability_superiority:.6f}")
print(f"rank-biserial = {rank_biserial:.6f}")

Python manual tie-adjusted auditpooled = np.r_[gp, ms]
ranks = rankdata(pooled, method="average")
w_gp = ranks[:n1].sum()
u_gp = w_gp - n1 * (n1 + 1) / 2

_, tie_sizes = np.unique(pooled, return_counts=True)
tie_term = np.sum(tie_sizes**3 - tie_sizes)
N = n1 + n2

mean_u = n1 * n2 / 2
var_u = (n1*n2/12) * (
(N + 1) - tie_term / (N * (N - 1))
)
z = (u_gp - mean_u - 0.5*np.sign(u_gp-mean_u)) / np.sqrt(var_u)

Why not use ranksums here? The integer G1 outcome has many ties. A generic normal rank-sum function that does not correct for ties can return a slightly different standard error. The verified calculation explicitly averages tied ranks and uses the cubic tie term.
Python primary metrics for the Wilcoxon rank sum test

Python chart 1: Primary metrics

The full-width Wilcoxon rank sum test overview displays the GP rank sum of 154,877, the equivalent U statistic of 65,201, the very small two-sided p-value and probability superiority of 0.6820. Because all quantities share one axis, the p-value and probability bar appear near zero relative to the rank totals. Their exact values should be read from the report rather than estimated from bar height.

Python school rank summary for GP and MS

Python chart 2: School rank summary

In the Wilcoxon rank sum test rank table, GP contributes 423 observations, rank sum 154,877, mean rank 366.139 and median G1 = 12. MS contributes 226 observations, rank sum 56,048, mean rank exactly 248 and median G1 = 10. The much higher GP mean rank is the central descriptive signal behind the positive U departure.

Python histogram of ranked G1 observations

Python chart 3: Ranked observations

The Wilcoxon rank sum test histogram shows the pooled G1 frequency structure from 0 through 19. Integer scores create substantial ties, particularly around 10–14. Those repetitions justify midranks and a tie-adjusted variance. The pooled chart describes overall frequency but should be supplemented by group-specific summaries before attributing the result to a pure location shift.

Python Wilcoxon rank sum identity chart

Python chart 4: W-to-U identity

The Wilcoxon rank sum test identity chart decomposes the GP rank sum into the fixed offset and the U equivalent: 154,877 = 89,676 + 65,201. This identity explains why packages can display different-looking statistics while returning the same p-value. The offset depends only on the first-group sample size.

Python verified Wilcoxon rank sum test result summary

Python chart 5: Verified result summary

The final Wilcoxon rank sum test chart repeats WGP, UGP, the p-value and probability superiority as an audit summary. The statistical conclusion is strongest when the tiny p-value is paired with the 68.20% probability-superiority estimate rather than presented as significance alone.

9

Wilcoxon rank sum test in R: wilcox.test() and statistic conventions

Base R performs the two-sample Wilcoxon test with continuity correction and optional confidence intervals.

The Wilcoxon rank sum test in R is run with wilcox.test(). With two independent samples and ties, set paired = FALSE, use the normal approximation, and state whether continuity correction was requested.

R / statsdf <- read.csv("dataset.csv")

gp <- df$G1[df$school == "GP"]
ms <- df$G1[df$school == "MS"]

fit <- wilcox.test(
gp, ms,
alternative = "two.sided",
paired = FALSE,
exact = FALSE,
correct = TRUE,
conf.int = TRUE,
conf.level = 0.95
)

fit

What R calls W

For the two-sample procedure, base R’s printed statistic labeled W is commonly the first-sample rank sum after subtracting n1(n1 + 1)/2. With GP supplied first, the printed value is therefore expected to match UGP = 65,201 rather than the raw pooled rank total 154,877.

This naming convention is not an error. Always identify the software and group order when copying the statistic into a report.

Confidence interval meaning

When conf.int = TRUE, R estimates the pseudomedian of pairwise differences under its shift model and provides a confidence interval. This is not automatically a confidence interval for the raw difference between the two sample medians. With many ties, warnings or slight software differences can occur.

R effect-size calculationsn1 <- length(gp)
n2 <- length(ms)

U_gp <- unname(fit$statistic)
A_gp <- U_gp / (n1 * n2)
rank_biserial <- 2 * A_gp - 1

c(probability_superiority = A_gp,
rank_biserial = rank_biserial)

R primary metrics for the Wilcoxon rank sum test

R chart 1: Primary metrics

The full-width R Wilcoxon rank sum test overview reproduces the verified rank total, U equivalent, p-value and probability-superiority estimate. The p-value is approximately 1.424 × 10−14, so it is visually compressed by rank totals measured in tens of thousands.

R school rank summary for the Wilcoxon rank sum test

R chart 2: School rank summary

In the R Wilcoxon rank sum test summary, the GP bar for rank sum is larger partly because GP has more observations, so mean rank is the more direct group comparison. Mean rank 366.139 for GP versus 248.000 for MS confirms that GP grades occupy higher pooled positions.

R ranked observations histogram for G1

R chart 3: Pooled grade frequencies

The discrete peaks in the Wilcoxon rank sum test chart demonstrate why exact no-tie theory is inappropriate for this dataset. The pooled order contains many tied blocks, and every member of a tied block receives the same average rank.

R W and U identity for the Wilcoxon rank sum test

R chart 4: Statistic identity

For the Wilcoxon rank sum test, the raw rank sum equals the fixed GP offset plus the Mann–Whitney U statistic. This relationship is the key to reconciling R, SciPy, SPSS, MATLAB and textbook output.

R verified Wilcoxon rank sum test result

R chart 5: Final verification

The closing R Wilcoxon rank sum test summary confirms the same numerical result as the workbook and Python analysis. Agreement across implementations reduces the risk of a group-order, tie-correction or statistic-labeling mistake.

10

Wilcoxon rank sum test in SPSS: Mann–Whitney U workflow

SPSS labels the equivalent test as Mann–Whitney U in the two-independent-samples procedure.

To run the Wilcoxon rank sum test in SPSS, select the Mann–Whitney U test for two independent samples. SPSS reports a Mann–Whitney statistic, a Wilcoxon rank sum and a standardized value; the displayed raw values can correspond to the smaller group rather than the first group used in Python or Excel.

Legacy dialog steps

Choose Analyze → Nonparametric Tests → Legacy Dialogs → 2 Independent Samples.
Move G1 to Test Variable List.
Move a numeric school code to Grouping Variable and define the GP and MS codes.
Select Mann–Whitney U.
Request descriptive statistics and run the procedure.

Expected statistic reconciliation

If SPSS reports the smaller U, the value is 30,397. Its associated Wilcoxon W is the MS rank sum, 56,048. These are equivalent to the GP-oriented values because UGP + UMS = 95,598 and WGP + WMS = 210,925.

The sign of the standardized z can depend on group coding and rank direction. The p-value and substantive direction should be interpreted using the group-rank table rather than the sign alone.

SPSS syntax* Create a numeric group code when school is stored as text.
AUTORECODE VARIABLES=school /INTO school_num.
VALUE LABELS school_num 1 'GP' 2 'MS'.

NPAR TESTS
/M-W = G1 BY school_num(1 2)
/STATISTICS = DESCRIPTIVES QUARTILES
/MISSING ANALYSIS.

Modern dialog option: Analyze → Nonparametric Tests → Independent Samples can also perform Mann–Whitney U when two groups are selected. Confirm the exact test name, alternative, p-value method and group coding in the output rather than relying on the automatic objective alone.
Do not select Wilcoxon signed-rank. The signed-rank procedure is for paired or one-sample differences. The school groups are independent, so the correct SPSS test is Mann–Whitney U.
11

Wilcoxon rank sum test in Excel: worked formulas with tie correction

Use pooled midranks and formula-driven checks rather than a hand-entered p-value.

The supplied Wilcoxon rank sum test Excel workbook separates raw data, row-level ranks, calculations, diagnostics and reporting. Its structure makes the result auditable from every G1 observation through W, U, the tie term, z and the final p-value.

Recommended workbook logic

ItemExcel action or formulaVerified result
Pooled midrank=RANK.AVG(A5,$A$5:$A$653,1) after pooling all G1 valuesOne average rank per tied score
GP rank sum=SUMIF($B$5:$B$653,"GP",$C$5:$C$653)154,877
GP sample size=COUNTIF($B$5:$B$653,"GP")423
MS sample size=COUNTIF($B$5:$B$653,"MS")226
UGP=W_GP-n1*(n1+1)/265,201
Mean U=n1*n2/247,799
Tie termSum t3 − t across unique G1 values3,336,300
Variance U=n1*n2/12*((N+1)-TieTerm/(N*(N-1)))5,115,025.6003
Corrected |z|=(ABS(U-MeanU)-0.5)/SQRT(VarianceU)7.694188
Two-sided p=2*NORM.S.DIST(-ABS(z),TRUE)≈ 1.424E-14

How to calculate tie sizes

Create a unique list of G1 values, count each value with COUNTIF, then calculate t^3-t for every count. The total 3,336,300 must be included in the variance. Omitting it produces an incorrect standard error for these highly discrete grades.

How to avoid p = 0

Use the lower-tail formula =2*NORM.S.DIST(-ABS(z),TRUE). The algebraically equivalent expression =2*(1-NORM.S.DIST(ABS(z),TRUE)) can lose precision when the cumulative probability rounds to 1.

Workbook quality check: WGP + WMS must equal 210,925, and UGP + UMS must equal 95,598. These identities immediately expose missing rows, rank-range errors and incorrect group filters.
12

Wilcoxon rank sum test in MATLAB, SAS and Stata

Equivalent commands use different labels but test the same independent-sample ordering question.

The Wilcoxon rank sum test is available as ranksum in MATLAB, the Wilcoxon option in SAS PROC NPAR1WAY, and ranksum in Stata. Always verify which group defines the printed rank sum or U statistic.

MATLAB

MATLABgp = G1(school == "GP");
ms = G1(school == "MS");

[p,h,stats] = ranksum(gp,ms,...
'tail','both',...
'method','approximate');

MATLAB returns the rank sum of the first sample and, for the approximate method, a z value. With GP first, the raw rank sum should be 154,877. Confirm the treatment of ties and continuity correction in the version used.

SAS

SASproc npar1way data=student wilcoxon;
class school;
var G1;
exact wilcoxon / maxtime=60;
run;

The asymptotic Wilcoxon analysis is appropriate for this large tied dataset. An exact request can be computationally intensive and must use a method that accounts for the observed ties.

Stata

Stataranksum G1, by(school)
return list

Stata reports rank sums, expected rank sums and a normal approximation. Check the group ordering in the output before interpreting the sign of z.

Cross-software rule: compare sample sizes, both group rank sums, the smaller and larger U values, the tie-adjusted z and the p-value. Matching only the number labeled “W” is not sufficient because W has different conventions.
13

Wilcoxon rank sum vs Mann–Whitney U, t test and signed rank

Closely related names do not imply identical designs or estimands.

The most common search question is whether the Mann Whitney U test is the same as the Wilcoxon rank sum test. The inferential tests are equivalent for two independent samples; the difference is mainly the raw statistic reported. The Wilcoxon signed rank test, however, is a different paired-sample procedure.

MethodDesignMain targetStatisticImportant caution
Wilcoxon rank sumTwo independent groupsDistributional ordering; location under common shapeRank sum WW convention varies by software.
Mann–Whitney UTwo independent groupsSame inference as rank sum; pairwise superiorityUSome software reports U for the first group, others the smaller U.
Wilcoxon signed rankPaired or one-sample differencesSymmetric location of paired differencesSigned-rank sumNot valid for independent groups.
Welch t testTwo independent groupsDifference in population meanstTargets means and uses metric distances.
Brunner–Munzel testTwo independent groupsRelative effect without equal-shape/equal-variance requirementt-like statisticCan be preferable when group shapes and variances differ.
Two-sample KS testTwo independent groupsAny difference between continuous CDFsMaximum CDF distanceDifferent sensitivity and complications with ties.
Kruskal–WallisThree or more independent groupsRank-based omnibus differenceHRequires post-hoc comparisons after significance.

Wilcoxon rank sum vs t test

The rank test is not simply a t test without normality. Welch’s t test targets the mean difference and uses the magnitude of each observation. The rank test targets ordering and is less sensitive to extreme numeric distances. Under normal location shifts, the t test is usually more efficient; under heavy tails or influential outliers, the rank approach can be more stable.

Wilcoxon rank sum vs median test

The median test reduces each observation to above/below a pooled median and discards much rank information. It can be useful for a narrowly defined median question but usually has lower power than the full rank-sum procedure. The rank-sum result should still not be called a median test unless shape conditions are satisfied.

14

Diagnostics, sensitivity checks, sample size and power

Inspect design and distributions before relying on the final p-value.

A strong Wilcoxon rank sum test analysis includes group-size checks, missing-value handling, pooled ties, distribution-shape diagnostics, alternative-statistic conventions, effect size and a power discussion. The method is robust to many non-normal shapes but not to dependence or an undefined estimand.

Independence audit

Check whether students are nested in classrooms or families, whether repeated records exist and whether school membership was sampled independently. A large nominal N cannot compensate for pseudoreplication.

Missing-data audit

Confirm that the same 649 complete records appear in all software. Report the rule for missing G1 or school values. A different valid-case set changes ranks for every included observation.

Tie audit

List the frequency of each observed grade and verify midranks. For small samples with ties, prefer a permutation procedure that conditions on the observed pooled values rather than a no-tie exact distribution.

Shape audit

Compare ECDFs, histograms, boxplots and quantiles. Similar IQRs of 4 support a location comparison, but the different SDs and ranges show that shape equality should not be asserted without visual evidence.

Direction audit

Confirm which group was entered first. A positive GP-oriented U departure indicates higher GP ranks, while software that reports the smaller U can attach a negative z to the same substantive result.

Effect-size audit

Report probability superiority or rank-biserial correlation. Avoid presenting z/√N as the only magnitude estimate because it depends on total sample size and does not translate as directly into pairwise ordering.

Power and sample-size planning

Power depends on the full alternative distribution, not only on a median difference. Simulation is often the clearest planning approach: specify plausible GP and MS distributions, sample repeatedly at candidate sizes, run the same tie-aware procedure and estimate the proportion of rejected null hypotheses.

For a probability-superiority target, planning can also be framed around the expected A parameter. The observed A = .682 is large enough that the present samples have overwhelming evidence, but a future study should use a conservative effect grounded in substantive importance rather than reusing the observed estimate without shrinkage.

Sensitivity analysis for this example

The no-correction and continuity-corrected p-values are nearly identical. The median difference and Hodges–Lehmann shift are both two points. Probability superiority, rank-biserial correlation and mean ranks all point in the same direction. This convergence makes the conclusion more stable than a decision based on one p-value alone.

A Welch t test could answer the separate mean-difference question, while Brunner–Munzel could test relative effect with weaker equal-shape requirements. Agreement across these conceptually different analyses would strengthen the descriptive conclusion, but each result must retain its own estimand.

Common errors: using paired Wilcoxon syntax, ranking each group separately, failing to average ties, reporting the smaller U without group context, saying “means are different,” treating p < .001 as effect size, or claiming causation from an observational school comparison.
15

How to report the Wilcoxon rank sum test in APA style

Include group summaries, statistic convention, p-value method, direction and effect size.

An APA-style Wilcoxon rank sum test report should identify the independent groups and outcome, explain whether W or U is reported, provide the continuity-corrected z and p-value, describe medians or rank summaries, and include a practical effect measure.

Recommended narrative

APA-style result: A two-sided Wilcoxon rank sum test indicated that first-period grades were higher for GP students (n = 423, Mdn = 12, IQR = 4) than for MS students (n = 226, Mdn = 10, IQR = 4), WGP = 154,877, UGP = 65,201, z = 7.69, p < .001. The probability that a randomly selected GP grade exceeded a randomly selected MS grade, with ties counted as one-half, was A = .682; the rank-biserial correlation was rrb = .364. The Hodges–Lehmann estimate of the GP-minus-MS shift was 2 grade points.

When the journal or software convention expects the smaller U, the same analysis can be reported as U = 30,397. State the group order or software source so readers can reconcile the number. Do not report both 65,201 and 30,397 without explaining that they are complementary statistics.

Minimum reporting checklist

Outcome and two independent groups.
Valid n, median and IQR for each group.
W or U with group orientation.
Exact, asymptotic or permutation p-value method.
Tie handling and continuity correction.
Direction and practical effect size.

Interpretive language to avoid

Avoid “the Wilcoxon test proves GP causes higher grades,” “the means are significantly different,” “the medians are unequal” without a shape qualification, and “p = 0.000.” Prefer “GP observations tended to be higher,” “the distributions differed,” and “under a common-shape interpretation, GP had the higher location.”

16

Wilcoxon rank sum test PDF, Excel and software downloads

Use the complete outputs to reproduce and audit the worked analysis.

Download the Wilcoxon rank sum test reports for Python, R and SPSS, plus the formula-driven Excel workbook containing raw data, pooled ranks, calculations, diagnostics and reporting checks.

Reproducibility recommendation: retain the raw group labels, analysis date, software version, p-value method and group order with every exported result. These details prevent apparent disagreements caused by statistic naming or continuity correction.
17

Official Wilcoxon rank sum references and software documentation

Method identity and implementation details were checked against primary documentation.

Reliable Wilcoxon rank sum test guidance should distinguish the broad equal-distributions null, the common-shape location interpretation, the W-to-U identity, exact versus asymptotic inference, ties and software-specific statistic conventions.

Wilcoxon (1945). The foundational rank-based comparison introduced the use of rank sums for two-sample inference.
Mann and Whitney (1947). Established the equivalent U statistic and the probability interpretation based on cross-sample ordering.
SciPy mannwhitneyu documentation. Documents the first-sample U statistic, W-to-U conversion, independent-sample design, exact/asymptotic/permutation methods and treatment of ties.
R stats::wilcox.test documentation. Documents the two-sample test, continuity correction, exact option, one-sided alternatives and shift confidence interval.
IBM SPSS two-independent-samples documentation. States that Mann–Whitney U tests equality of distributions and that a location interpretation requires comparable distribution shapes.
MathWorks ranksum documentation. Provides the rank-sum statistic, U identity, tie-adjusted normal approximation, continuity correction and exact/approximate method rules.
Fay and Proschan (2010). Explains that the Wilcoxon–Mann–Whitney decision rule can have multiple interpretations depending on the assumptions and scientific question.
Numerical source: all worked-example values in this article come from the supplied 649-row G1/school workbook and an independent formula verification of the pooled ranks, tie term, W, U, z, p-value and effect sizes.
18

Wilcoxon rank sum test FAQs

Clear answers to the most common formula, assumption, software and interpretation questions.

What is a Wilcoxon rank sum test?

The Wilcoxon rank sum test is a nonparametric test for comparing two independent samples. It pools the observations, assigns ranks and tests whether one group tends to occupy higher ranks than the other.

Is the Mann–Whitney U test the same as the Wilcoxon rank sum test?

The Wilcoxon rank sum test and Mann–Whitney U procedures are inferentially equivalent. The Wilcoxon form emphasizes a rank sum W; the Mann–Whitney form emphasizes a pair-count statistic U. Software can report either orientation.

Is the Wilcoxon signed rank test the same test?

The Wilcoxon rank sum test is not the signed-rank test. Signed rank is for paired observations or one-sample differences. Rank sum is for two independent groups.

What does the Wilcoxon rank sum test measure?

The Wilcoxon rank sum test measures whether one population tends to generate higher observations than the other. Broadly it tests equality of distributions; under common shape it can be interpreted as a location or median-shift test.

What are the main assumptions?

For the Wilcoxon rank sum test, the samples and observations should be independent, the outcome must be orderable, the sampling design must justify inference, ties must be handled correctly, and similar shapes are needed for a pure median interpretation.

Can the sample sizes be unequal?

The Wilcoxon rank sum test permits unequal sample sizes. The worked example uses 423 GP observations and 226 MS observations. Unequal sizes are included directly in the W, U, expectation and variance formulas.

How are tied values ranked?

In the Wilcoxon rank sum test, every observation in a tie block receives the average of the ranks occupied by that block. The normal-approximation variance must also be reduced using the tie term.

What is W in the Wilcoxon rank sum test?

In the textbook Wilcoxon rank sum test form, W is the pooled rank total for a selected group. Some software uses W for an offset statistic equivalent to U, so the convention must be stated.

How are W and U related?

For the Wilcoxon rank sum test, group 1 has U = W − n₁(n₁ + 1)/2. In the example, 154,877 − 89,676 = 65,201.

What was the worked-example result?

The worked Wilcoxon rank sum test gave GP W = 154,877 and U = 65,201, with continuity-corrected z = 7.694 and two-sided p approximately 1.424 × 10⁻¹⁴.

How should the p-value be interpreted?

For the Wilcoxon rank sum test, under the equal-distributions null, a rank separation at least as extreme as the observed result is extraordinarily unlikely. The p-value does not measure the probability that the null is true or the size of the effect.

What is probability superiority?

For the Wilcoxon rank sum test, probability superiority is U/(n₁n₂). In this analysis it is .682, meaning a random GP grade is higher than a random MS grade, ties counted one-half, 68.2% of the time.

What effect size should be reported?

For a Wilcoxon rank sum test, probability superiority and rank-biserial correlation are direct choices. The analysis reports A = .682 and rrb = .364. A Hodges–Lehmann shift can also be useful under a location model.

Does a significant result prove the medians differ?

A significant Wilcoxon rank sum test does not prove a median difference in every situation. The test can respond to differences in spread or shape. A median-shift conclusion requires reasonably similar distribution shapes.

How do I run the test in Python?

Run the Wilcoxon rank sum test in Python with scipy.stats.mannwhitneyu with the two independent arrays, the planned alternative and an appropriate exact, asymptotic or permutation method.

How do I run the test in R?

Run the Wilcoxon rank sum test in R with wilcox.test(x, y, paired = FALSE) or the formula interface. With ties and large samples, use the asymptotic method and state the continuity-correction choice.

How do I run the test in SPSS?

Run the Wilcoxon rank sum test in SPSS by choosing the Mann–Whitney U option under two independent samples, define the two group codes, and inspect the rank table, U, Wilcoxon W, z and significance.

How do I calculate it in Excel?

Calculate the Wilcoxon rank sum test in Excel by pooling the observations, assigning RANK.AVG midranks, sum one group’s ranks, convert W to U, calculate the tie-adjusted variance, continuity-correct z and use the standard normal lower tail for the p-value.

+

Related statistical guides

Continue with methods that clarify independent samples, paired samples, distribution shape and effect size.

↑ Back to top