# How to Perform the Friedman Test in Python

The Friedman Test in Python is a non-parametric test used to determine if there are any statistically significant differences between multiple groups of related data. It can be used to compare two or more related samples and is performed by calculating the chi-squared statistic and comparing it to the critical value from the chi-squared distribution. The Friedman Test in Python can be performed using the scipy.stats.friedmanchisquare() function.


The is a non-parametric alternative to the . It is used to determine whether or not there is a statistically significant difference between the means of three or more groups in which the same subjects show up in each group.

This tutorial explains how to perform the Friedman Test in Python.

Example: The Friedman Test in Python

A researcher wants to know if the reaction times of patients is equal on three different drugs. To test this, he measures the reaction time (in seconds) of 10 different patients on each of the three drugs.

Use the following steps to perform the Friedman Test in Python to determine if the mean reaction time differs between drugs.

Step 1: Enter the data.

First, we’ll create three arrays that contain the response times for each patient on each of the three drugs:

group1 = [4, 6, 3, 4, 3, 2, 2, 7, 6, 5]
group2 = [5, 6, 8, 7, 7, 8, 4, 6, 4, 5]
group3 = [2, 4, 4, 3, 2, 2, 1, 4, 3, 2]

Step 2: Perform the Friedman Test.

Next, we’ll perform the Friedman Test using the from the scipy.stats library:

from scipy import stats

#perform Friedman Test
stats.friedmanchisquare(group1, group2, group3)

(statistic=13.3514, pvalue=0.00126)

Step 3: Interpret the results.

The Friedman Test uses the following null and alternative hypotheses:

The null hypothesis (H0): The mean for each population is equal.

The alternative hypothesis: (Ha): At least one population mean is different from the rest.

In this example, the test statistic is 13.3514 and the corresponding p-value is p = 0.00126. Since this p-value is less than 0.05, we can reject the null hypothesis that the mean response time is the same for all three drugs.

In other words, we have sufficient evidence to conclude that the type of drug used leads to statistically significant differences in response time.

x