ANOVA (one-way)
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
One-way ANOVA
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)One-way ANOVA
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"]
🧪 Try It Yourself
Exercise 1 – Run a one-way ANOVA
Exercise 2 – Reading the result
Exercise 3 – Group means and variances
Next
Continue to Chi-Square Test to compare categorical variables instead of numeric means.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
