One-Way ANOVA
Compare means across multiple groups using Analysis of Variance
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 ). With three tests:
- Probability of at least one false positive
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:
Group 2:
Group 3:
Grand Mean:
Visualizing the Data
The dot plot shows all individual data points colored by group:
Group Data Points
Group Data Points
Hypotheses
- Null Hypothesis (): All group means are equal:
- Alternative Hypothesis (): 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:
With observations per group, each squared gap between a group mean and the grand mean counts three times:
Step 2: Sum of Squares Within (SSW)
SSW measures variability within each group:
Where SSB and SSW Come From
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 is large.
Total Sum of Squares
Variance Decomposition
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:
- Within-group df:
Step 4: The F-Statistic
The F-statistic is the ratio of between-group variance to within-group variance:
Under , this ratio follows an F-distribution with and .
Making the Decision
Significance level:
At with and :
Critical value:
F-Distribution Under H0
Decision Rule: Reject if
Result: Reject
Since , we reject the null hypothesis.
There is statistically significant evidence at that at least one group mean differs from the others.
Effect Size: Eta-Squared ()
Beyond statistical significance, we want to know the practical significance. Eta-squared measures the proportion of total variance explained by group membership:
This means
| Interpretation | |
|---|---|
| 0.01 | Small effect |
| 0.06 | Medium effect |
| 0.14 | Large effect |
Your effect size of
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
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
Understanding Bayes' Theorem
Explore how prior beliefs update with new evidence
Bayesian Inference
Explore how prior beliefs combine with observed data to form posterior distributions using Bayes' theorem
Bootstrap Confidence Intervals
Learn how resampling provides confidence intervals without parametric assumptions
Chi-Square Goodness of Fit Test
Test whether observed frequencies match expected frequencies using the chi-square goodness of fit test
You might also like
Normal Distribution Calculator
Calculate z-scores and convert between z-scores and raw values
Chi-Square Goodness of Fit Test
ExplorationTest whether observed frequencies match expected frequencies using the chi-square goodness of fit test
Hypothesis Testing Explorer
ExplorationVisualize and understand hypothesis testing with the one-sample z-test
Hypothesis Testing with t-Tests
ExplorationMaster one-sample and two-sample t-tests for comparing means when population variance is unknown