🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Wilcoxon Signed-Rank Test — Nonparametric Paired Test

Nonparametric TestsNonparametric Tests🟢 Free Lesson

Wilcoxon Signed-Rank Test

Nonparametric Tests

The Nonparametric Alternative to the Paired t-Test

When your data violates normality assumptions, the Wilcoxon signed-rank test provides a robust alternative for comparing paired observations. It's essential for analyzing ordinal data, Likert scales, and small samples where normality cannot be verified.

  • Clinical Trials — Assess treatment effects on patient symptom ratings before and after intervention
  • Quality Control — Compare measurements from two instruments without assuming normal distributions
  • Survey Research — Analyze pre-post responses on non-normal ordinal scales

When normality fails, ranks still speak the truth about paired differences.


What You'll Learn

  • 1State the symmetry assumption that separates the signed-rank test from the sign test
  • 2Rank absolute differences by hand and compute W+ and W− for a small sample
  • 3Decide between the exact distribution and the normal approximation, including tie corrections
  • 4Choose among paired t, Wilcoxon signed-rank, and sign test from the shape of the differences

The nonparametric alternative to the paired t-test. Tests whether the median of differences equals zero, without assuming normality.

What the Test Actually Hypothesises

The sharp null says that the differences come from a distribution symmetric about zero, so every assignment of plus and minus signs to the ranked magnitudes is equally likely. The composite alternative usually quoted — that the median difference is nonzero — follows from that symmetry, but only from it. If the differences are asymmetric, a significant result can reflect the shape of the distribution rather than a shift in its centre, which is precisely the situation where the sign test, which never looks at magnitudes, is the safer instrument.

What the test uses is the ordering of the magnitudes, not their values. A difference of 40 contributes four times the rank of a difference of 4, but it does not contribute ten times the evidence, because the ranks compress the spacing. That compression is the source of the test's resistance to outliers: one extreme pair can move a mean arbitrarily far, whereas it can only occupy the top rank.

The Ranking Procedure

  1. Compute the difference for each pair, .
  2. Discard any difference that is exactly zero, since it carries no directional information.
  3. Rank the absolute differences from smallest to largest, assigning the average rank to ties.
  4. Restore the original sign of each difference to its rank.
  5. Add the ranks carrying a positive sign to get , and the negative ones to get . The two always sum to .
  6. Report the smaller of the two as the test statistic and compare it against the null distribution for effective pairs.

Worked Example, Computed by Hand

Take the eight differences 7, 3, −1, 5, 2, −4, 6, 8. Their absolute values happen to be distinct, so rank attaches to the -th smallest:

DifferenceAbsolute valueRankSigned rank
−111−1
222+2
333+3
−444−4
555+5
666+6
777+7
888+8

The check confirms the arithmetic. Under the null each of the sign patterns is equally likely, and counting those with a negative-rank sum of 5 or less gives ten: the empty set, each of the singletons 1 through 5, and the pairs {1,2}, {1,3}, {1,4}, {2,3}. The exact two-sided p-value is therefore

At the conventional 0.05 level this sample does not reach significance, and with only eight pairs it could not have done so unless fell to 3 or below. The smallest p-value attainable at is . Sample size governs the resolution of a rank test exactly as it governs a t-test.

Exact Distribution Versus Normal Approximation

For small samples with no ties, software enumerates the sign patterns and returns an exact p-value. SciPy switches to a normal approximation once passes roughly 25 or once ties make enumeration meaningless. Under the null the statistic has known moments:

For the example above, and . Applying a continuity correction of half a rank gives , a two-sided p-value of 0.080 — close to the exact 0.0781 and confirming that the approximation is already adequate at this size. When absolute differences tie, they receive midranks and the variance shrinks through a correction term built from the cube of each tie group's size; failing to apply it makes the test slightly conservative.

Two further switches change behaviour at the margin. The zero_method parameter decides what happens to exact zeros: the default wilcox discards them and reduces , pratt ranks them but then drops their contribution, and zsplit splits their rank evenly between the two sides. The correction parameter toggles the continuity adjustment in the normal approximation. State which you used whenever zeros are present, because the three choices can disagree on the decision.

Python Implementation

python
import numpy as np
from scipy import stats

np.random.seed(42)
before = np.array([85, 90, 78, 92, 88, 76, 95, 82, 87, 91, 73, 89])
after  = np.array([78, 82, 75, 88, 85, 70, 89, 79, 80, 86, 68, 84])
differences = before - after

print(f"Median difference: {np.median(differences):.2f}")

# Wilcoxon signed-rank test
stat, p = stats.wilcoxon(before, after, alternative='two-sided')
print(f"W = {stat:.2f}, p = {p:.4f}")

# Compare with paired t-test
t, p_t = stats.ttest_rel(before, after)
print(f"Paired t-test: t={t:.4f}, p={p_t:.4f}")

# When to prefer Wilcoxon
print("\nUse Wilcoxon signed-rank when:")
print("* n is small and normality of differences can't be verified")
print("* Differences have heavy tails or outliers")
print("* Data is ordinal")
python
# Manual computation — reproduces the worked example exactly
d = np.array([7, 3, -1, 5, 2, -4, 6, 8])
d_nonzero = d[d != 0]
n = len(d_nonzero)

ranks = stats.rankdata(np.abs(d_nonzero))
W_plus  = ranks[d_nonzero > 0].sum()
W_minus = ranks[d_nonzero < 0].sum()
W = min(W_plus, W_minus)

