Chapter 15 of 22 Statistics guide · Part 4: Analyzing your data

Two-Way ANOVA and Factorial Experiments: Interaction, Blocks, Latin Squares and Unbalanced Data

Most trials study more than one factor: diet and sex, variety and nitrogen. Two-way ANOVA tests each factor and, most importantly, whether they interact. This chapter covers factorial experiments, interaction, block designs (RCBD, Latin square, incomplete blocks), and what to do when data are unbalanced: least squares means and Type I vs Type III sums of squares.

  • Plant and animal examples
  • Worked by hand and in R
  • Sources cited
  • Free tools to try it

Quick answers

What is a two-way ANOVA?
An ANOVA with two factors, such as diet and sex. It tests the main effect of each factor and their interaction, all from one experiment.
What is an interaction effect?
When the effect of one factor depends on the level of the other. In the wheat trial, extra nitrogen raised yield more for Variety 2 than for Variety 1.
What is a factorial design?
An experiment that tests every combination of the levels of two or more factors: 4 diets × 2 sexes = 8 treatment combinations. Written as a 4 × 2 factorial.
What is the difference between two-way ANOVA and RCBD?
An RCBD is analyzed as a two-way ANOVA without interaction: treatment plus block. In a factorial both factors are treatments, and their interaction is tested.
What should I do if the interaction is significant?
Interpret the factors together: compare one factor within each level of the other (simple effects) and plot the cell means. Main effects alone can mislead.
What are least squares means?
Means adjusted for the other terms in the model, as if the data were balanced. With missing data they are fairer than raw means.
On this page
  1. Quick answers
  2. Factorial experiments
  3. Interaction: when one factor changes the effect of another
  4. Block designs: RCBD, Latin square and incomplete blocks
  5. Unbalanced data, least squares means and Type I vs Type III
  6. Two-way ANOVA in R and SAS
  7. Key takeaways
  8. Questions people ask
  9. Sources

Factorial experiments

A factorial experiment tests all combinations of two or more factors. It is more efficient than separate one-factor trials, because every unit gives information on every factor, and it is the only way to discover interactions. Factors can be any mix: a 2 × 2 (two drugs × two diets), a 2 × 5 (two varieties × five nitrogen rates), or 2ᵏ designs that screen k factors at two levels each.

yᵢⱼₖ = μ + αᵢ + βⱼ + (αβ)ᵢⱼ + εᵢⱼₖ

αᵢ and βⱼ are the main effects of the two factors, and (αβ)ᵢⱼ is their interaction.

Interaction: when one factor changes the effect of another

An interaction means the lines on an interaction plot (response against one factor, one line per level of the other) are not parallel. Its two forms matter differently:

  • Quantitative interaction: the effect changes in size but not direction. Main effects still make some sense.
  • Qualitative (crossover) interaction: the ranking reverses. One variety wins at low nitrogen, the other at high. Main effects are then meaningless on their own.

When the interaction is significant, test simple effects (variety at each N rate, or the N response within each variety) and report cell means. When it is not, report main-effect means.

Block designs: RCBD, Latin square and incomplete blocks

Blocks are a second classification that is not a treatment. Their analysis is a two-way ANOVA without the interaction:

DesignModelUse when
RCBDy = μ + block + treatment + εOne known source of variation: litters, field gradients, days
Latin squarey = μ + row + column + treatment + εTwo crossing sources: field rows and columns; cows and periods
Balanced incomplete block (BIBD)y = μ + block + treatment + ε (treatment means adjusted)Blocks too small for all treatments: litters of 3 with 4 diets
Factorial in an RCBDy = μ + block + A + B + A×B + εTwo treatment factors, one blocking factor

The block × treatment interaction is the error term in an RCBD with one unit per treatment per block, which is why it is not tested. In a Latin square, each treatment appears once in every row and every column; with t treatments you need t² units, which keeps squares small (4 × 4 to 8 × 8). In incomplete block designs, treatment means must be adjusted for the blocks they happened to appear in, so report least squares means. The layouts of each design are drawn in experimental design, and Plan a study randomizes them for you.

Unbalanced data, least squares means and Type I vs Type III

Data are balanced when every treatment (and treatment × block cell) has the same number of observations. Animals die, plots flood, records go missing, and then the factors become partly confounded: raw means and sequential sums of squares start to mislead.

  • Type I (sequential) sums of squares test each term after those listed before it; the order changes the answer with unbalanced data. Diet entered first: F = 5.69, p = 0.010.
  • Type III (partial) sums of squares test each term after all others. Diet adjusted for litter: F = 7.95, p = 0.003. This is the one to report for treatments in unbalanced designed experiments.
  • Type II is a middle ground used in some R packages; it equals Type III when there is no interaction in the model.

With empty cells (a treatment missing from a block entirely), some means are not estimable; a mixed model with random blocks handles missing data best.

Two-way ANOVA in R and SAS

In R

anova(lm(adg ~ diet * sex, data = dat))            # factorial with interaction
interaction.plot(dat$diet, dat$sex, dat$adg)
fit <- lm(adg ~ litter + diet, data = dat)
car::Anova(fit, type = 3)                           # Type III tests (set contr.sum for factorials)
emmeans::emmeans(fit, "diet")                       # least squares means

In SAS

proc glm data=pigs;
  class diet sex;
  model adg = diet sex diet*sex;      /* SS1 and SS3 printed */
  lsmeans diet*sex / slice=sex;       /* simple effects of diet within sex */
run;
proc glimmix data=pigs;
  class litter diet;
  model adg = litter diet;
  lsmeans diet / adjust=tukey lines;
run;

Key takeaways

  • Factorial experiments test every combination of factors and are the only way to detect interactions.
  • Check the interaction first; if it is significant, interpret simple effects and cell means.
  • An RCBD is a two-way ANOVA of treatment plus block, without interaction; Latin squares block in two directions.
  • With unbalanced data, report least squares means and Type III tests, not raw means and sequential tests.
  • Plot cell means: non-parallel lines are the picture of an interaction.

Questions people ask

What is the difference between one-way and two-way ANOVA?

One-way ANOVA has one factor. Two-way has two, which lets you test each factor and their interaction in the same experiment.

Can I do a two-way ANOVA without replication?

Yes, but then the interaction cannot be separated from error, as in an RCBD with one unit per treatment per block. You must assume no interaction.

What is a main effect?

The effect of one factor averaged over the levels of the other. It is meaningful when the interaction is negligible.

How many factors can a factorial have?

Any number, but the combinations multiply quickly: 3 factors at 3 levels give 27 combinations. Fractional factorials test a planned subset when there are many factors.

Is a split-plot a factorial?

Yes, a factorial with two sizes of experimental unit. It needs two error terms; see the mixed models chapter.

Sources

  • Kaps, M., and Lamberson, W. R. (2017). Biostatistics for Animal Science (3rd ed.), chapters on blocking and factorial experiments. CABI.
  • Littell, R. C., Stroup, W. W., and Freund, R. J. (2002). SAS for Linear Models (4th ed.). SAS Institute.
  • Gomez, K. A., and Gomez, A. A. (1984). Statistical Procedures for Agricultural Research (2nd ed.), chapters 3 and 4. Wiley.