How can the Friedman Test be performed in Python?

How can the Friedman Test be performed in Python?

The Friedman Test is a statistical test used to compare three or more related groups. It is commonly used in situations where the data is not normally distributed. In order to perform the Friedman Test in Python, the scipy.stats module provides the function friedmanchisquare(). This function takes in the data from the different groups as input and returns the calculated Friedman statistic and p-value. The test can also be performed using the stats.friedmanchisquare() function from the statsmodels library. Both of these methods allow for easy and accurate calculation of the Friedman Test in Python, providing a valuable tool for statistical analysis in various research and data analysis tasks.

Perform the Friedman Test in Python


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.

Cite this article

stats writer (2024). How can the Friedman Test be performed in Python?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-friedman-test-be-performed-in-python/

stats writer. "How can the Friedman Test be performed in Python?." PSYCHOLOGICAL SCALES, 17 Apr. 2024, https://scales.arabpsychology.com/stats/how-can-the-friedman-test-be-performed-in-python/.

stats writer. "How can the Friedman Test be performed in Python?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-friedman-test-be-performed-in-python/.

stats writer (2024) 'How can the Friedman Test be performed in Python?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-friedman-test-be-performed-in-python/.

[1] stats writer, "How can the Friedman Test be performed in Python?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, April, 2024.

stats writer. How can the Friedman Test be performed in Python?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top