ANOVA (Analysis of Variance)
Compare means across multiple groups and follow up with post-hoc contrasts carefully.
In plain words
ANOVA checks whether three or more groups have different averages by comparing how different the groups are from each other with how different people are within each group.
Think of it like…
Judging whether three classes' exam scores really differ: if the class averages are far apart relative to how much scores vary inside each class, the classes differ; if each class's own spread is as large as the gaps between class averages, the gaps could just be noise.
Where you’ve seen it
Three checkout page designs are tested on 30 users each (N = 90) with time-to-purchase as the outcome. The one-way ANOVA gives F(2, 87) = 5.1, p ≈ 0.008: not all means are equal. Effect size η² = SS_between / SS_total = (2 × 5.1) / (2 × 5.1 + 87) ≈ 0.105, so about 10% of the variance in time is associated with design. Tukey's HSD then shows that design C differs from A (adjusted p = 0.006) while B is not distinguishable from either, which tells the team to prefer C over A but not that C beats B.
Words you’ll hear
- F statistic
- Ratio of between-group to within-group mean squares; large F suggests real differences.
- Degrees of freedom
- k − 1 between groups and N − k within, for k groups and N observations.
- Post-hoc test
- Pairwise comparisons after a significant ANOVA with multiplicity control (Tukey HSD).
- η² (eta squared)
- Share of total variance explained by group membership.
Visual diagram
Theory & deep dive
How one-way ANOVA works
Total variation SS_total splits into SS_between (how far group means lie from the grand mean, weighted by group size) and SS_within (how far observations lie from their own group mean). Dividing by degrees of freedom gives mean squares: MS_between = SS_between / (k − 1) and MS_within = SS_within / (N − k). If all group means are equal, both estimate the same noise variance and F ≈ 1; if means differ, MS_between grows and F becomes large. The p-value comes from the F distribution with (k − 1, N − k) degrees of freedom. With two groups, ANOVA's F equals the square of the pooled t statistic.
In Python: stats.f_oneway(a, b, c) for the one-way test, or statsmodels (ols("time ~ C(design)", data=df).fit() followed by anova_lm) for tables and extensions such as two-way ANOVA with interactions. Report F with both degrees of freedom, the p-value and an effect size (η² or partial η²).
F, p = stats.f_oneway(times_a, times_b, times_c) returns F ≈ 5.1 and p ≈ 0.008 for the page-design data; pg.anova or statsmodels also give η².
Assumptions, post-hoc tests and alternatives
ANOVA assumes independent observations, approximately normal residuals within groups (fairly robust with balanced groups and moderate n) and equal variances (check with Levene's test or look at group standard deviations). With unequal variances use Welch's ANOVA; with heavy skew, outliers or ordinal outcomes use Kruskal-Wallis (stats.kruskal). Repeated measures on the same users need repeated-measures ANOVA or a mixed model, and several factors (design × device) need two-way ANOVA, where interactions (the design effect differs by device) are often the interesting part.
A significant F only says that not all means are equal. To learn which pairs differ, run a post-hoc procedure that controls the family-wise error rate: Tukey's HSD (statsmodels.stats.multicomp.pairwise_tukeyhsd) for all pairwise comparisons, Dunnett's test when comparing every group with a control, or Bonferroni/Holm-adjusted t-tests. If the overall F is not significant, don't go hunting for pairwise differences. Plan comparisons in advance when possible (planned contrasts are more powerful), and interpret in terms of effect sizes and confidence intervals for differences, not just p-values.
print(pairwise_tukeyhsd(df.time, df.design)) lists mean differences, adjusted p-values and CIs for A–B, A–C and B–C, flagging A–C as the only significant pair at α = 0.05.
How it works, step by step
Step 1 of 41. Frame the comparison
Confirm you have one numeric outcome and three or more independent groups; list planned comparisons.
- Paired?
- use repeated measures
When to use it & trade-offs
What it is
ANOVA (analysis of variance) tests whether the means of three or more groups are all equal. It compares the variation between group means with the variation within groups: F = MS_between / MS_within. A large F (small p-value) says at least one mean differs, but not which ones; post-hoc tests (Tukey's HSD, Bonferroni-adjusted t-tests) then identify the differing pairs while controlling the false-positive rate. Assumptions: independent observations, roughly normal residuals and similar variances across groups (check with Levene's test); alternatives include Welch's ANOVA and the rank-based Kruskal-Wallis test.
Why it matters: Comparing three variants of a page, four regions, or five customer segments with repeated pairwise t-tests inflates false positives: three comparisons at α = 0.05 give a 1 − 0.95³ ≈ 14% chance of a spurious finding. ANOVA answers the overall question once, at the right error rate, and its framework extends to regression with categorical predictors and to experiments with several factors. Interpreting it correctly (including effect size and post-hoc follow-up) is a standard analytics skill.
When to reach for it
- Comparing several page or pricing variants
- Comparing metrics across regions or segments
- Quality control across machines or batches
When to avoid or be careful
- Many unadjusted pairwise t-tests
- Post-hoc comparisons after a non-significant F
- Ignoring unequal variances and group sizes
Comparing several groups
Strengths: One test at the right error rate; extends to regression.
Watch out: Says only that some means differ.
Strengths: Robust to assumption violations.
Watch out: Less power if ANOVA assumptions actually hold.
Strengths: Simple.
Watch out: Inflates false positives (14% with 3 comparisons).
Interview signals & numbers to know
When this topic comes up
- “Compare three or more groups”
- “F-test”
- “Post-hoc tests”
- Kruskal-Wallis
- Interaction effects
Benchmarks & rules of thumb
- k − 1 and N − k
- ANOVA degrees of freedom (2 and 87)
- ≈ 14%
- false-positive chance with 3 unadjusted comparisons
- ≈ 0.10
- η² in the example
Common mistakes & follow-ups
Common interview mistakes
- Running three separate t-tests and reporting each at α = 0.05.
- Concluding "all designs differ" from a significant F.
- Using Student's ANOVA with wildly different group variances and sizes.
Likely interviewer follow-ups
- Why not just use several t-tests?
- What does a significant ANOVA tell you, and what doesn't it?
- What would you do if the variances are unequal?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply ANOVA (Analysis of Variance) with data science interview Q&A and hands-on practice.