Wilcoxon Signed-Rank Test

Introduction

The Wilcoxon signed-rank test is a non-parametric statistical test used to determine if the median of a paired sample differs significantly from a hypothesized median. This lesson explores the concept of the Wilcoxon signed-rank test, its assumptions, practical applications, and implementation in Python.

What is the Wilcoxon Signed-Rank Test?

The Wilcoxon signed-rank test is used when comparing two related (paired) samples to assess whether their distributions differ significantly. It is particularly useful when the assumptions of parametric tests (such as the paired t-test) are not met, especially when dealing with non-normally distributed data or ordinal variables.

Assumptions of the Wilcoxon Signed-Rank Test

The Wilcoxon signed-rank test does not assume that the data are normally distributed. However, it does assume:

  • The paired observations are independent of each other.
  • The differences between paired observations are symmetrically distributed around the median.
Performing the Wilcoxon Signed-Rank Test in Python

Using scipy.stats

Scipy library provides functions to perform the Wilcoxon signed-rank test in Python. Here’s an example of conducting a Wilcoxon signed-rank test:

import numpy as np
from scipy.stats import wilcoxon

# Example data (paired samples)
before = np.array([85, 92, 88, 78, 90])
after = np.array([79, 83, 77, 81, 85])

# Wilcoxon signed-rank test
statistic, p_value = wilcoxon(before, after)

# Interpret results
alpha = 0.05 # significance level
if p_value < alpha:
print("Reject null hypothesis: There is a significant difference between before and after.")
else:
print("Fail to reject null hypothesis: There is no significant difference between before and after.")
Practical Applications

The Wilcoxon signed-rank test is applied in various fields, including:

  • Medicine: Comparing pre- and post-treatment outcomes in clinical trials.
  • Psychology: Analyzing scores before and after an intervention.
  • Environmental Science: Assessing pollutant levels before and after a cleanup effort.
  • Quality Improvement: Evaluating performance metrics before and after process changes.
Conclusion

The Wilcoxon signed-rank test provides a robust method for comparing paired samples when parametric assumptions are not met. By understanding its principles, assumptions, and how to implement it in Python, researchers and analysts can effectively analyze non-parametric data, draw valid conclusions, and make informed decisions based on statistical evidence.