Section 2.4

Factorial ANOVA (Two-Way)

Real situations rarely involve just one factor. Does a drug's effect depend on dose and on age? Does a teaching method work differently for beginners than experts? A factorial ANOVA tests two (or more) factors at once. It can also test something no single-factor study can: the interaction, whether the effect of one factor depends on the other.

Factors, levels, and cells

Three words cover most of the notation. A factor is a categorical variable the study manipulates or classifies people by. Its levels are the categories it takes, so a factor called Dose might have the levels None, Low and High. Cross two factors, pairing every level of one with every level of the other, and each pairing is a cell.

The design is then named by its levels, multiplied. Two levels of each factor is a 2 × 2 with four cells. Three levels of each is a 3 × 3 with nine. Four doses crossed with two age bands is a 4 × 2 with eight. The notation tells you three things: how many numbers there are is the number of factors, each number is that factor's number of levels, and their product is the number of cells. A third factor adds a third number, so 2 × 2 × 4 is sixteen cells.

Two properties of a design matter for everything below. It is fully crossed when every cell has observations in it, and that allows one analysis to answer three questions. It is balanced when every cell holds the same number of observations, and that keeps the arithmetic simple.

Three questions for the price of one

A two-way design with factors A and B answers three separate questions:

  • Main effect of A: does A matter, averaging over B?
  • Main effect of B: does B matter, averaging over A?
  • A × B interaction: does the effect of A depend on the level of B? You can only test this by studying the two factors together.

The interaction plot

