38  Friedman Test

The Friedman test is a non-parametric statistical test used to detect differences in treatments across multiple test attempts. It is the non-parametric alternative to the one-way ANOVA with repeated measures and is suitable for experiments where the data violate the assumption of normality required for ANOVA. This test is commonly used in situations where measurement variables are ordinal or when interval scale measurements fail the assumptions of normality.

38.0.1 Assumptions

The Friedman test operates under several key assumptions:

  1. Dependent Samples: The groups are related or matched; typically, measurements are taken from the same subjects at different times or under different conditions.
  2. Ordinal or Continuous Data: The data should be at least ordinal, though they can also be continuous.
  3. Same Number of Observations: Each subject is measured the same number of times, ensuring that the data matrix is balanced.

38.0.2 Hypotheses

The hypotheses for the Friedman test can be framed as:

  • Null Hypothesis (H₀): The distributions of the treatments are identical across repeated measures.
  • Alternative Hypothesis (H₁): At least one treatment yields a different distribution.

38.0.3 Formula

The Friedman test statistic ($ ^2_F \() is calculated as follows:\)$ ^2_F = _{j=1}^k R_j^2 - 3n(k+1) $$ Where:

  • \(n\) is the number of subjects.
  • \(k\) is the number of conditions or treatments.
  • \(R_j\) is the sum of ranks for each treatment across all subjects.

38.0.4 Calculation Steps

  1. Rank each row (or block) of observations separately from 1 to \(k\), treating ties by assigning average ranks.
  2. Calculate the sum of ranks for each treatment across all subjects.
  3. Compute the test statistic using the formula above.

38.0.5 Interpretation

A significant $ ^2_F $ statistic indicates that at least one of the treatments significantly differs from the others. The value is compared against critical values from the chi-square distribution with \(k-1\) degrees of freedom. If $ ^2_F $ is greater than the critical value for a given level of significance (\(\alpha\)), the null hypothesis is rejected.

38.0.6 Example Problem

Imagine a study examining the effect of three different diets on weight loss. Each of four participants tries each diet for one month, and their weight loss is recorded:

  • Diet A: 5, 4, 6, 5
  • Diet B: 4, 3, 5, 4
  • Diet C: 6, 5, 7, 6

Hypotheses:

  • Null Hypothesis (H₀): No diet leads to significantly different weight loss.
  • Alternative Hypothesis (H₁): At least one diet leads to significantly different weight loss.

38.0.7 Friedman Test using Excel:

Download the Excel file link here

38.0.8 Friedman Test using R:

Code
R
# Data for diets
weight_loss <- matrix(c(5, 4, 6, 5, 4, 3, 5, 4, 6, 5, 7, 6), nrow = 4, byrow = TRUE)
colnames(weight_loss) <- c("Diet_A", "Diet_B", "Diet_C")

# Perform Friedman test
friedman_test <- friedman.test(weight_loss)

# Print the results
print(friedman_test)

    Friedman rank sum test

data:  weight_loss
Friedman chi-squared = 0.5, df = 2, p-value = 0.7788

38.0.9 Friedman Test using Python:

Code
Python
import numpy as np
from scipy.stats import friedmanchisquare

# Data for diets
diet_a = [5, 4, 6, 5]
diet_b = [4, 3, 5, 4]
diet_c = [6, 5, 7, 6]

# Perform Friedman test
chi_square, p_value = friedmanchisquare(diet_a, diet_b, diet_c)

# Print the results
print("Friedman chi-square statistic:", chi_square, "P-value:", p_value)
Friedman chi-square statistic: 8.0 P-value: 0.018315638888734182

This test is crucial in fields like medicine, psychology, and agronomy where multiple treatments are compared under non-normal conditions and repeated measures are common.