The Logic: Partitioning Variability

The key insight behind ANOVA is that total variability in your data can be split into two parts:

  • Variability between groups — how much do the group means differ from the overall mean?
  • Variability within groups — how much do individual observations vary from their own group mean?

If between-group variability is large compared to within-group variability, that's evidence the groups really differ. If between-group variability is small relative to within-group, you can't distinguish group differences from random noise.

Three Sums of Squares

Sum of Squares Total (SST): Total variability around the grand mean.

SST=i=1n(yiyˉ)2\text{SST} = \sum_{i=1}^{n}(y_i - \bar{y})^2

Sum of Squares Between (SSB): Variability of group means around the grand mean.

SSB=j=1knj(yˉjyˉ)2\text{SSB} = \sum_{j=1}^{k} n_j(\bar{y}_j - \bar{y})^2

Sum of Squares Within (SSW): Variability within each group around its own mean.

SSW=j=1ki=1nj(yijyˉj)2\text{SSW} = \sum_{j=1}^{k}\sum_{i=1}^{n_j}(y_{ij} - \bar{y}_j)^2

These three quantities satisfy: SST = SSB + SSW.

The F-Statistic

The F-statistic compares between-group and within-group variability, normalized by degrees of freedom:

F=SSB/(k1)SSW/(nk)F = \frac{\text{SSB}/(k-1)}{\text{SSW}/(n-k)}

A large F means between-group variability dominates within-group variability — evidence against the null. If p ≤ α, reject the null: at least one group mean differs.


In Python: scipy.stats.f_oneway(group1, group2, group3, ...)

ANOVA Variance Partitioner
Group distributions
Group AGroup BGroup Cgrand mean

Vertical colored bars = group means. Dashed line = grand mean. Brackets show between-group distance.

Group A
Mean40
Spread5
Group B
Mean50
Spread5
Group C
Mean60
Spread5
Variance decomposition (SST = SSB + SSW)
SSB 87%SSW 13%
ANOVA Table
SourceSSdfMS
Between groups (SSB)2400.021200.00
Within groups (SSW)354.53310.74
Total (SST)2754.535
F-statistic
111.692
MSB / MSW = 1200.00 / 10.74
p-value
< 0.001
Reject H₀ — means differ
Group AGroup BGroup CGrand mean

Adjust the means and spreads of three groups. See SSB, SSW, and the F-statistic update in real time. Observe how group separation relative to within-group spread determines F.

Checkpoint

You run a one-way ANOVA comparing three ML models on the same metric and get F = 0.8, p = 0.46. What can you conclude?