print(f"W+ = {W_plus:.1f}, W- = {W_minus:.1f}, W = {W:.1f}, n = {n}")
print(f"Check: W+ + W- = {W_plus + W_minus:.1f} vs n(n+1)/2 = {n*(n+1)/2:.1f}")

# Exact p-value by enumerating all 2^n sign patterns
from itertools import product
total_ranks = n * (n + 1) / 2
abs_ranks = np.sort(np.abs(d_nonzero))
count = sum(1 for signs in product([1, -1], repeat=n)
            if min(sum(s * r for s, r in zip(signs, abs_ranks)),
                   total_ranks - sum(s * r for s, r in zip(signs, abs_ranks))) <= W)
print(f"Exact two-sided p = {2 * count / 2**n:.4f}")

The enumeration loop is deliberately slow and transparent: it shows that an exact rank p-value is nothing more than a proportion of achievable sign patterns, the same logic that a permutation test generalises to arbitrary statistics.

Wilcoxon Versus Paired t Versus Sign Test

CriterionPaired tWilcoxon signed-rankSign test
Information usedExact magnitudesOrder of magnitudesDirection only
AssumptionDifferences approximately normalDifferences symmetric about the medianDifferences independent, any shape
Outlier sensitivityHighLowNone
Relative efficiency under normality1.0000.9550.637
Ordinal data such as LikertInappropriateAppropriateAppropriate
Smallest attainable p at n = 8Continuous0.01560.0078

The efficiency row explains the everyday choice. Under a genuinely normal distribution the signed-rank test gives up about 4.5 percent of the power of the t-test — an almost invisible cost — while buying immunity to skew and outliers. The sign test is far cheaper still but throws away magnitude information, costing roughly a third of the power under normality; it earns its keep only when the data are so malformed that even symmetry is doubtful.

Effect Size and Reporting

Two effect sizes circulate and they answer different questions. The matched-pairs rank-biserial correlation uses the rank sums directly,

which for the worked example gives , a large positive shift. The second, , standardises the normal-approximation statistic and is what many papers report. Either is preferable to a bare p-value, and the median difference with its interquartile range should accompany them so the reader can see the raw scale.

A complete report names the test, the number of pairs after zero removal, , the exact or approximate p-value, the direction and median of the differences, and an effect size. If a paired t-test was also run, say so and explain why the rank version was preferred — reviewers read an unexplained switch as p-hacking.

Common Mistakes

Quoting the median of the differences as if it were what Wilcoxon tests

Fix: The test targets a symmetric location shift. Report the median and interquartile range as description, and state the symmetry assumption as the basis of the inference.

Letting software silently discard tied zeros

Fix: Check the count of zero differences and set zero_method explicitly. Pratt and Wilcox can give different p-values when zeros are common.

Switching to Wilcoxon only after the t-test comes back non-significant

Fix: Choose the test from the design and the shape of the differences, decided before seeing the p-value, and report both if you genuinely cannot decide.

Best Practices

  • Plot the differences before testing so the choice between t, Wilcoxon, and sign test is evidence based
  • Report W, n after zero removal, whether the p-value was exact, and an effect size alongside the p-value
  • Use Wilcoxon for Likert-style pre-post ratings, where the mean difference has no defensible interpretation

Key Takeaways

  • Wilcoxon ranks the absolute differences and tests the signed rank total, so only ordering and symmetry matter
  • W+ and W− always sum to n(n+1)/2; the test statistic is the smaller of the two
  • Exact enumeration holds for small n without ties; the normal approximation takes over above about 25 pairs
  • Relative efficiency against the paired t-test is 3/π ≈ 0.955 under normality, a small price for outlier resistance

Frequently Asked Questions

Does the Wilcoxon signed-rank test test the median?

Only when the difference distribution is symmetric. Under symmetry the mean and median coincide and the test is a valid location test. Under strong asymmetry it can reject for reasons that have nothing to do with the median, and the sign test becomes the appropriate distribution-free test for a median shift.

What happens to tied ranks?

Tied absolute differences receive the average of the ranks they would otherwise occupy, and the variance used in the normal approximation is reduced accordingly. Software handles this automatically, but the exact distribution is no longer available, so large tied samples fall back on the approximation.

Is it a valid substitute for a paired t-test in every situation?

It is a valid substitute when the differences are continuous and at least roughly symmetric. It is not a cure for non-independence between pairs, and it cannot rescue a design where the pairing was invented during analysis rather than built into data collection.

Interview Questions

Q1: How does the Wilcoxon signed-rank test differ from the sign test?

Signed-rank uses the order of the absolute differences, so magnitude information contributes through ranking; the sign test counts only how many differences are positive. Under normality signed-rank is about 1.5 times as efficient, at the price of assuming symmetry.

Q2: State the assumptions of the signed-rank test

Pairs are independent, the differences are measured on at least an ordinal scale, and the difference distribution is symmetric about its centre. Normality is not required.

Q3: How do you compute W?

Rank the absolute non-zero differences, attach the original signs, sum the positive ranks to W+ and the negative ranks to W−, and take the smaller as W. For n = 8 the two sums must total 36.

Q4: When does software use the exact versus the approximate distribution?

Exact enumeration of all 2^n sign patterns is used for small n with no ties; beyond roughly 25 pairs, or when ties force midranks, the normal approximation with mean n(n+1)/4 and variance n(n+1)(2n+1)/24 is used, optionally with a continuity correction.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement