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
- Compare two measurements on the same subjects (e.g., Before vs After treatment).
- 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
- Calculate differences:
. - Ignore zeros (ties with 0).
- Rank the absolute differences.
- Assign signs (positive/negative) to ranks based on original differences.
- Sum positive ranks (
) and negative ranks ( ). - The test statistic
is the smaller of or .
Hypotheses
: Median of differences = 0 (no change). : Median of differences 0.
Assumptions
Limitations
Pitfalls
- Symmetry Assumption: If differences are highly asymmetric, the test may be biased.
- 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:
- Drop zero (Patient 5). n=5.
- Absolute Diffs: [6, 4, 1, 1, 1]
- Ranks: 6(Rank 5), 4(Rank 4), 1s(Rank 2, average of 1,2,3... tricky with ties).
Software Result:
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 |
| 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!
Related Concepts
- Student's T-Test (Paired) - Parametric alternative.
- Mann-Whitney U Test - For independent samples.