Why ANOVA
If you compare 3+ groups with many t-tests, you increase false positives.
ANOVA tests:
- H0: all group means are equal
- H1: at least one mean differs
Example
import numpy as np
from scipy import stats
A = np.array([10, 12, 11, 13, 12])
B = np.array([7, 8, 9, 8, 7])
C = np.array([14, 15, 13, 16, 14])
f_stat, p = stats.f_oneway(A, B, C)
print("F:", f_stat)
print("p:", p)If ANOVA is significant
ANOVA says “some difference exists” but not where.
Next steps:
- Post-hoc tests (e.g., Tukey HSD)
- Pairwise comparisons with correction
Assumptions
- Independence
- Normality within groups (approx)
- Homogeneity of variances
If variances differ a lot, consider Welch ANOVA or non-parametric alternatives.
Why not just run many t-tests?
flowchart TD A["3+ groups to compare"] --> B["Many pairwise t-tests"] A --> C["One-way ANOVA"] B --> D["False positive rate
compounds with each test"] C --> E["Single F-test:
any group differ?"] E --> F["If significant,
run post-hoc tests"]
Check your understanding
What is the null hypothesis of one-way ANOVA?
H0 says all group means are equal and H1 says at least one differs.
Show answer
B — All group means are equal — H0 says all group means are equal and H1 says at least one differs.
Why not run many t-tests for three or more groups?
Each extra test adds a chance of a false positive, which ANOVA avoids with a single test.
Show answer
B — Many tests increase false positives — Each extra test adds a chance of a false positive, which ANOVA avoids with a single test.
ANOVA on groups A, B and C gives a small p-value. What do you know?
ANOVA does not say where the difference is. Follow with post-hoc tests such as Tukey HSD or corrected pairwise comparisons.
Show answer
B — Some difference exists, but not where — ANOVA does not say where the difference is. Follow with post-hoc tests such as Tukey HSD or corrected pairwise comparisons.
Which scipy function runs the one-way ANOVA in the lesson?
stats.f_oneway(A, B, C) returns the F statistic and p-value.
Show answer
D — stats.f_oneway — stats.f_oneway(A, B, C) returns the F statistic and p-value.
🧪 Try It Yourself
Exercise 1 – Run a one-way ANOVA
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Reading the result
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Group means and variances
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Next
Continue to Chi-Square Test to compare categorical variables instead of numeric means.