Quantitative Analysis/ Compare Means
Testing two factors together

How to tell if two factors, and their combination, affect an outcome

Two-way ANOVA examines how two categorical factors relate to a numeric outcome, both separately and together. This guide explains what it is, how it differs from one-way ANOVA and regression, when to use it, how main effects and interactions work, and how to run it in AnalyZ Solutions.

12 min read Compare Means Intermediate

01What is two-way ANOVA?

One-way ANOVA compares group averages across one grouping variable. Many real questions involve two. Two-way ANOVA studies two grouping variables at the same time. Each grouping variable is called a factor, and each category within it is a level. Crossing the two factors creates cells, one for every combination of levels. Gender with two levels and delivery method with two levels, for example, gives four cells: women online, women in person, men online, and men in person.

Like one-way ANOVA, it works by splitting the variation in the outcome. Here the variation is divided into four parts: variation explained by the first factor, by the second factor, by the interaction between them, and variation left unexplained within the cells. Each effect is compared with the unexplained variation to give an F statistic and a significance level.

Three questions at once

Two-way ANOVA answers three questions in one analysis.

The third question is often the most interesting. An interaction means the combination matters, and the factors cannot be described one at a time. If online delivery raises scores for women and lowers them for men, the overall online average may look the same as the in-person average, because the opposite effects cancel out. The main effects would suggest that delivery does not matter, when it matters a great deal for each gender.

Seeing an interaction

The easiest way to spot an interaction is to plot the cell averages, with one line for each level of one factor. Parallel lines mean the effect of the factor on the horizontal axis is the same for both groups, so there is no interaction. Lines that cross, or that fan out so that the gap changes, mean the effect differs between groups.

Figure 1. Average scores by gender and delivery method, without and with an interactionTwo line charts. On the left the lines for women and men are parallel. On the right they cross.No interaction65707580OnlineIn personWomenMenOnline helps both groups by about the same amountInteraction65707580OnlineIn personWomenMenOnline helps women and hurts menAverage scoreAverage score
Figure 1. Average scores by gender and delivery method, without and with an interaction

Why not run two one-way ANOVAs?

Two separate analyses would each ignore the other factor. That wastes information, because variation due to the second factor is left in the unexplained part and makes each test less sensitive. It also makes it impossible to detect an interaction, since each analysis sees only one factor at a time. Analysing both together is more informative and uses the data more efficiently.

A balanced design is easiest

Two-way ANOVA is easiest to read when every cell holds about the same number of cases, which is called a balanced design. Experiments tend to produce balanced designs, while surveys rarely do. When cell sizes differ a lot, the effects of the two factors overlap, and the results depend on how the software divides up the shared variation.

02Two-way ANOVA compared with one-way ANOVA and regression

How the methods compare
FeatureOne-way ANOVATwo-way ANOVALinear regression
Grouping variablesOne factorTwo factors that cross each otherAny number of categorical and numeric predictors
Questions answeredDo the groups differ?Does each factor matter, and does the effect of one depend on the other?How does the outcome change with each predictor, holding the others constant?
InteractionNot applicableTested directlyPossible in general statistical software, but not available in the AnalyZ Solutions regression module
Follow-up comparisonsPairwise differences between groupsCell averages, then separate testsCoefficients against a reference category
Covariates such as ageNoNoYes

Two-way ANOVA is a regression with two categorical predictors and their interaction. In a balanced design, the F tests for the two main effects and the interaction match the ones from a regression fitted to the same data, so the choice does not change the conclusion. The general relationship between ANOVA and regression is covered in the one-way ANOVA guide.

The practical difference is flexibility. Regression can add numeric predictors such as age, can include more than two factors, and copes better when cell sizes are unequal. In AnalyZ Solutions, however, the regression module has no interaction terms. Two-way ANOVA is therefore the way to test whether the effect of one categorical factor depends on another.

03When to use two-way ANOVA

Use it when all of these hold:

Typical examples are test scores by gender and course delivery, crop yield by fertiliser and irrigation method, customer spending by store type and season, and recovery time by treatment and age group.

Choose a different method when your situation changes:

04Assumptions

The assumptions match one-way ANOVA: independent observations, roughly normal outcomes within each cell, and similar spread across cells. Two-way ANOVA is also easiest to interpret when the cells are of roughly similar size. When some cells are much smaller than others, the main effect estimates become harder to separate from each other, and results can differ between software packages that partition the variation in different ways. Aim for at least 10 to 15 respondents per cell if you can.

05Reading the result

Start with the interaction

If the interaction is significant, interpret it first. The effect of each factor depends on the other, so statements about main effects alone can mislead. The interpretation in AnalyZ Solutions leads with the interaction when it is significant, telling you that the effect of one factor depends on the level of the other.

To understand the pattern, read the cell averages in the descriptives table. Compare, for instance, the online and in-person averages separately for women and for men.

Then the main effects

If the interaction is not significant, the main effects can be read on their own. Each one asks whether the outcome differs across the levels of that factor when the other factor is averaged over.

Eta-squared

Each row of the table has an eta-squared, the share of total variation explained by that effect. Under 6% is small, 6% to 14% medium, and over 14% large.

06How to run it in AnalyZ Solutions

