ANOVA (Analysis of Variance) › The Mathematics of One-Way ANOVA
Machine Learning from ScratchAll chapters ANOVA (Analysis of Variance) › The Mathematics of One-Way ANOVAOne section · Sections in this chapter4 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's formalize these ideas mathematically. One-way ANOVA compares means across groups, where "one-way" means there's a single grouping factor.
Notation
- = number of groups
- = sample size of group (for )
- = total sample size
- = observation in group
- = mean of group
- = grand mean (overall mean)
The ANOVA Decomposition
The total variation in the data can be decomposed into two components:
Let's understand each component:
Total Sum of Squares (): Measures total variation in the data. Each observation's squared deviation from the grand mean, summed across all observations. This is the same quantity we'd use to compute variance of the entire dataset.
Between-Group Sum of Squares (): Measures variation of group means around the grand mean. Each group mean's squared deviation from the grand mean, weighted by sample size. Larger groups contribute more because their means are more reliable.
Within-Group Sum of Squares (): Measures variation within each group. Each observation's squared deviation from its own group mean, summed across all groups. This represents the "noise" or baseline variability.
From Sums of Squares to Mean Squares
Sums of squares grow with sample size, so we convert them to mean squares (variance estimates) by dividing by degrees of freedom:
Why these degrees of freedom?
- Between-groups (): We have group means, but they must average to the grand mean (one constraint), leaving independent pieces of information.
- Within-groups (): We have observations, but we estimate group means (one per group), losing degrees of freedom.
The F-Statistic
The F-statistic is the ratio of mean squares:
Under the null hypothesis that all population means are equal (), this F-statistic follows an F-distribution with and degrees of freedom.
Intuition:
- estimates (the common variance within groups) regardless of whether the null is true
- estimates only if the null is true; if means differ, it estimates something larger
- If is true, ; if is false,
The Hypotheses
Null hypothesis: (all population means are equal)
Alternative hypothesis: At least one population mean differs from the others
Note that rejecting tells us that some means differ, but not which ones. For that, we need post-hoc tests (discussed later).