10.7 C
London
Sunday, July 7, 2024
HomePythonANOVA in PythonHow to Perform the Friedman Test in Python

How to Perform the Friedman Test in Python

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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 (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.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories