The Friedman Test is a non-parametric alternative to the Repeated Measures ANOVA. 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 friedmanchisquare() function 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 (H _{0}):** 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.