MathsStatistics & Probability

Two-Way ANOVA
calculator.

Test two factors and their interaction on one outcome, from a balanced table.

How it's worked out

You have one measured outcome and two factors, such as battery life by material and temperature. Three questions can be tested: does the first factor matter, does the second factor matter, and do they interact? An interaction means the effect of one factor depends on the level of the other.

With the same number of values in each cell, the total spread splits cleanly into four parts: one for each factor, one for the interaction, and one for error. That clean split is why this tool asks for a balanced table.

SST\displaystyle SS_T=SSA+SSB+SSAB+SSE\displaystyle {}= SS_A + SS_B + SS_{AB} + SS_E

With aa levels of the first factor, bb of the second and rr values per cell, each factor's sum compares its level means with the grand mean y‾\bar{y}. The error sum takes each value around its own cell mean y‾ij\bar{y}_{ij}. The interaction is what the cell means leave over after both factors.

SSA\displaystyle SS_A=br∑i(y‾i−y‾)2\displaystyle {}= br \sum_i (\bar{y}_i - \bar{y})^2
SSB\displaystyle SS_B=ar∑j(y‾j−y‾)2\displaystyle {}= ar \sum_j (\bar{y}_j - \bar{y})^2
SSE\displaystyle SS_E=∑ijk(yijk−y‾ij)2\displaystyle {}= \sum_{ijk} (y_{ijk} - \bar{y}_{ij})^2

Dividing a sum by its degrees of freedom gives a mean square. The degrees of freedom are a−1a - 1, b−1b - 1, (a−1)(b−1)(a - 1)(b - 1) and N−abN - ab for error, where NN is the count of all values. Each F compares an effect with the error.

FA\displaystyle F_A=SSA/(a−1)MSE\displaystyle {}= \frac{SS_A / (a - 1)}{MS_E}

With one value per cell, nothing is left to measure error, so the interaction term has to stand in for it. The tool then tests both factors, assumes no interaction, and says so.

Simple effects test one factor inside each level of the other. For level ii of the first factor, the sum is taken around that level's own mean, and the F divides by the error mean square of the whole table, as UCLA's worked example does with the model's error degrees of freedom.

SSB|i\displaystyle SS_{B \mid i}=r∑j(y‾ij−y‾i)2\displaystyle {}= r \sum_j (\bar{y}_{ij} - \bar{y}_i)^2

Worked examples

Which battery lasts longest, and does it depend on the heat?

This is Montgomery's battery example: three materials at three temperatures, with four batteries in each cell. Temperature has F = 28.97 (p below 0.0001), material has F = 7.91 (p = 0.002), and the interaction has F = 3.56 (p = 0.0186), all on 27 error degrees of freedom. UC Berkeley's analysis of the same data shows the same three F values.

The significant interaction means the materials do not keep one order at every temperature. Testing material at each temperature, the F values are 0.66 (p = 0.5269) at the lowest, 12.26 (p = 0.0002) at the middle and 2.12 (p = 0.14) at the highest. So the clear gap between materials shows up at the middle temperature. Those tests carry no adjustment for running three of them.

Open this example in the tool

Crop yield with one plot per combination

Four varieties each get three fertilizers, with one plot per combination. The tool runs the additive model: variety has F = 22.29 (p = 0.0012) and fertilizer has F = 36.09 (p = 0.0005), on 6 degrees of freedom. These are real results only if the varieties respond to fertilizer in the same way, because the design has no way to test that. One extra plot per cell would change that.

Open this example in the tool

Two teaching methods across class sizes

Here are made-up scores for two methods at three class sizes, three students per cell. Method has F = 60.5 and class size has F = 165.5, while the interaction has F = 0.5 (p = 0.6186). On the plot the two lines run almost side by side, so the gap between the methods is about the same at every class size, and you can quote that one gap.

Open this example in the tool

Reading your result

Start with the interaction. If it is significant, the main effects average over patterns that differ, and McDonald advises against reading them as they stand. Describe one factor at each level of the other instead.

Look at the plot. If there are no interactions, the lines should be parallel. Crossing or spreading lines are a sign of one. Try the swap as well, since the same interaction can be clearer with the other factor along the axis.

Separate the two effect sizes. Eta squared is an effect's share of the total, and partial eta squared leaves the other effects out of the total. For temperature in the battery data, the two are 0.504 and 0.682. Lakens quotes 0.01, 0.06 and 0.14 as small, medium and large for eta squared, and warns that they fit poorly with covariates or repeated measures.

A dropped interaction changes the rest of the table. Pooling it into the error moves temperature's F from 28.97 to 21.78, on 31 degrees of freedom. That is only a fair model if the factors really do not interact, which this battery test says they do.

To compare levels of just one factor, use the one-way ANOVA calculator. It also gives pairwise comparisons.

Common mistakes

  • Quoting a main effect past a significant interaction. An interaction means the simple effects differ, so the main effect is not general. A material that wins on average can lose at the temperature you care about.
  • Treating one value per cell as a full test. The p-values appear, but they rest on assuming no interaction. GraphPad's guide says plainly that replication is much better.
  • Entering an unbalanced table. This tool refuses one, as the clean split above needs equal cells. McDonald calls the unbalanced analysis much more complicated, with several competing methods, so use statistical software if cells differ.
  • Using it for repeated measures. The F tests assume independent values, and both factors fixed. Measuring the same people at each level, or sampling levels at random, needs a different error term.

Questions people ask

It means the effect of one factor depends on the level of the other. It does not say which levels differ, only that the lines on the plot are not parallel beyond what chance would produce. A significant interaction with no significant simple effects can happen, since the two test related but different questions.

Sources