One-Way ANOVA

Compare means across multiple groups using Analysis of Variance

Calculate

Try these examples:

One-Way ANOVA: Comparing Multiple Group Means

Analysis of Variance (ANOVA) is a statistical method for comparing means across multiple groups simultaneously. While a t-test compares two groups, ANOVA can compare three, four, or more groups at once.

Why Not Just Use Multiple t-Tests?

Suppose you want to compare three treatment groups. You might think: "I'll just run three t-tests comparing Group 1 vs 2, Group 1 vs 3, and Group 2 vs 3."

The problem: Each test has a 5% chance of false positive (at α=0.05\alpha = 0.05). With three tests:

  • Probability of at least one false positive ≈1−(0.95)3=14.3%\approx 1 - (0.95)^3 = 14.3\%

This multiple comparisons problem inflates your Type I error rate. ANOVA solves this by testing all groups simultaneously with a single test.

The Key Insight

ANOVA compares two sources of variation:

  • Between-group variance: How much do group means differ from the grand mean?
  • Within-group variance: How much do individual observations vary within each group?

If all groups have the same true mean, the between-group variance should be similar to the within-group variance. A large ratio suggests the groups truly differ.

Your Data

Enter values for three groups (3 observations each):

Group 1: 5, 6, 7 xˉ1=\quad\bar{x}_1 = 6

Group 2: 10, 11, 12 xˉ2=\quad\bar{x}_2 = 11

Group 3: 15, 16, 17 xˉ3=\quad\bar{x}_3 = 16

Grand Mean: xˉ=\bar{x} = 11

Visualizing the Data

The dot plot shows all individual data points colored by group:

Group Data Points

Group Data Points

23.85.67.49.21112.814.616.418.220MeanMeanMean
Group 1Mean: 6
Group 2Mean: 11
Group 3Mean: 16

Hypotheses

  • Null Hypothesis (H0H_0): All group means are equal: μ1=μ2=μ3\mu_1 = \mu_2 = \mu_3
  • Alternative Hypothesis (H1H_1): At least one group mean differs from the others

Computing the ANOVA

Step 1: Sum of Squares Between (SSB)

SSB measures variability between group means:

SSB=∑i=1kni(xˉi−xˉ)2SSB = \sum_{i=1}^{k} n_i (\bar{x}_i - \bar{x})^2

With n=3n = 3 observations per group, each squared gap between a group mean and the grand mean counts three times:

SSB=3×[0+0+0]=0SSB = 3 \times [{\cmv{computed}{dev1Squared}} + {\cmv{computed}{dev2Squared}} + {\cmv{computed}{dev3Squared}}] = {\cmv{computed}{ssb}}

Step 2: Sum of Squares Within (SSW)

SSW measures variability within each group:

SSW=∑i=1k∑j=1ni(xij−xˉi)2=0SSW = \sum_{i=1}^{k} \sum_{j=1}^{n_i} (x_{ij} - \bar{x}_i)^2 = {\cmv{computed}{ssw}}

Where SSB and SSW Come From

Grand mean51015123ValueGroup

The short ticks mark the group means and the dashed line the grand mean. Each thin line runs from a value to its group mean: squared and added up, these give SSW. Each thick line under a row runs from that group's mean to the grand mean: squared, counted once for each of the group's 3 values and added up, these give SSB. When the thick lines are long next to the thin ones, the groups differ by more than their own scatter, and FF is large.

Total Sum of Squares

SST=SSB+SSW=0+0=0SST = SSB + SSW = {\cmv{computed}{ssb}} + {\cmv{computed}{ssw}} = {\cmv{computed}{sst}}

Variance Decomposition

Between-Group (SSB)150.00
6.00Within-Group (SSW)
96%
Ratio: 150.00 : 6.00(1 : 0.04)

The ratio bar above shows how total variance is partitioned. When groups are truly different, SSB will be large relative to SSW.

Step 3: Degrees of Freedom and Mean Squares

