The Wayback Machine - https://web.archive.org/web/20240708124732/https://www.geeksforgeeks.org/one-way-anova/
Open In App

One-Way ANOVA

Last Updated : 22 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

ANOVA, or Analysis of Variance, is a statistical method for comparing means among three or more groups, crucial in understanding group differences and relationships in diverse fields. In this article, we’ll focus on One-way ANOVA.

What is ANOVA?

ANOVA, or Analysis of Variance is a parametric statistical technique that helps in finding out if there is a significant difference between the mean of three or more groups. It checks the impact of various factors by comparing groups (samples) based on their respective mean. ANOVA tests the null hypothesis that all group means are equal, against the alternative hypothesis that at least one group mean is different.

Assumptions for ANOVA

  1. The dependent variable is approximately normally distributed within each group. This assumption is more critical for smaller sample sizes.
  2. The samples are selected at random and should be independent of one another.
  3. All groups have equal standard deviations.
  4. Each data point should belong to one and only one group. There should be no overlap or sharing of data points between groups.

In the case of two-way ANOVA, there are additional assumptions related to the interaction between the independent variables.

  • The effect of one independent variable on the dependent variable should be consistent across all levels of the other independent variable.
  • Combined effect of two independent variables is equal to the sum of their individual effects.

Types of ANOVA

There are two main types of ANOVA:

  1. One-way ANOVA: This is the most basic form of ANOVA and is used when there is only one independent variable with more than two levels or groups. It assesses whether there are any statistically significant differences among the means of the groups.
  2. Two-way ANOVA: Extending the one-way ANOVA, two-way ANOVA involves two independent variables. It allows for the examination of the main effects of each variable as well as the interaction between them. The interaction effect explores whether the effect of one variable on the dependent variable is different depending on the level of the other variable.

How to perform One-Way ANOVA?

It is a type of hypothesis test where only one factor is considered. We use F-statistic to perform a one-way analysis of variance. 

Steps Involved

Step 1 – Define the null and alternative hypothesis.

  • H0 -> μ1 = μ2 = μ3 (where μ = mean)
  • Ha -> At least one difference among the means.

Step 2 – Find the degree of freedom between and within the groups. [Using Eq-1 and Eq-2]

df_{\text{between}}=k-1 \;\;\; \cdots \text{ Equation-1}

df_{\text{within}}=n-k  \;\;\; \cdots \text{ Equation-2}

  • n = number of samples in all groups combined
  • k = number of groups.

Then, find total degree of freedom. [Using Eq-3]

df_{total}=df_{\text{within}}+df_{\text{between}} \;\;\; \cdots \text{ Equation-3}

For the next step, we need to understand what F-statistic is. 

F-value: It is defined as the ratio of the variance between samples to variance within samples. It is obtained while performing ANOVA test.

Eq-4 shows the F-value formula for one-way ANOVA.

F_{value}=\frac{\text{Variance}_{\text{between-samples}}} {\text{Variance}_{\text{within-samples}}} \;\;\; \cdots \text{ Equation-4}

Step 3 – Refer the F-Distribution table and find Ftable using dfbetween and dfwithin.

As per the given F-Distribution table,

df_1 = df_{\text{between}}  \\ df_2 = df_{\text{with in}}

[use the given value of α while referring the table.]

Step 4 – Find the mean of all samples in each group.

Then use Eq-5 to find the Grand mean.
μ_{Grand}=\frac{\sum G}{n} \;\;\; \cdots \text{ Equation-5} )

where,

  • \sum G = sum of all sample values.
  • n = number of samples.

Step 5 – Find the sum of squares total using Eq-6 and sum of squares within using Eq-7.

SS_{Total}= \sum(x_i-\mu_{Grand})^2  \;\;\; \cdots \text{ Equation-6}

SS_{\text{with in}}= \sum(x_i-\mu_{i})^2  \;\;\; \cdots \text{ Equation-7}

where,

  • xi = ith sample.
  • μi = mean of ith group.

Then find sum of squares between using Eq-8.

SS_{\text{between}}=SS_{Total}-SS{\text{with in}}  \;\;\; \cdots \text{ Equation-8}

Step 6 – Find the variance (μ2 or S2) between and within samples using Eq-9 and Eq-10.

