A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/how-to-perform-a-one-way-anova-in-python/ below:

How to Perform a One-Way ANOVA in Python

How to Perform a One-Way ANOVA in Python

Last Updated : 23 Jul, 2025

One-Way ANOVA is a statistical test used to check if there are significant differences between the means of three or more groups i.e analysis of variance. It helps us to find whether the variations in data are due to different treatments or random chance.

Hypotheses in One-Way ANOVA

One-way ANOVA has null and alternative hypotheses:

Example:

Imagine we want to compare the performance of four different engine oils used in cars. The cars drive 100 kilometers with each type of oil and their performance is recorded. We want to check if the performance differs depending on the oil used. Now we will use One-Way ANOVA test in Python with following steps:

Step 1: Install Required Libraries

We need to install the SciPy library in our system. We can install it using below command in terminal:

pip3 install scipy

Step 2: Create Data Groups

We create arrays representing the performance of cars with each engine oil.

Python
performance1 = [89, 89, 88, 78, 79]
performance2 = [93, 92, 94, 89, 88]
performance3 = [89, 88, 89, 93, 90]
performance4 = [81, 78, 81, 92, 82]
Step 3: Perform One-Way ANOVA

Now we use the f_oneway() function from SciPy to conduct the One-Way ANOVA test.

Python
from scipy.stats import f_oneway

f_statistic, p_value = f_oneway(performance1, performance2, performance3, performance4)

print(f"F-statistic: {f_statistic}")
print(f"P-value: {p_value}")

Output:

Result Step 4: Analyze the Result

The output will provide two important values:

Since p-value is less than 0.05 hence we would reject the null hypothesis. This implies that we have sufficient proof to say that there exists a difference in performance among four different engine oils.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4