Quick answers
- What is ANOVA?
- A test of whether the means of three or more groups differ, by comparing the variation between groups with the variation within them. A large ratio (F) means the groups differ more than chance would explain.
- What does the F value mean in ANOVA?
- F = mean square for treatments ÷ mean square for error. Near 1, treatment differences are no bigger than random noise; much larger than 1, they are. Its p value comes from the F distribution.
- What are the assumptions of ANOVA?
- Independent experimental units, normally distributed residuals, and equal variances across groups (homogeneity of variance). Check residuals with a Q-Q plot and Levene's test.
- What does a significant ANOVA tell you?
- That at least one mean differs from the others. It does not say which; for that you need post hoc tests or planned contrasts.
- What is the difference between one-way ANOVA and a CRD?
- They are the same analysis seen from two sides: a completely randomized design (CRD) is the experiment, and one-way ANOVA is how you analyze it.
- What is the non-parametric alternative to ANOVA?
- The Kruskal-Wallis test, which compares groups using ranks. Follow it with Dunn's test for pairwise comparisons.
On this page
The idea: splitting variation
Why "analysis of variance" when we compare means? Because the way to tell whether diets differ is to compare two kinds of variation. If diets have no effect, the diet means differ only by chance, and the spread between them matches what the pig-to-pig variation predicts. If diets matter, the means are more spread out than chance allows.
Total SS = Treatment SS + Error SS
- Total sum of squares: each value's squared distance from the grand mean.
- Treatment (between-group) SS: each group mean's squared distance from the grand mean, times the group size.
- Error (within-group, residual) SS: each value's squared distance from its own group mean.
Dividing each SS by its degrees of freedom gives a mean square (a variance). F is the ratio of the treatment mean square to the error mean square.
One-way ANOVA, step by step
The model for a completely randomized design (CRD) with t treatments:
yᵢⱼ = μ + τᵢ + εᵢⱼ
where μ is the overall mean, τᵢ the effect of treatment i, and εᵢⱼ the random error of unit j. H₀: all τᵢ = 0 (all means equal); H₁: at least one differs.
The error mean square (MSE) is the pooled within-group variance, the best estimate of the noise, and it is reused everywhere afterward: in standard errors of means (√(MSE / r)), in post hoc tests and in the experiment CV.
Assumptions of ANOVA and how to check them
| Assumption | How to check | Pig trial |
|---|---|---|
| Independence | Design: one treatment per experimental unit, randomized | Each pig fed individually and randomized: met |
| Normal residuals | Q-Q plot of residuals; Shapiro-Wilk test | W = 0.955, p = 0.35: met |
| Equal variances | Residuals vs fitted plot; Levene's (Brown-Forsythe) test | SDs 0.076 to 0.092; Levene p = 0.94: met |
- Independence is the assumption that matters most, and only the design can guarantee it. Pseudoreplication breaks it.
- ANOVA is fairly robust to mild non-normality, especially with equal group sizes.
- Unequal variances are more serious with unequal group sizes. Remedies: transform, use Welch's ANOVA, or model the variances in a mixed model.
- Levene's test with the median (the Brown-Forsythe-Levene test) is preferred over Bartlett's or Hartley's F-max, which are very sensitive to non-normality.
When assumptions fail: Kruskal-Wallis
The Kruskal-Wallis test ranks all observations together and compares the average rank of each group. It extends the Mann-Whitney test to three or more groups and suits ordinal scores or clearly non-normal data.
Follow a significant Kruskal-Wallis test with Dunn's test. Kruskal-Wallis cannot handle blocks or factorials; for counts and proportions, a generalized linear model keeps the design in the analysis.
Analyze as designed: adding the litters
The one-way ANOVA treated the pigs as if diets had been assigned at random to all 24. They were not: the trial was a randomized complete block design (RCBD), with each litter receiving every diet once. Litter must be in the model:
yᵢⱼ = μ + τᵢ + βⱼ + εᵢⱼ, where βⱼ is the effect of litter j
That is the payoff of blocking, and the reason for the rule analyze as designed. Ignoring blocks wastes power; ignoring split-plots or repeated measures does worse, giving p values that are too small. Two-way ANOVA and mixed models pick this up.
Fixed and random effects, in brief
Diets are fixed effects: you chose these four on purpose and want to compare them. Litters can be treated as random effects: a sample from all possible litters, of interest only through how much they vary. With balanced data like these the diet test is the same either way; the distinction matters for unbalanced data, for standard errors of means, and for split-plot and repeated-measures designs. See mixed models.
ANOVA in R, SAS and aStat
In R
dat$diet <- factor(dat$diet); dat$litter <- factor(dat$litter)
anova(lm(adg ~ diet, data = dat)) # one-way (CRD)
anova(lm(adg ~ litter + diet, data = dat)) # RCBD, as designed
car::leveneTest(adg ~ diet, data = dat) # equal variances
kruskal.test(adg ~ diet, data = dat)In SAS
proc glm data=pigs;
class litter diet;
model adg = litter diet;
means diet / hovtest=bf; /* Brown-Forsythe-Levene, from a one-way model */
run;
proc npar1way data=pigs wilcoxon;
class diet;
var adg;
run;The free ANOVA Calculator runs one-way (CRD), RCBD and two-way ANOVA in your browser, with assumption checks, post hoc letters and the R script.
Key takeaways
- ANOVA splits total variation into treatment and error parts; F = treatment MS ÷ error MS.
- A significant F says at least one mean differs; post hoc tests or contrasts say which.
- Check independence (design), normal residuals and equal variances; Kruskal-Wallis is the rank alternative.
- One-way ANOVA is the analysis of a CRD; a blocked trial must be analyzed with its blocks.
- In the pig trial, adding litters cut the CV from 9.4% to 5.4% and p from 0.022 to 0.0003.
Questions people ask
Can I use ANOVA for two groups?
Yes. With two groups, one-way ANOVA gives exactly the same p value as the pooled t-test, and F = t².
What if my ANOVA is not significant but one pair looks different?
Be cautious. Testing pairs after a non-significant F inflates false positives, unless the comparison was planned in advance as a contrast.
What is a mean square?
A sum of squares divided by its degrees of freedom: a variance estimate. The error mean square estimates the variance among units treated alike.
Does ANOVA need equal group sizes?
No, but equal sizes make it more robust to unequal variances and simplify interpretation. With unequal sizes in factorials, use least squares means; see the two-way ANOVA chapter.
What is eta squared?
η² = treatment SS ÷ total SS: the share of variation explained by the treatment, an effect size for ANOVA.
Sources
- Kaps, M., and Lamberson, W. R. (2017). Biostatistics for Animal Science (3rd ed.), chapters on fixed effects one-way analysis of variance and blocking. CABI.
- Gomez, K. A., and Gomez, A. A. (1984). Statistical Procedures for Agricultural Research (2nd ed.), chapter 2. Wiley.
- Brown, M. B., and Forsythe, A. B. (1974). Robust tests for the equality of variances. Journal of the American Statistical Association, 69, 364–367.