We divide by degrees of freedom to get unbiased variance estimates:

  • Between-group df: df1=k−1=3−1=2df_1 = k - 1 = 3 - 1 = 2
  • Within-group df: df2=N−k=9−3=0df_2 = N - k = 9 - 3 = {\cmv{computed}{dfWithin}}
MSB=SSBdf1=02=0MSB = \frac{SSB}{df_1} = \frac{{\cmv{computed}{ssb}}}{2} = {\cmv{computed}{msb}} MSW=SSWdf2=00=0MSW = \frac{SSW}{df_2} = \frac{{\cmv{computed}{ssw}}}{{\cmv{computed}{dfWithin}}} = {\cmv{computed}{msw}}

Step 4: The F-Statistic

The F-statistic is the ratio of between-group variance to within-group variance:

F=MSBMSW=00=0F = \frac{MSB}{MSW} = \frac{{\cmv{computed}{msb}}}{{\cmv{computed}{msw}}} = {\cmv{computed}{fStatistic}}

Under H0H_0, this ratio follows an F-distribution with df1=2df_1 = 2 and df2=0df_2 = {\cmv{computed}{dfWithin}}.

Making the Decision

Significance level: α=\alpha = 0.05

At α=0\alpha = {\cmv{computed}{alpha}} with df1=2df_1 = 2 and df2=0df_2 = {\cmv{computed}{dfWithin}}:

Critical value: Fcritical=F_{critical} = 5.1433

F-Distribution Under H0

020406080F-statisticReject H0F-statistic = 75F-critical = 5.1

Decision Rule: Reject H0H_0 if F>FcriticalF > F_{critical}

Result: Reject H0H_0

Since F=0>0=FcriticalF = {\cmv{computed}{fStatistic}} > {\cmv{computed}{fCritical}} = F_{critical}, we reject the null hypothesis.

There is statistically significant evidence at α=0\alpha = {\cmv{computed}{alpha}} that at least one group mean differs from the others.

Effect Size: Eta-Squared (η2\eta^2)

Beyond statistical significance, we want to know the practical significance. Eta-squared measures the proportion of total variance explained by group membership:

η2=SSBSST=00=0\eta^2 = \frac{SSB}{SST} = \frac{{\cmv{computed}{ssb}}}{{\cmv{computed}{sst}}} = {\cmv{computed}{etaSquared}}

This means 96.15% of the total variance is explained by group differences.

η2\eta^2Interpretation
0.01Small effect
0.06Medium effect
0.14Large effect

Your effect size of 0.9615 indicates a large effect.

What Happens Next?

A significant F-test tells us that at least one group mean differs, but not which groups differ from each other. Post-hoc tests such as Tukey's HSD or Bonferroni correction identify the specific pairs. ANOVA also assumes independence, approximate normality within each group, and similar variances across groups.

Try widening the gap between groups -- set Group 1 values to 5, 6, 7 and Group 3 values to 15, 16, 17 -- and watch how the F-statistic (75) and η2\eta^2 (0.9615) respond. A larger spread between group means increases the between-group variance relative to the within-group variance. You can also tighten the significance level with α=\alpha = 0.05 to see how the critical value (5.1433) shifts on the F-distribution above.

Try it in Code

# One-Way ANOVA with three groups
import numpy as np
from scipy import stats

group1 = [5, 6, 7]
group2 = [10, 11, 12]
group3 = [15, 16, 17]

f_stat, p_value = stats.f_oneway(group1, group2, group3)
print(f"F-statistic: {f_stat:.4f}")
print(f"P-value: {p_value:.4f}")

# Effect size (eta-squared)
all_data = group1 + group2 + group3
grand_mean = np.mean(all_data)
ssb = 3 * sum((np.mean(g) - grand_mean)**2 for g in [group1, group2, group3])
sst = sum((x - grand_mean)**2 for x in all_data)
print(f"Eta-squared: {ssb / sst:.4f}")

What to explore next

You might also like