Open Inferential Analysis, choose Compare Means, then Two-way ANOVA.

  1. Select the dependent variable
    Choose the numeric outcome.
  2. Select Factor A
    Choose the first categorical grouping variable.
  3. Select Factor B
    Choose the second one. It must be a different variable.
  4. Apply a subsample filter if needed
    For instance, to analyse one region only.
  5. Click Run
    The output includes a table with the average, standard deviation, and count for every combination of the two factors, an ANOVA table with rows for each factor, the interaction, and the error, and a plain-language interpretation.

Running two-way ANOVA in AnalyZ Solutions.

The table does not include automatic follow-up comparisons between cells. If the interaction is significant, use the cell averages to describe the pattern, and run a t-test within one level of a factor if you need a specific comparison.

Draw the pattern before you describe it. A line for each level of Factor B, plotted across the levels of Factor A, shows an interaction immediately. Lines that cross or fan out point to one. Lines that run roughly parallel suggest there is none. Plot the cell averages from the descriptives table with the Data Visualization module.

07Interpreting the result

The figures below are invented to show the steps, and they follow the results tables in AnalyZ Solutions, with a few columns left out to save space. Suppose test scores were recorded for 20 students in each combination of gender and course delivery (online or in person).

Cell averages
GenderDeliveryNMeanSD
FemaleOnline2078.08.0
FemaleIn person2070.08.0
MaleOnline2068.08.0
MaleIn person2076.08.0
ANOVA table
SourceSSdfMSFp-valueSigη²
Gender80.0180.01.25000.2671ns0.013
Delivery0.010.00.00001.0000ns0.000
Gender × Delivery1280.011280.020.0000< 0.001***0.206
Error4864.07664.0

Reading it step by step

  1. Look at the interaction first
    The Gender × Delivery row has a p-value below 0.001 with three stars, so the effect of delivery depends on gender. This finding takes priority over the other two rows.
  2. Explain it with the cell averages
    Women scored 78 online and 70 in person, while men scored 68 online and 76 in person. Online delivery helped women by 8 points and cost men 8 points. The pattern reverses between the two genders.
  3. Read the main effects with that in mind
    Gender and Delivery are both non-significant (p 0.2671 and 1.0000). That does not mean neither matters. The two opposite effects cancel out when averaged over the other factor, which is why the interaction has to be read first.
  4. Judge the size
    The interaction has an eta-squared of 0.206, so it explains about 21% of the variation in scores, a large effect. The main effects explain almost nothing on their own.

In plain words

The best delivery method depends on gender. Women did better online, and men did better in person, and the interaction is significant at the 0.1% level and large. Reporting either factor alone would have suggested that neither matters. Because the module gives no follow-up tests between cells, describe the pattern from the cell averages, and run a separate t-test within one gender if you need a formal comparison.

08Common mistakes

Interpreting main effects when an interaction is present. The main effects average over a pattern that differs between levels, and the average can describe nobody.

Empty or tiny cells. If one combination has very few respondents, its average is unreliable. Check the counts in the descriptives table.

Treating a non-significant interaction as proof of parallel effects. Interaction tests have low power, especially in small samples.

Using it for more than two factors. Add further predictors through linear regression.

Frequently Asked Questions
What is an interaction effect in plain terms?
It means the effect of one factor changes depending on the level of the other. If a training method works well for one region and badly for another, method and region interact. It is a stronger finding than a main effect because it describes who benefits and who does not.
Is two-way ANOVA the same as running two one-way ANOVAs?
No. Two one-way analyses would each ignore the other factor and could never detect an interaction. A two-way ANOVA analyses both factors together, which makes each test more sensitive and adds the test of whether the effect of one factor depends on the other.
Does a significant interaction mean the main effects are meaningless?
They become harder to interpret, because each main effect averages over a pattern that differs between the levels of the other factor. When lines cross, as in the figure, the averages can describe nobody. Describe the interaction first. If the interaction is small and the effects point the same way in every group, the main effects still say something useful.
Is two-way ANOVA the same as regression?
In a balanced design, a two-way ANOVA gives the same F tests as a regression with the two factors and their interaction. Regression is more flexible, because it can add numeric predictors and handle unequal cell sizes. In AnalyZ Solutions, only the two-way ANOVA tests the interaction.
Do the two factors have to have the same number of categories?
No. One factor can have two levels and the other four, for example. Each combination of levels forms a cell, and every cell should contain enough respondents to give a stable average.
Why is there no post-hoc test after the two-way ANOVA?
The module reports the main effects, the interaction, and the cell averages. For a specific follow-up, filter to one level of a factor and run a t-test or one-way ANOVA on the other factor, being clear that you chose that comparison for a reason.
What should I do if my cells have very different sizes?
Treat the main effects with caution, and consider collapsing sparse categories or using linear regression, which lets you include both factors with a reference category and explains each coefficient directly.
Can I include a continuous covariate such as age?
Not in this test. Linear regression handles a mix of categorical and continuous predictors, though the AnalyZ Solutions regression module does not include interaction terms, so a test of an interaction between two categorical factors belongs here.

Test two factors together

Open Compare Means in AnalyZ Solutions. Free to sign up, free to analyze.

Get started
Related Guides