S^2_{\text{between}}=\frac{SS_{\text{between}}}{df_{\text{between}}}   \;\;\; \cdots \text{ Equation-9}

S^2_{\text{with in}}=\frac{SS_{\text{with in}}}{df_{\text{with in}}}   \;\;\; \cdots \text{ Equation-10}

Step 7 – Find Fcalc using Eq-11.

F_{calc}=\frac{S^2{\text{between}}}{S^2{\text{with in}}}   \;\;\; \cdots \text{ Equation-11} (Equation-11)

Interpreting the results

  • If Fcalc < Ftable :
    • Don’t reject null hypothesis.
    • i.e \mu_1 = \mu_2 =\mu_3
  • If Fcalc > Ftable :
    • Reject null hypothesis.

One-Way ANOVA Example

Consider the example given below to understand step by step how to perform this test. The marks of 3 subjects (out of 5) for a group of students is recorded. (as given in the table below) 
[Take α = 0.05]

Std/SubEnglish (e)Math (m)Science (s)
Student 1

2

2

1

Student 2

4

3

2

Student 3

2

4

5

Step 1: Define the hypothesis

  • Null hypothesis, H_0 : \mu_E = \mu_M = \mu_S (where μ = mean)
  • Alternate hypothesis,   H_a :\text{At least one difference among the means of the 3 subjects}.

Step 2: Degres of Freedom

As per the table, k = 3, n = 9

df_{between} =k-1= 3 - 1 = 2 \\ df_{within} =n-k= 9 - 3 = 6 \\ df_{total} =df_{between}+df_{within}= 2 + 6 = 8

Step 3 Find the F-value corresponding to Degree of Freedom and alpha

On referring to the F-Distribution table, using df1 = 2 and df2 = 6 at α = 0.05: we get, Ftable = 5.14

Step 4 Compute the mean

\mu_e = (2 + 4 + 2)/3 = (8/3) = 2.67 \\ \mu_m = (2 + 3 + 4)/3 = (9/3) = 3.00 \\ \mu_s = (1 + 2 + 5)/3 = (8/3) = 2.67 \\ \mu_{grand} = (8 + 8 + 9)/9 = (25/9) = 2.78

Step 5 Compute the Sum of Squares

\begin{aligned} SS_{Total}&= \sum(x_i-\mu_{Grand})^2  \\&=(2 - 2.78)^2 + (4 - 2.78)^2 + (2 - 2.78)^2 + (2 - 2.78)^2+ (3 - 2.78)^2+ (4 - 2.78)^2  +(1 - 2.78)^2 + (2 - 2.78)^2 + (5 - 2.78)^2 \\&= 13.60 \end{aligned}

\begin{aligned} SS_{\text{with in}}&= \sum(x_i-\mu_{i})^2  \\&=(2 - 2.67)^2 + (4 - 2.67)^2 + (2 - 2.67)^2 +            (2 - 3.00)^2 + (3 - 3.00)^2 + (4 - 3.00)^2 +            (1 - 2.67)^2 + (2 - 2.67)^2 + (5 - 2.67)^2              \\&= 13.34  \end{aligned}

\begin{aligned} SS_{between} &=SS_{Total}-SS_{within} \\&=13.60 - 13.34  \\&= 0.23 \end{aligned}

Step 6 Find the variance

\begin{aligned} S^2_{\text{between}}&=\frac{SS_{\text{between}}}{df_{\text{between}}} \\&= \frac{0.23}{2}  \\&= 0.115 \approx 0.12 \end{aligned}

\begin{aligned} S^2_{\text{with in}}&=\frac{SS_{\text{with in}}}{df_{\text{with in}}} \\& = \frac{13.34}{6}  \\& = 2.22 \end{aligned}

Step 7 Compute F-statistics

\begin{aligned} F_{calc}&=\frac{S^2{\text{between}}}{S^2{\text{with in}}} \\&= \frac{0.12}{2.22} \\&= 0.05   \end{aligned}

Since, Fcalc < Ftable (0.05 < 5.14)

We cannot reject the null hypothesis.

Thus, we can say that the means of all three subjects is the same.

Conclusion

