A two-way ANOVA (two-way analysis of variance) is a statistical test that examines how two categorical independent variables (called factors) affect one quantitative outcome. Unlike a one-way ANOVA, it tells you three things at once: the effect of each factor on its own (the two main effects) and whether the two factors combine to produce an effect that neither shows alone (the interaction effect). Use it when you have one continuous dependent variable measured across the levels of two categorical predictors.
What is ANOVA?
Analysis of variance (ANOVA) is a family of statistical models used to compare the means of three or more groups. It works by partitioning the total variation in a dataset into the part explained by the groups and the part that remains unexplained (random error), then asking whether the explained portion is large enough to be unlikely due to chance.
Rather than running many separate t-tests (which inflates the chance of a false positive), ANOVA makes a single, controlled comparison using the F-statistic — the ratio of variance between the groups to variance within the groups. For a fuller introduction, see our complete guide to ANOVA.
What is Two-Way ANOVA?
A two-way ANOVA assesses the effect of two independent categorical variables on a single quantitative dependent variable. “Two-way” simply refers to the two factors. Each factor is divided into levels — the distinct categories it contains. For example, the factor “fertiliser brand” might have three levels (X, Y and Z), while the factor “watering frequency” might have two levels (low and high).
The test answers three questions:
- Main effect of Factor A — does the dependent variable differ across the levels of the first factor, averaged over the second?
- Main effect of Factor B — does the dependent variable differ across the levels of the second factor, averaged over the first?
- Interaction effect (A × B) — does the effect of one factor depend on the level of the other factor?
The interaction is what makes a two-way ANOVA more powerful than running two separate one-way ANOVAs. To understand it correctly: an interaction exists when the influence of one factor on the outcome changes depending on the level of the other factor. If a fertiliser boosts yield only when water is plentiful but does nothing when water is scarce, that is an interaction — the fertiliser’s effect is not constant. When the two factors act independently (the effect of one is the same at every level of the other), there is no interaction.
“Two-way ANOVA… is used to estimate how the mean of a quantitative variable changes according to the levels of two categorical variables.” — Scribbr, “Two-Way ANOVA | Examples & When To Use It”
Main Effects vs Interaction Effects
Getting the distinction right is the single most important idea in two-way ANOVA, so it is worth stating plainly:
- A main effect is the effect of one factor on the outcome, averaged across all levels of the other factor. Each factor has its own main effect.
- An interaction effect describes whether the two factors work together. When an interaction is present, you cannot describe the effect of one factor without also stating the level of the other.
A simple visual test helps. If you plot the group means with one factor on the horizontal axis and a separate line for each level of the second factor, parallel lines mean no interaction and non-parallel (or crossing) lines suggest an interaction.
An important caution: when a significant interaction is present, the main effects can be misleading and should be interpreted carefully — or not in isolation at all. If a drug raises blood pressure in men but lowers it in women, the “average” main effect of the drug might look like zero, even though the drug clearly does something. In that situation the interaction tells the real story.
How the Two-Way ANOVA Works
A two-way ANOVA partitions the total variation in the data into four sources: the variation due to Factor A, the variation due to Factor B, the variation due to the A×B interaction, and the leftover within-group (error) variation. For each of the three effects it computes an F-statistic — the ratio of that effect’s mean square to the error mean square — and a corresponding p-value.
A larger F-value means the variation explained by that effect is large relative to random noise, which makes it less likely the difference arose by chance. If the p-value falls below your chosen significance threshold (commonly 0.05), you conclude that the effect is statistically significant.
Quick recap of key terms:
- t-test: an inferential test of whether the means of two groups differ significantly.
- Type I error: a false positive — rejecting a true null hypothesis.
- Type II error: a false negative — failing to reject a false null hypothesis.
The Three Null Hypotheses
A two-way ANOVA with interaction tests three null hypotheses (H0) simultaneously, each with its own alternative hypothesis (H1):
- Main effect of Factor A. H0: the population means are equal across all levels of Factor A. H1: at least one level mean differs.
- Main effect of Factor B. H0: the population means are equal across all levels of Factor B. H1: at least one level mean differs.
- Interaction (A × B). H0: there is no interaction — the effect of Factor A is the same at every level of Factor B. H1: an interaction exists.
Each hypothesis produces a separate F-test and p-value, so you can find, for example, a significant main effect for one factor but no interaction, or a significant interaction with no main effects at all.
When Should You Use Two-Way ANOVA?
Use a two-way ANOVA when you have data on a quantitative dependent variable measured at multiple levels of two categorical independent variables.
- The dependent variable must be quantitative (continuous) — something you can take a mean of, such as crop yield in bushels per acre, exam scores, or reaction times.
- Both independent variables must be categorical, each with two or more levels.
- You should have enough observations in every combination of factor levels to estimate a reliable mean for each cell.
If one of your two predictors is categorical and the other is quantitative (a covariate), use an ANCOVA instead. If you have only one categorical factor, a one-way ANOVA is the right test. Unsure which test fits your design? See our guide on choosing the right statistical test.
One-Way vs Two-Way ANOVA
The choice comes down to how many categorical factors you are testing. A one-way ANOVA handles a single factor; a two-way ANOVA handles two and, crucially, lets you test their interaction.
| Feature | One-Way ANOVA | Two-Way ANOVA |
|---|---|---|
| Number of independent factors | One | Two |
| Dependent variable | One quantitative variable | One quantitative variable |
| Main effects tested | One | Two (one per factor) |
| Interaction effect | Not possible | Yes (Factor A × Factor B) |
| Null hypotheses | One | Three |
| Typical question | Does fertiliser brand affect yield? | Do fertiliser brand and watering level — and their combination — affect yield? |
In short, reach for a one-way ANOVA when a single grouping variable is all that matters, and a two-way ANOVA when two factors might act together. Read our overview of the one-way ANOVA for the simpler case.
Worked Example and ANOVA Summary Table
Suppose an agricultural researcher wants to know how fertiliser brand (Factor A: X, Y, Z — three levels) and watering frequency (Factor B: low, high — two levels) affect crop yield in bushels per acre. This 3 × 2 design produces six treatment combinations, and the experiment runs a two-way ANOVA on the results.
| Source of variation | SS | df | MS (SS/df) | F (MS/MSerror) | p-value |
|---|---|---|---|---|---|
| Fertiliser brand (A) | 120.0 | 2 | 60.0 | 12.0 | < 0.001 |
| Watering frequency (B) | 50.0 | 1 | 50.0 | 10.0 | 0.003 |
| Interaction (A × B) | 40.0 | 2 | 20.0 | 4.0 | 0.028 |
| Error (within) | 270.0 | 54 | 5.0 | — | — |
| Total | 480.0 | 59 | — | — | — |
Interpretation (at α = 0.05): all three p-values are below 0.05, so each effect is significant. Fertiliser brand and watering frequency each have a significant main effect, and there is a significant interaction. Because the interaction is significant, the main effects must be read with care: the best fertiliser may depend on how often the crop is watered. The researcher would follow up with a post-hoc test (e.g. Tukey’s HSD) and an interaction plot to see exactly which brand-and-water combination produces the highest yield.
These illustrative figures show the mechanics; with real data the software (SPSS, R, Stata, Excel) computes the sums of squares for you. What matters is reading the table correctly — check the interaction row first, then interpret the main effects in that light.
Struggling to run or interpret your ANOVA?
ResearchProspect to the rescue!
Our qualified statisticians can run your two-way ANOVA, check the assumptions and explain every result — see our statistical analysis service.
Two-Way ANOVA Assumptions
As a parametric test of difference, a two-way ANOVA relies on several assumptions. If your data violate them, your results may be unreliable, so check each one before trusting the output.
1. Homogeneity of variance (homoscedasticity)
The spread of values around the mean should be roughly similar across all groups being compared. Levene’s test is commonly used to check this. If the assumption fails, a non-parametric alternative such as the Kruskal–Wallis test may be more appropriate.
2. Normally distributed dependent variable
The dependent variable’s values (more precisely, the model residuals) should be approximately normally distributed — following a bell curve. If they are markedly skewed, a data transformation (such as a log transform) can sometimes help.
3. Independence of observations
Each observation should be independent of the others — your data should not be clustered by person, time or location. Good experimental design is the only reliable way to guarantee this. If observations are grouped (for example, repeated measurements on the same subjects), use a blocking variable or a repeated-measures ANOVA instead.
A fourth practical requirement is that both independent variables are categorical and that you have a reasonable number of observations within each combination of levels.