The fastest way to read a two-way result is a picture. Put factor A on the x-axis and draw one line for each level of B. Parallel lines mean no interaction (A's effect is the same at every level of B), and non-parallel lines mean there is an interaction. Drag the cell-mean sliders below to see this. The table beside the plot shows the same four numbers in the square layout a printed report uses, with every margin and every simple effect worked out from them.

🎮 Interaction Plot Explorer

A 2×2 design. Set the average outcome in each of the four cells. The lines show how factor A's effect changes across the two levels of factor B, and the table works out the margins, the grand mean and the four simple main effects.

Cell meansB₁B₂Row mean
A₁———
A₂———
Column mean———

 

Main effect of A—
Main effect of B—
Interaction (A×B)—
Lines are—
A at B₁—
A at B₂—
B at A₁—
B at A₂—

Margins, and the difference of differences

Everything the analysis says about the pattern is already in those four cell means, and you need nothing harder than averaging to get it out. Take the widget's starting numbers. The A₁ row has 60 at B₁ and 40 at B₂, and the A₂ row has 75 and 55.

Average the two cells in a row and the answer is a marginal mean for that level of A: 50 for A₁, 65 for A₂. The gap between those margins, 15 points, is the main effect of A. Average down the columns instead and B's margins are 67.5 and 47.5, a main effect of 20. Average all four cells and you have the grand mean, 57.5.

The word marginal is literal. Write the four cells in a square and the row and column averages go in the margins around it. A printed table puts them there, and the Estimated Marginal Means box in SPSS is named after them. One caution about that box. A marginal mean is the unweighted average of the cells in its row. Once cells hold different numbers of people, it no longer matches the plain average of everyone in that row. In a balanced design the two agree exactly.

Now stay inside one column. The simple main effect of A at B₁ is the effect of A at that one level of B. With two levels of A, it is the difference of two cells: 75 − 60 = 15. At B₂ it is 55 − 40 = 15. Those two numbers are the slopes of the two lines in the plot. Each main effect is the average of its own two simple main effects, and that is what "averaging over the other factor" means.

Subtract one simple main effect from the other and you have the difference of differences: 15 − 15 = 0. A does the same thing at both levels of B, the lines are parallel, and there is no interaction. Press the widget's Interaction button and the same subtraction gives 15 − 35 = −20. Non-parallel lines give a difference of differences that is not zero.

The same works with the factors swapped. The simple main effects of B are the vertical gaps between the lines at each level of A: 60 − 40 = 20 at A₁ and 75 − 55 = 20 at A₂. Their difference is the same 0. An interaction is symmetric. If A's effect changes across the levels of B, then B's effect changes across the levels of A by the same amount. Only the sign depends on which factor you subtracted first.

Signs, as the widget reports them. The main effect of A is A₂ minus A₁ and the main effect of B is B₁ minus B₂, so both are positive on the starting numbers. Each simple main effect is computed in the same direction as its own main effect, so the two always average to it.

Reading the patterns

With A on the x-axis and one line per level of B, five arrangements cover almost every 2 × 2 result. The table lists the effects each one shows:

What the plot showsABA × B
Two flat lines on top of each othernonono
Two sloping lines on top of each otheryesnono
Two flat lines, one above the othernoyesno
Two parallel sloping lines, one above the otheryesyesno
Two lines that are not parallelread the marginsread the marginsyes

Sloping lines mean the row margins differ, so A has a main effect. Separated lines mean the column margins differ, so B has one. Only the last row needs care. Non-parallel lines can come with exactly equal margins, and then the main effect is zero even though the simple main effects are not.

Non-parallel splits into two named shapes. A spreading interaction (also called fanning) keeps both simple main effects in the same direction and changes only their size: A helps at both levels of B, but more at one than the other. A crossover interaction reverses the sign: A helps at one level of B and hurts at the other, and the two lines meet. Crossover is also called disordinal, because the ordering of the levels itself flips. The widget's third preset is a crossover, and it is the pattern most likely to be missed by a study that measured only A.

Interaction is moderation

Other lessons describe the same idea with different words. A variable that changes the strength or the direction of another variable's effect is a moderator, and what it does is moderation. Age moderates the drug's effect; prior expertise moderates the teaching method's. The design tradition says interaction and the modeling tradition says moderation, and interactions in regression shows they are one model, written once with factors and once with continuous predictors.

There are two good reasons to design a study around an interaction. The first is generalization. A main effect found in one population, one setting or one task is usually assumed to hold everywhere else. Crossing the manipulation with a second factor shows where it stops holding. The second is theory. Some theories predict an interaction directly, and then the interaction is the main test, not a qualification of one. If a memory advantage comes from effortful retrieval, it should appear when retrieval is effortful and vanish when it is easy, and no main effect can test that.

Often the interaction is the finding. "The drug works" is useful, but "the drug works for young patients but not old ones" is far more useful. The opposite mistake is common: reporting only main effects when a strong interaction is present can be misleading. If a crossover makes A helpful for B₁ and harmful for B₂, the average main effect of A might be zero, hiding two large and opposite real effects.

Read the interaction first. When lines are clearly non-parallel, interpret the main effects with caution: the effect of one factor differs depending on the other, so a single "average" effect can mislead.

The two-way ANOVA table

The plot shows the pattern the means make. The table tells you which parts of that pattern are statistically significant, and factorial exam questions usually ask you to complete one. It has two more source lines than the one-way table, because the variation between cells now splits three ways.

SourcedfMSF
Factor AI − 1SSA / dfAMSA / MSE
Factor BJ − 1SSB / dfBMSB / MSE
A × B(I − 1)(J − 1)SSAB / dfABMSAB / MSE
Error (within cells)N − IJSSE / dfE
TotalN − 1

I is the number of levels of A, J the number of levels of B, and IJ the number of cells. The degrees of freedom add up, as they always do: (I − 1) + (J − 1) + (I − 1)(J − 1) + (N − IJ) is N − 1. In a 2 × 2 the first three are all 1, so a 2 × 2 prints three F ratios, each with 1 as its first df.

With n observations in every cell, and writing x̄i· for a row margin, x̄·j for a column margin, x̄ij for a cell mean and x̄ for the grand mean, the sums of squares are:

Sum of squaresFormulaRead it as
SSAnJ Σi (x̄i· − x̄)²Row margins against the grand mean, weighted by the number of observations behind each margin.
SSBnI Σj (x̄·j − x̄)²The same down the columns.
SSABn ΣiΣj (x̄ij − x̄i· − x̄·j + x̄)²What each cell does that its own two margins did not predict.
SSEΣ (x − x̄ij)²Every score against its own cell mean. Nothing in the design explains this.
SSTΣ (x − x̄)² = SSA + SSB + SSAB + SSEEvery score against the grand mean. The identity is the arithmetic check.

The bracket inside SSAB is the difference of differences again, one cell at a time. Take a cell mean and subtract what its row margin and column margin together predict. The remainder is that cell's share of the interaction. In a 2 × 2 those four leftovers are the same size with alternating signs, each one a quarter of the difference of differences.

The table gives three F ratios, and all three divide by the same MSE. That error term is the pooled within-cell variance, the two-way version of the pooled spread the follow-up comparisons use. Its square root, sp = √MSE, is the number to report as the residual spread. For effect sizes the usual choice is partial eta squared, ηp² = SSeffect / (SSeffect + SSE): the share of the variation an effect accounts for once the other effects have been set aside. Software prints it, and because its denominator changes from row to row, the three values in a table do not sum to anything meaningful.

All of this assumes a balanced design. When cells hold different numbers of people, the four sums of squares no longer add to SST, because the effects are no longer separable. Software then has to use one of several conventions for splitting the overlap. The default nearly everywhere is Type III, which tests what each effect adds once every other effect is already in the model. It is the right default, but know that the choice exists, because different settings print different tables from the same data.

🎮 Where the Variance Goes

One fixed 2 × 2 study, analyzed twice. The top bar is a one-way ANOVA on practice time alone, so all the variation due to feedback is counted in its error. The bottom bar is the two-way model, which gives that variation rows of its own. Slide the effect of feedback: the top bar's error grows while the bottom bar's stays the same.

The participants slider rebuilds the built-in study at that size. A dataset arriving in a link keeps its own.

 

F for A, one-way—
F for A, two-way—
Error MS, one-way—
Error MS, two-way—

The starting study crosses practice time (short or long) with feedback (none or coached). The outcome is a skills test scored out of 40, with four people in each cell. Its cell means are 10 and 14 in the short-practice row and 16 and 28 in the long-practice row, so SSA = 400, SSB = 256, SSAB = 64 and SSE = 60, out of a total of 780. The two-way table gives MSE = 5.00 on 12 degrees of freedom and F(1, 12) = 80.00 for practice time. Analyzed as a one-way ANOVA on practice time alone, the same 400 is tested against an error of 380 on 14 degrees of freedom, so MSE = 27.14 and F(1, 14) = 14.74. The data and the effect are the same, but the two-way F is more than five times as large.

Push the feedback slider to its maximum and the one-way F falls to 3.25. On 1 and 14 degrees of freedom it would need 4.60 to be significant at α = .05. The two-way F for practice time stays at 80.00 the whole way. So a real effect that a well-designed study finds easily can be missed by a study that leaves out another factor affecting the outcome.

Two factors are cheaper than two studies

A more sensitive test of the first factor is one argument for factorial designs. The other is about sample size. Consider a 3 × 3 with 14 participants in each of its nine cells, 126 people in all. Every level of A then has 42 of them, and so does every level of B, because each person is in one level of each. To get 42 per group from separate studies, you would need a three-group study of A with 126 people and a three-group study of B with another 126. Those 252 people would still tell you nothing about the interaction. The factorial design answers both questions, plus a third that neither separate study could answer, with half the sample.

Adding a factor has a cost. Each extra source line takes degrees of freedom away from the error term, and in a small study that loss can outweigh the variation the new lines remove. The widget above gives up 2 error df (14 down to 12) to move 320 points of variation out of the error, which is clearly worth it. It would not be if those sums of squares were tiny and the df were scarce. Usually the trade is worth making, so a factor that affects the outcome is worth crossing in even when its own main effect is not your research question.

Interpret the interaction first

Read a two-way table in a fixed order, which is not the order it prints in. Look at the A × B line first. If it is significant, the two main effects above it are averages that may not describe any real condition. The write-up should lead with the interaction and then report each main effect as qualified by it, usually alongside the simple main effects that say what happened at each level. If the interaction is not significant, the main effects can be read and reported as they stand.

One misreading is common. A nonsignificant main effect alongside a significant interaction does not mean the factor never matters. It means the factor's effects at the different levels of the other factor averaged out. That is a statement about the average, not about either level. In a full crossover the main effect can be exactly zero while both simple main effects are large and both are real. Test the simple main effects before concluding that a factor did nothing.

Why it matters: many effects in the real world depend on the situation. Factorial designs let you test those "it depends" claims directly, through the interaction.

Problem 36 of the practice problems reads a caffeine × sleep interaction off a 2 × 2 table of cell means. Problem 51 works out a full set of margins and simple main effects from four cell means, and Problem 52 completes a two-way table with four cells blanked. Problem 66 is the mistake described above: an abstract that reports the main effect when the interaction is the main finding. To follow one 2 × 2 study from its hypothesis to its APA paragraph, see the complete worked project.

Common questions

How many participants do I need to detect an interaction?

More than the main effect needed, usually by a lot. An interaction is a difference between differences, so its standard error is larger than that of a plain two-group comparison. Take a study with enough people to detect an effect in one condition. If you now expect that effect to be present at one level of B and absent at the other, detecting the interaction takes roughly four times the total sample. A full crossover, where the effect reverses sign, needs far fewer: about the same total as the original two-group study. This is the most common reason a factorial study reports two clean main effects and an underpowered interaction, so settle the sample size at design time. Power analysis for complex designs works it through.

My interaction came out nonsignificant. Should I drop it and rerun the model?

This is a real practice, called pooling, and it has a cost. Deleting the interaction row puts SSAB and its degrees of freedom back into the error term. That usually lowers MSE a little and raises the df a little, so the two main effects are tested slightly more sharply. But the gain rests on an assumption (no interaction) that you only failed to reject and never established. And a nonsignificant interaction is weak evidence at the best of times. An interaction is a difference between differences, so a factorial with comfortable power for its main effects is often underpowered for the interaction by a factor of four. In a designed factorial, the safer habit is to keep the full model, report the interaction as it came out with its own effect size, and let a reader see that it was tested. Pooling makes more sense when the interaction was never of interest, the study is small enough that the extra degrees of freedom matter, and the decision was written down before the data arrived.

Can I run a factorial ANOVA when the cells hold different numbers of people?

The analysis still runs, but three things change without any warning in the output. First, the four sums of squares no longer add to the total, because the effects are no longer separable and part of the variation belongs to both factors at once. Software resolves that with a convention (SPSS calls the default Type III), so two packages with different settings can print different tables from the same data. Second, the margins change meaning. The F tests the unweighted average of the cells in a row, which is no longer the plain average of everyone at that level, so a large cell counts no more than a small one. Third, the equal-variance assumption matters more, because the pooled error term tolerates unequal spreads only while the cells are the same size. Report the cell sizes, check the spreads, and do not delete cases to force a balance: throwing away data costs more power than the imbalance does.