One-way ANOVA compares three or more than three categorical groups to establish whether there is a difference between them. The fundamental strategy of ANOVA is to systematically examine variability within groups being compared and also examine variability among the groups being compared. For any doubt/query, comment below. 

Frequently Asked Questions (FAQs)

Q. What is ANOVA used for?

It analyzes group variances to test differences in means, commonly applied in comparing group effects.

Q.How to use ANOVA using Python?

In Python, the scipy.stats module provides functions for ANOVA, and libraries like statsmodels offer comprehensive ANOVA capabilities.

Q. What is the role of ANOVA in EDA?

In Exploratory Data Analysis (EDA), ANOVA helps identify significant variations between groups, aiding insights into data patterns.

Q. What is the basic principle of ANOVA?

ANOVA compares means across groups, assessing if observed differences are statistically significant, using variances within and between groups.



Similar Reads

How to set up balanced one-way ANOVA for lm() in R
Balanced one-way Analysis of Variance (ANOVA) is a statistical technique used to compare the means of three or more groups to determine if at least one group's mean is different from the others. In R, this can be achieved using the lm() function, which fits linear models. This article will guide you through setting up a balanced one-way ANOVA using
4 min read
How to Perform a Two-Way ANOVA in Python
Two-Way ANOVA: Two-Way ANOVA in statistics stands for Analysis of Variance and it is used to check whether there is a statistically significant difference between the mean value of three or more that has been divided into two factors. In simple words, ANOVA is a test conducted in statistics and it is used to interpret the difference between the mea
3 min read
How to Perform a Three-Way ANOVA in R
Analysis of Variance (ANOVA) is a powerful statistical technique used to compare means across multiple groups. A Three-Way ANOVA extends this analysis to investigate the interaction effects between three categorical variables on a continuous outcome variable. In this detailed guide, we will walk through the process of performing a Three-Way ANOVA i
5 min read
What is the Non-Parametric Equivalent of a Two-Way ANOVA in R?
In statistical analysis, when dealing with data that does not meet the assumptions required for parametric tests like the Two-Way ANOVA, researchers often turn to non-parametric equivalents. These alternatives do not assume normality or homogeneity of variances and are more flexible for various types of data. This article explores the non-parametri
4 min read
How to Perform Welch’s ANOVA in Python
When the assumption of equal variances is violated, Welch's ANOVA is used as an alternative to the standard one-way ANOVA. A one-way ANOVA ("analysis of variance") is used to see if there is a statistically significant difference in the means of three or more independent groups. Steps to perform Welch's ANOVA : Step 1: Create a Pandas Data frame to
3 min read
Regression vs ANOVA
ANOVA and Regression have distinct objectives. Whereas regression employs a binary response variable to predict the category, ANOVA generates a continuous response variable to anticipate its value. In this article, let's understand the difference between regression and ANOVA. What is Regression? Regression is a statistical method that measures the
4 min read
When to use aov() vs. anova() in R
In R Programming Language aov() stands for analysis of variance. It is used to analyze variance. Variance is a statistical technique to compare means among two or more groups. anova() function is used to perform analysis of variance calculation and hypothesis testing. Together both aov() and anova() are used to analyze variance tests in the R Progr
6 min read
ANOVA vs multiple linear regression?
In the realm of statistical analysis, ANOVA (Analysis of Variance) and multiple linear regression are two powerful techniques used to examine relationships within data. Although they share similarities, such as dealing with variance and multiple predictors, their applications and interpretations differ significantly. This article delves into the co
4 min read
How Does Do a Type-III SS ANOVA in R with Contrast Codes?
Performing a Type-III sum of squares (SS) ANOVA in R with contrast codes is crucial for analyzing data, especially when dealing with unbalanced designs or specific hypotheses about factor levels. This guide will walk through what Type-III SS ANOVA is, how to prepare data, different contrast codes, using the car package for Type-III SS ANOVA, interp
4 min read
What is Descriptive Analytics and how does it summarize past data in a simple way?
The term Analytics means analyzing the patterns or the trends of the data. Since data comprises patterns it is important to analyze them so that the companies can harness the results to gain profit. The term descriptive means description. In this article, we will discuss What is Descriptive analytics, the Tools used for Descriptive analytics, how t
6 min read
Practice Tags :