39  Wilcoxon Signed-Rank Test

The Wilcoxon Signed-Rank Test is a non-parametric statistical hypothesis test used to compare two related samples, matched samples, or repeated measurements on a single sample to assess whether their population mean ranks differ. It is an alternative to the paired Student’s t-test when the data does not meet the assumptions required by the latter, specifically normal distribution of differences.

Purpose:

The Wilcoxon Signed-Rank Test is used to compare two related samples, matched samples, or repeated measurements on a single sample to assess whether their population mean ranks differ. It is the non-parametric alternative to the paired t-test.

How it Works:

39.0.1 Assumptions

The Wilcoxon Signed-Rank Test is based on the following assumptions:

  1. Paired Data: The data must be paired, coming from the same participants or closely matched subjects.
  2. Ordinal or Continuous Data: The data should be ordinal, interval, or ratio in nature.
  3. Symmetry of the Distribution: The distribution of the differences between pairs should be symmetric.

39.0.2 Hypotheses

The hypotheses for the Wilcoxon Signed-Rank Test are generally framed as follows:

  • Null Hypothesis (H₀): The median of the differences between the pairs of observations is zero.
  • Alternative Hypothesis (H₁): The median of the differences is not zero.

39.0.3 Formula

The test involves several steps:

  1. Calculate the difference (\(d\)) between each pair of observations.
  2. Exclude pairs with no difference (\(d = 0\)).
  3. Rank the absolute differences, ignoring signs.
  4. Sum the ranks for the positive differences and the ranks for the negative differences.
  5. The test statistic (\(W\)) is the smaller of these two sums.

The calculation for \(W\) is: \[ W = \text{min}(W^+, W^-) \] Where:

  • \(W^+\) is the sum of ranks for the positive differences.
  • \(W^-\) is the sum of ranks for the negative differences.

39.0.4 Interpretation

The significance of the observed \(W\) is evaluated by comparing it to a distribution of \(W\) values expected by chance, which can be obtained from a table of critical values for the Wilcoxon signed-rank test or calculated using an appropriate software function. A small \(W\) value suggests a significant difference between the paired samples.

39.0.5 Example Problem

Suppose a dietitian wants to determine if a new diet reduces the weight of patients. Weigh-ins are conducted before starting the diet and after one month of being on the diet for 6 patients:

  • Weights Before: 200, 220, 180, 195, 210, 230
  • Weights After: 190, 215, 175, 185, 205, 225

Hypotheses:

  • Null Hypothesis (H₀): The median difference in weight before and after the diet is zero.
  • Alternative Hypothesis (H₁): The median difference in weight before and after the diet is not zero.

Calculate Differences and Ranks:

  1. Calculate differences (Before - After): [10, 5, 5, 10, 5, 5]
  2. Rank the absolute differences: [3.5, 1.5, 1.5, 3.5, 1.5, 1.5]
  3. Sum of ranks for positive differences: 13 (since all differences are positive, \(W^+ = W\))

39.0.6 Wilcoxon Signed-Rank Test using Excel:

39.0.7 Wilcoxon Signed-Rank Test using R:

Code
R
# Weights before and after diet
weights_before <- c(200, 220, 180, 195, 210, 230)
weights_after <- c(190, 215, 175, 185, 205, 225)

# Perform Wilcoxon signed-rank test
wilcox_test <- wilcox.test(weights_before, weights_after, paired = TRUE)

# Print the results
print(wilcox_test)

    Wilcoxon signed rank test with continuity correction

data:  weights_before and weights_after
V = 21, p-value = 0.03054
alternative hypothesis: true location shift is not equal to 0

39.0.8 Wilcoxon Signed-Rank Test using Python:

Code
Python
from scipy.stats import wilcoxon

# Weights before and after diet
weights_before = [200, 220, 180, 195, 210, 230]
weights_after = [190, 215, 175, 185, 205, 225]

# Perform Wilcoxon signed-rank test
w_statistic, p_value = wilcoxon(weights_before, weights_after)

# Print the results
print("Wilcoxon statistic:", w_statistic, "P-value:", p_value)
Wilcoxon statistic: 0.0 P-value: 0.03125

This method is crucial for research in fields like medicine and psychology, where matched pairs or repeated measures are common.