Wilcoxon Signed Rank Test (original) (raw)

Last Updated : 27 Jul, 2025

The Wilcoxon Signed Rank Test is a non-parametric statistical test used to compare two related groups. It is often applied when the assumptions for the paired t-test (such as normality) are not met. This test evaluates whether there is a significant difference between two paired observations, making it especially useful for non-normally distributed or ordinal data. It is widely used in fields like medicine, psychology and social sciences, where normality assumptions are often violated.

**Key Features of the Wilcoxon Signed Rank Test

**When to Use the Wilcoxon Signed Rank Test?

The test is appropriate when:

**Example

To evaluate the effectiveness of a new teaching method, researchers measure literacy levels of 20 children before and after applying the method. Since the data is non-normal, the Wilcoxon Signed Rank Test is ideal.

**Hypotheses

**Steps to Perform the Wilcoxon Signed Rank Test

  1. **Formulate Hypotheses:
    • H0: There is no significant difference between the pairs.
    • H1: There is a significant difference between the pairs.
  2. **Find the Difference (D) between paired observations (i.e., D = B − A).
  3. **Calculate the Absolute Difference (|D|) for each pair.
  4. **Assign Ranks to the absolute differences from lowest to highest. For tied ranks (duplicate absolute differences), assign them the average rank.
    **Example for ties: If two absolute differences are both 3, assign them a rank of \frac{3 + 4}{2} = 3.5.
  5. **Calculate the Sum of Ranks:
    • **T+: Sum of ranks for positive differences.
    • **T-: Sum of ranks for negative differences.
  6. **Find the Wilcoxon Rank Statistic (W calc ): Wcalc = min⁡ (T+ ,T−)
  7. **Compare W calc to W table:
    • Use the sample size n and the significance level α (commonly 0.05) to find the critical value Wtable from a table of critical values for the Wilcoxon Signed Rank Test.
  8. **Interpret the Result:
    • If Wcalc < Wtable ​, reject H0​.
    • If Wcalc > Wtable ​, accept H0​.

**Interpretation of Results

**Example: Smog Concentration Comparison

Let's consider an example where we compare smog concentrations in India from May to December. The data is presented for 13 states with measurements in both months.

States Smog in May(A) Smog in December(B) Difference[D] Absolute Difference[Abs-D] Rank
Delhi 13.3 11.1 -2.2 2.2 5
Mumbai 10.0 16.2 6.2 6.2 9
Chennai 16.5 15.3 -1.2 1.2 3
Kerala 7.9 19.9 12.0 12.0 11
Karnataka 9.5 10.5 1.0 1.0 2
Tamil Nadu 8.3 15.5 7.2 7.2 10
Orissa 12.6 12.7 0.1 0.1 1
UP 8.9 14.2 5.3 5.3 7
MP 13.6 15.6 2.0 2.0 4
Rajasthan 8.1 20.4 12.3 12.3 12
Gujarat 18.3 12.7 -5.6 5.6 8
West Bengal 8.1 11.2 3.1 3.1 6
Jammu 13.4 36.8 23.4 23.4 13

**Step 5: Calculate T+ and T−

**Step 6: Calculate W calc

Wcalc = min⁡(T+ ,T−) = min⁡(82 ,8) = 8

**Step 7: Find W table

For n = 13 and α = 0.05 for a two-tailed test, the critical value is 17.

**Step 8: Interpret the Result

Since Wcalc = 8 is less than Wtable = 17, we reject the null hypothesis H0​. This means that there is a significant difference in the smog concentrations between May and December.

**Conclusion

The Wilcoxon Signed Rank Test shows that the smog concentration has significantly changed from May to December.

Code Implementation of Wilcoxon Signed Rank Test

Lets see the implementation of Wilcoxon Signed Rank Test with help of an example in Python. Libraries like NumPy and Wilcoxon from scipy would be used,

Python `

import numpy as np from scipy.stats import wilcoxon

may_smog = np.array([13.3, 10.0, 16.5, 7.9, 9.5, 8.3, 12.6, 8.9, 13.6, 8.1, 18.3, 8.1, 13.4]) december_smog = np.array( [11.1, 16.2, 15.3, 19.9, 10.5, 15.5, 12.7, 14.2, 15.6, 20.4, 12.7, 11.2, 36.8])

stat, p_value = wilcoxon(may_smog, december_smog)

print("Wilcoxon Signed Rank Test Statistic:", stat) print("p-value:", p_value)

if p_value < 0.05: print("Reject the null hypothesis: There is a significant difference between the two samples.") else: print("Fail to reject the null hypothesis: No significant difference between the two samples.")

`

**Output

Wicoxon-signed-rank-test-code-output

Output

The null hypothesis was rejected since there is a significant difference between the two samples.

Difference Between the Wilcoxon Signed Rank Test and Wilcoxon Rank-Sum Test

Lets see the differences between the Wilcoxon Signed Rank Test and Wilcoxon Rank-Sum Test( also known as Mann-Whitney U Test):

Aspect Wilcoxon Signed Rank Test **Wilcoxon Rank-Sum Test
Data Type Paired (related) data Independent (unrelated) data
Purpose Compares two related groups or measurements Compares two independent groups to determine if they come from the same distribution
Assumption Data is paired and dependent (e.g., before and after measurement) Data is independent (e.g., comparing two different groups)
Test Statistic Based on the difference between pairs of data points Based on the ranks of data points from two groups combined
Null Hypothesis The median difference between paired samples is zero The two groups come from the same distribution
Example Comparing the effect of a drug on patients before and after treatment Comparing the test scores of two independent groups of students
Test Type Non-parametric test for paired data Non-parametric test for independent data