Friedman rank sum test
data: weight_loss
Friedman chi-squared = 0.5, df = 2, p-value = 0.7788
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:
- Dependent Samples: The groups are related or matched; typically, measurements are taken from the same subjects at different times or under different conditions.
- Ordinal or Continuous Data: The data should be at least ordinal, though they can also be continuous.
- 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
- Rank each row (or block) of observations separately from 1 to \(k\), treating ties by assigning average ranks.
- Calculate the sum of ranks for each treatment across all subjects.
- 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:
38.0.9 Friedman Test using Python:
Code
Python
import numpy as np
from scipy.stats import friedmanchisquare
# Data for diets
= [5, 4, 6, 5]
diet_a = [4, 3, 5, 4]
diet_b = [6, 5, 7, 6]
diet_c
# Perform Friedman test
= friedmanchisquare(diet_a, diet_b, diet_c)
chi_square, p_value
# 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.