R
Friedman rank sum test
data: weight_loss
Friedman chi-squared = 0.5, df = 2, p-value = 0.7788
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.
The Friedman test operates under several key assumptions:
The hypotheses for the Friedman test can be framed as:
The Friedman test statistic ($ ^2_F \() is calculated as follows:\)$ ^2_F = _{j=1}^k R_j^2 - 3n(k+1) $$ Where:
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.
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:
Download the Excel file link here
R
Friedman rank sum test
data: weight_loss
Friedman chi-squared = 0.5, df = 2, p-value = 0.7788
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.