Wilcoxon Signed-Rank Test

Wilcoxon Signed-Rank Test

Definition

Core Statement

The Wilcoxon Signed-Rank Test is a non-parametric test for comparing two related (paired) samples. It tests whether the median of the differences is zero, making it the non-parametric alternative to the paired t-test.


Purpose

  1. Compare two measurements on the same subjects (e.g., Before vs After treatment).
  2. Analyze paired data when normality of differences is violated.

When to Use

Use Wilcoxon Signed-Rank When...

  • Data is paired (same subjects measured twice).
  • Differences are not normally distributed.
  • Outcome is ordinal or continuous.

Alternatives

  • If differences are normal: Use Paired T-Test.
  • If samples are independent: Use Mann-Whitney U Test.


Theoretical Background

Procedure

  1. Calculate differences: Di=XafterXbefore.
  2. Ignore zeros (ties with 0).
  3. Rank the absolute differences.
  4. Assign signs (positive/negative) to ranks based on original differences.
  5. Sum positive ranks (W+) and negative ranks (W).
  6. The test statistic W is the smaller of W+ or W.

Hypotheses


Assumptions


Limitations

Pitfalls

  1. Symmetry Assumption: If differences are highly asymmetric, the test may be biased.
  2. Zeros are Dropped: If many differences are exactly zero, information is lost.


Python Implementation

from scipy import stats
import numpy as np

before = np.array([10, 12, 15, 20, 25])
after = np.array([12, 14, 18, 22, 30])

# Wilcoxon Signed-Rank Test
stat, p_val = stats.wilcoxon(before, after)

print(f"Wilcoxon Statistic: {stat}")
print(f"p-value: {p_val:.4f}")

R Implementation

# Wilcoxon Signed-Rank (paired = TRUE)
wilcox.test(after, before, paired = TRUE)

# Equivalently
wilcox.test(after - before)

Worked Numerical Example

Pain Relief Drug (Before vs After)

Data: 6 Patients. Pain level (0-10).

  • Before: [8, 7, 6, 9, 5, 8]
  • After: [2, 3, 5, 8, 5, 9]
  • Diff (After-Before): [-6, -4, -1, -1, 0, +1]

Steps:

  1. Drop zero (Patient 5). n=5.
  2. Absolute Diffs: [6, 4, 1, 1, 1]
  3. Ranks: 6(Rank 5), 4(Rank 4), 1s(Rank 2, average of 1,2,3... tricky with ties).

Software Result: W=3.0,p=0.14.
Interpretation: No significant reduction in pain (sample too small, or effect inconsistent). Note Patient 6 got worse (+1).


Interpretation Guide

Output Interpretation Edge Case Notes
p < 0.05 Significant shift in distributions. "Before After".
Small W Distribution shifted in one direction. One W sum is tiny because few contradictions.
Mean Diff = -5, but p = 0.3 Outlier influence? T-test might say sig, Wilcoxon checks consistency.
Ties Warning "Exact p-value cannot be computed". Normal approximation used. standard warning.

Common Pitfall Example

Using Wilcoxon for Independent Data

Mistake: Comparing Men vs Women (Independent Groups) using Wilcoxon Signed-Rank.

Why Wrong: Signed-Rank measures changes within pairs (diff = X1-X2). Men and Women are not paired!

Consequence: The calculation makes no sense (tries to subtract Woman #1 from Man #1).

Correction:

  • Paired Data: Wilcoxon Signed-Rank Test.
  • Independent Data: Mann-Whitney U Test (also called Wilcoxon Rank-Sum).
  • Names are confusing, be careful!