ANOVA Hypothesis Testing Inferential Statistics 32 min read September 5, 2026
BY: Statistics Fundamentals Team
Reviewed By: Minsa A (Senior Statistics Editor)

Two-Way ANOVA: How It Works, Formula, Examples, and Interpretation

A researcher studies whether a new drug reduces blood pressure differently in men and women. A teacher tests whether study method and classroom environment together affect exam scores. An agronomist examines crop yield across fertilizer types and irrigation schedules. Each of these studies has two categorical variables and one measured outcome — the exact situation two-way ANOVA is built for.

This guide covers two-way ANOVA from first principles: what the test does, how the math works, how to read an ANOVA table, how to interpret main effects and interaction effects, and how to report results in a publication-ready format. A fully verified numerical example and an interactive calculator are included throughout.

What You'll Learn
  • ✓ The definition of two-way ANOVA and its three F-tests
  • ✓ The difference between main effects and interaction effects
  • ✓ How to partition SS, compute df, MS, F, and p for each source
  • ✓ A fully verified numerical example with every calculation shown
  • ✓ How to interpret a significant interaction — and what to do next
  • ✓ Assumptions, post hoc tests, effect sizes, and power analysis
  • ✓ Implementation in SPSS, R, Python, and Excel

What Is Two-Way ANOVA?

Definition — Two-Way ANOVA (Two-Factor Analysis of Variance)
Two-way ANOVA is a statistical test that examines the effects of two categorical independent variables (factors) on a continuous dependent variable, and tests whether the two factors interact. It produces three separate F-tests: one for each factor's main effect and one for their interaction.
SS_Total = SS_A + SS_B + SS_AB + SS_Error

One-way ANOVA answers one question: does this factor affect the outcome? Two-way ANOVA asks three at once.

Take a simple study measuring exam scores. Factor A is teaching method (traditional vs. interactive). Factor B is study environment (quiet vs. noisy). Two-way ANOVA simultaneously answers: Does teaching method affect scores regardless of environment? Does environment affect scores regardless of teaching method? Does the effect of teaching method change depending on which environment students are in?

That third question — does one factor's effect depend on the other factor? — is the interaction effect. It's where two-way ANOVA goes beyond what running two separate one-way ANOVAs could ever tell you, and it deserves close attention in any analysis.

2
Categorical factors tested simultaneously
3
F-tests produced: A, B, and A×B
4
SS sources partitioned from SS_Total
1
Continuous dependent variable

Factors, Levels, and the Dependent Variable

Every two-way ANOVA study has the same three-part structure: two factors and one outcome.

A factor is a categorical variable used to group observations — the thing you're manipulating or comparing. Each category within a factor is called a level. The dependent variable is the continuous outcome you measure. Both factors must have at least two levels, but neither is limited to two.

Component Technical Term Example 1 (Education) Example 2 (Agriculture)
Factor AIndependent variable 1Teaching methodFertilizer type
Levels of ACategories of Factor ATraditional, InteractiveType X, Type Y, Control
Factor BIndependent variable 2Study environmentIrrigation schedule
Levels of BCategories of Factor BQuiet, NoisyDaily, Weekly
Dependent variableOutcome measuredExam score (0–100)Crop yield (kg/plot)

When Factor A has a levels and Factor B has b levels, the design contains a × b unique combinations called cells. A 2×2 design has four cells; a 3×2 design has six. Each cell is one unique combination of Factor A level and Factor B level.

When to Use Two-Way ANOVA

Two-way ANOVA fits your study when all of the following apply: you have exactly two categorical independent variables you want to assess simultaneously, your outcome is continuous, observations are independent across groups (or your design accounts for any dependence), and the research question concerns either the individual contribution of each factor or whether they interact.

Common research scenarios where two-way ANOVA is the right choice:

📚

Education Research

Teaching method × school type → exam score. Does the method advantage hold across school types?

🌱

Agriculture

Fertilizer type × irrigation schedule → crop yield. Does the best fertilizer depend on how often you water?

💊

Clinical Research

Drug treatment × patient sex → blood pressure change. Does the drug work differently in men and women?

📈

Marketing

Advertising channel × region → sales volume. Does the best channel vary by geography?

🏭

Manufacturing

Machine type × operator experience → production time. Does the machine advantage depend on operator skill?

🏋️

Exercise Science

Exercise type × diet → weight change. Is the exercise benefit consistent across different diets?

Two-way ANOVA may not be the right method when your outcome is binary or a count rather than continuous, residuals deviate severely from what the model assumes, observations are clustered or nested rather than independent, you have more than two outcome variables measured together, or your design involves repeated measurements that require a mixed-effects or repeated-measures model. Logistic regression, Poisson models, MANOVA, and linear mixed models are the relevant alternatives in those situations.

Two-Way ANOVA Example — The Dataset

Throughout this guide we'll use one concrete dataset. The research question: do teaching method and study environment affect exam scores, and do the two factors interact?

Factor A is teaching method with two levels (Traditional, Interactive). Factor B is study environment with two levels (Quiet, Noisy). Each cell contains five student scores — five replications per cell, 20 observations total.

Teaching Method Environment Student Scores Cell Mean
TraditionalQuiet72, 68, 75, 71, 7472.0
TraditionalNoisy58, 61, 55, 63, 5859.0
InteractiveQuiet84, 88, 82, 86, 8585.0
InteractiveNoisy62, 65, 60, 64, 6463.0

The grand mean across all 20 scores is 69.75. We'll use these numbers throughout the worked calculations.

What Is a Main Effect?

A main effect is the overall influence of one factor on the outcome, averaged across all levels of the other factor. It answers: ignoring everything else, does this factor matter?

Main Effect of Factor A (Teaching Method)

Average each method's scores across both environments:

Teaching MethodMean Score (averaged across environments)
Traditional(72.0 + 59.0) / 2 = 65.5
Interactive(85.0 + 63.0) / 2 = 74.0

The marginal mean for interactive teaching (74.0) is 8.5 points higher than for traditional teaching (65.5). This gap is the main effect of Factor A — how much teaching method matters, collapsed across environments.

Main Effect of Factor B (Study Environment)

Study EnvironmentMean Score (averaged across teaching methods)
Quiet(72.0 + 85.0) / 2 = 78.5
Noisy(59.0 + 63.0) / 2 = 61.0

Quiet environments produce scores 17.5 points higher on average. This is the main effect of Factor B.

💡
Marginal Means vs. Cell Means

A marginal mean is the mean for one level of a factor collapsed across all levels of the other factor. Cell means are the means within each specific factor combination. Main effects describe differences in marginal means; interaction effects require comparing cell means.

What Is an Interaction Effect?

An interaction between two factors means the effect of Factor A on the outcome changes depending on which level of Factor B you're looking at — and vice versa. No amount of looking at main effects alone reveals this.

In our dataset, how much does teaching method matter in each environment?

EnvironmentTraditional MeanInteractive MeanMethod Difference
Quiet72.085.0+13.0 points
Noisy59.063.0+4.0 points

In a quiet environment, interactive teaching beats traditional by 13 points. In a noisy environment, the same comparison yields only 4 points. The method advantage is real in both settings, but the size of that advantage is quite different depending on where students study. That's an interaction.

⚠️
Why Interactions Matter

If you only reported the main effect of teaching method (8.5-point advantage on average), you'd miss that this advantage is much larger in quiet settings. A policy recommendation based on main effects alone could mislead — the "best" method in one context might not be the best in another.

The Interaction Plot

An interaction plot displays cell means visually: one factor on the x-axis, mean outcome on the y-axis, and separate lines for each level of the other factor. Parallel lines suggest little interaction; lines that converge, diverge, or cross indicate the effect of one factor differs across levels of the other.

Interactive Interaction Plot — Teaching Method × Study Environment

Quiet Environment
Noisy Environment

Use the dropdown to see how parallel vs. nonparallel lines represent different interaction patterns. Lines crossing indicate a particularly strong interaction where the ranking of factor levels reverses.

⚠️
Visual Nonparallelism Is Descriptive, Not Inferential

Lines that look slightly nonparallel in a plot don't automatically mean a statistically significant interaction. Sample-to-sample variation creates apparent nonparallelism even when the population interaction is zero. Always use the interaction's F-test to judge statistical significance.

Two-Way ANOVA Hypotheses

Two-way ANOVA tests three sets of hypotheses simultaneously. Each has its own F statistic, degrees of freedom, and p-value.

Hypothesis Set 1 — Main Effect of Factor A

H₀: All population marginal means for Factor A are equal (teaching method has no effect on exam scores, averaged across environments).
H₁: At least one Factor A marginal mean differs from the others.

Hypothesis Set 2 — Main Effect of Factor B

H₀: All population marginal means for Factor B are equal (study environment has no effect on exam scores, averaged across teaching methods).
H₁: At least one Factor B marginal mean differs from the others.

Hypothesis Set 3 — Interaction Effect A × B

H₀: There is no interaction between teaching method and study environment — any differences in Factor A effects are consistent across all levels of Factor B.
H₁: There is an interaction — the effect of Factor A on the outcome changes depending on the level of Factor B.

The Two-Way ANOVA Model

Every observation in a two-way ANOVA is described by this linear model:

Two-Way ANOVA Statistical Model
Yijk = μ + αi + βj + (αβ)ij + εijk
Yijk = observed score for unit k in cell (i,j) μ = grand population mean αi = effect of level i of Factor A βj = effect of level j of Factor B (αβ)ij = interaction effect for cell (i,j) εijk = random residual error

Each observed score decomposes into a grand mean, the contribution of Factor A's level, the contribution of Factor B's level, any additional effect from their combination (the interaction), and random error. When there is no interaction, the model simplifies and the cell means are fully predicted by adding the factor effects to the grand mean. When an interaction exists, those additive predictions no longer match the data and the interaction term is needed.

Variance Decomposition

Two-way ANOVA works by partitioning the total variation in the data into four separate components:

Sum of Squares Decomposition
SSTotal = SSA + SSB + SSAB + SSError
SSA = variation due to Factor A SSB = variation due to Factor B SSAB = variation due to A×B interaction SSError = residual within-cell variation

The F-statistic for each effect divides that effect's mean square by the error mean square. A large F means that source of variation is large relative to random noise — evidence against the null hypothesis for that effect.

The Two-Way ANOVA Table

Every two-way ANOVA result is summarized in a table with five columns: source of variation, sum of squares, degrees of freedom, mean square, and F statistic (with associated p-value). Here's the general form:

Source SS df MS = SS/df F = MS/MSError p-value
Factor ASSAa − 1MSAMSA / MSErrorFrom F-distribution
Factor BSSBb − 1MSBMSB / MSErrorFrom F-distribution
A × B InteractionSSAB(a−1)(b−1)MSABMSAB / MSErrorFrom F-distribution
Error (Within)SSErrorN − abMSError
TotalSSTotalN − 1

Where a = number of levels of Factor A, b = number of levels of Factor B, N = total number of observations. This table applies to a balanced fixed-effects design with equal observations per cell.

Degrees of Freedom

For a balanced two-factor design with a levels of Factor A, b levels of Factor B, and n observations per cell (N = abn total):

SourceFormulaOur Example (2×2, n=5)
Factor Aa − 12 − 1 = 1
Factor Bb − 12 − 1 = 1
A × B Interaction(a − 1)(b − 1)(1)(1) = 1
ErrorN − ab = ab(n − 1)20 − 4 = 16
TotalN − 120 − 1 = 19

Degrees of freedom always sum correctly: 1 + 1 + 1 + 16 = 19 = N − 1. Unbalanced designs and more complex model structures (such as random effects or nested factors) require different computational approaches and should be handled with appropriate software.

Complete Worked Example

We'll work through the full calculation using the teaching method × environment dataset. All arithmetic is shown so you can verify every step.

Full Two-Way ANOVA Calculation — Teaching Method × Environment

Design: 2 (Method) × 2 (Environment), n = 5 per cell, N = 20. Grand mean = 69.75

1

Cell means, marginal means, and grand mean:
Cell means: ȳ11 = 72.0 (Trad/Quiet), ȳ12 = 59.0 (Trad/Noisy), ȳ21 = 85.0 (Inter/Quiet), ȳ22 = 63.0 (Inter/Noisy)
Marginal means: ȳA1· = 65.5 (Traditional), ȳA2· = 74.0 (Interactive)
Marginal means: ȳ·B1 = 78.5 (Quiet), ȳ·B2 = 61.0 (Noisy)
Grand mean: ȳ··· = 69.75

2

SS for Factor A (Teaching Method):
SSA = bn · Σ(ȳAi· − ȳ···
= (2 × 5) · [(65.5 − 69.75)² + (74.0 − 69.75)²]
= 10 · [(-4.25)² + (4.25)²]
= 10 · [18.0625 + 18.0625]
= 10 · 36.125 = 361.25

3

SS for Factor B (Study Environment):
SSB = an · Σ(ȳ·Bj − ȳ···
= (2 × 5) · [(78.5 − 69.75)² + (61.0 − 69.75)²]
= 10 · [(8.75)² + (-8.75)²]
= 10 · [76.5625 + 76.5625]
= 10 · 153.125 = 1531.25

4

SS for A×B Interaction:
SSAB = n · Σijij − ȳAi· − ȳ·Bj + ȳ···
For cell (1,1): 72.0 − 65.5 − 78.5 + 69.75 = −2.25
For cell (1,2): 59.0 − 65.5 − 61.0 + 69.75 = 2.25
For cell (2,1): 85.0 − 74.0 − 78.5 + 69.75 = 2.25
For cell (2,2): 63.0 − 74.0 − 61.0 + 69.75 = −2.25
SSAB = 5 · [(-2.25)² + (2.25)² + (2.25)² + (-2.25)²]
= 5 · [5.0625 + 5.0625 + 5.0625 + 5.0625]
= 5 · 20.25 = 101.25

5

SS_Error (within-cell variation):
Cell (Trad/Quiet) scores: 72,68,75,71,74. Mean=72.0. SS = (0²+(-4)²+3²+(-1)²+2²) = 30
Cell (Trad/Noisy) scores: 58,61,55,63,58. Mean=59.0. SS = (1²+4²+(-4)²+16+1²) = wait, recalculate: (58-59)²+(61-59)²+(55-59)²+(63-59)²+(58-59)² = 1+4+16+16+1 = 38
Cell (Inter/Quiet) scores: 84,88,82,86,85. Mean=85.0. SS = 1+9+9+1+0 = 20
Cell (Inter/Noisy) scores: 62,65,60,64,64. Mean=63.0. SS = 1+4+9+1+1 = 16
SSError = 30 + 38 + 20 + 16 = 104

6

SS_Total check:
SSA + SSB + SSAB + SSError = 361.25 + 1531.25 + 101.25 + 104 = 2097.75
(This should equal the total corrected SS computed from all 20 raw scores — confirmed.)

7

Mean Squares:
MSA = 361.25 / 1 = 361.25
MSB = 1531.25 / 1 = 1531.25
MSAB = 101.25 / 1 = 101.25
MSError = 104 / 16 = 6.50

8

F statistics:
FA = 361.25 / 6.50 = 55.58
FB = 1531.25 / 6.50 = 235.58
FAB = 101.25 / 6.50 = 15.58

9

p-values (each F compared to F-distribution with given df and 16 dfError):
FA(1, 16) = 55.58 → p < 0.001
FB(1, 16) = 235.58 → p < 0.001
FAB(1, 16) = 15.58 → p = 0.001
All three effects are statistically significant at α = 0.05. See the F-distribution table — the critical value F(1,16) at α = 0.05 is 4.49.

✅ Completed ANOVA Table: Factor A (Method): F(1,16) = 55.58, p < 0.001. Factor B (Environment): F(1,16) = 235.58, p < 0.001. A×B Interaction: F(1,16) = 15.58, p = 0.001. All three effects are statistically significant.

Putting it all in the standard table:

SourceSSdfMSFp-value
Teaching Method (A)361.251361.2555.58< 0.001
Environment (B)1531.2511531.25235.58< 0.001
Method × Environment101.251101.2515.580.001
Error (Within)104.00166.50
Total2097.7519
Calculation methodology follows Montgomery, D.C. (2017). Design and Analysis of Experiments, 9th edition. Wiley. F-critical values from the F-distribution table.

Interpreting a Significant Interaction

All three F-tests came back significant. So what do you do?

Start with the interaction, not the main effects. The A×B interaction F(1,16) = 15.58, p = 0.001 tells us the effect of teaching method is not the same across environments. Reporting only the main effects would average over a pattern that differs by condition — a potentially misleading summary.

Simple Effects Analysis

Simple effects (also called simple main effects) break down the interaction by examining Factor A separately at each level of Factor B. In our data:

ComparisonTraditionalInteractiveDifferenceInterpretation
Within Quiet environment72.085.0+13.0Large method advantage in quiet settings
Within Noisy environment59.063.0+4.0Smaller method advantage when noisy

Interactive teaching benefits students more in a quiet environment than in a noisy one. This interaction is the key finding — and it's what justifies studying both factors together rather than separately.

📊
Main Effects When Interaction Is Significant

Main effects still exist mathematically even when an interaction is significant. Whether they're meaningful to report depends on your research question. If the interaction makes the main effect averages misleading (e.g., opposite directions in different conditions), focus on simple effects. If the interaction just changes the magnitude but not the direction, main effects can still be reported alongside the interaction.

Three Possible Result Patterns

PatternWhat It MeansNext Step
A significant, B significant, A×B not significant Both factors independently affect the outcome. Factor A's effect is consistent regardless of Factor B's level, and vice versa. Interpret main effects directly. If factors have >2 levels, run post hoc comparisons for each.
A×B significant; main effects not significant Factors offset each other across cells. For example, A's effect is positive at one level of B and negative at another, averaging to near zero. Look at the interaction plot and run simple effects. Do not conclude "no effect of A" or "no effect of B."
A significant, A×B significant (our example) Factor A has an overall effect, but its size varies across Factor B's levels. Report both the main effect and the interaction. Examine simple effects to characterize where the difference is largest.

Post Hoc Tests

Post hoc comparisons are most relevant when a significant effect involves a factor with three or more levels. In a 2-level factor, the omnibus F-test already identifies which level is higher — there's only one comparison to make.

For factors with three or more levels, Tukey's HSD is widely used because it controls the family-wise error rate while remaining reasonably powerful. Other options include Bonferroni correction (conservative, good for planned comparisons) and Games-Howell (when variances differ across groups).

When the interaction is significant, simple effects comparisons are the priority. You compare the levels of Factor A separately within each level of Factor B (and vice versa). Software like SPSS, R, and Python will compute estimated marginal means and pairwise comparisons with appropriate multiplicity adjustments. See the Bonferroni correction guide for how multiplicity adjustments work.

Two-Way ANOVA Assumptions

Two-way ANOVA is a parametric method. It works well when the following conditions hold reasonably well — "reasonably well" being the key phrase, because ANOVA is fairly robust to moderate violations, especially in balanced designs with suitable sample sizes.

1

Independence of Observations

Observations must be independent across groups according to the study design. Students in the same classroom, animals from the same litter, or patients treated by the same doctor are not independent — they share variance. Violating independence is the most serious assumption failure and requires a different model (mixed-effects, nested ANOVA).

2

Continuous Dependent Variable

The outcome should be measured on an interval or ratio scale. Binary outcomes call for logistic regression; count data with small values call for Poisson regression. Ordinal outcomes with few categories may need non-parametric alternatives.

3

Normality of Residuals

The model residuals — not the raw data — should be approximately normally distributed. ANOVA is fairly robust to this assumption when cell sizes are moderate and balanced, because the Central Limit Theorem applies to the group means underlying the F-test. Check with a Q-Q plot of residuals rather than raw scores. See the normality tests guide for practical diagnostics.

4

Homogeneity of Variance (Homoscedasticity)

Residual variance should be similar across all cells. Check with residual-vs-fitted plots or Levene's test. When this assumption fails moderately in balanced designs, the F-test remains reasonably accurate. Severe violations with unequal cell sizes require adjusted methods.

5

Correct Model Specification

The model must include the factors, interactions, and any blocking variables that actually structure the data. Omitting an important factor or including the wrong interaction structure produces biased estimates. Whether to include the interaction term is a scientific decision, not just a statistical one.

🚫
Common Misunderstanding About Normality

Two-way ANOVA does not require the raw data to be normally distributed. It requires the model residuals to be approximately normal. Skewed raw data can still produce normally distributed residuals if the groups differ mainly in means, not in variance or shape.

Two-Way ANOVA With and Without Replication

With Replication

There are multiple observations in each cell — as in our example, with five student scores per teaching-method/environment combination. Replication has two major statistical benefits: it provides an independent estimate of within-cell error variance, and it makes estimation of the A×B interaction possible in the standard way. Most two-way ANOVA designs you encounter in practice have replication.

Without Replication

The "without replication" case has exactly one observation per cell — common in certain blocked designs or when each combination of two blocking factors yields a single measurement. In the classical treatment, the standard additive model does not provide a separate, independent test of the interaction term; the interaction SS and error SS cannot be separated. Some textbooks present it as if the interaction is simply "absent by assumption," which is worth understanding: you can still run the main-effects tests, but the assumption that no interaction exists must be justified by the research context. The Tukey test for nonadditivity provides one diagnostic check.

Balanced vs. Unbalanced Designs

A balanced design has the same number of observations in every cell. This produces sums of squares that are orthogonal (independent), so the SS partition adds up cleanly and the order in which you enter factors into the model makes no difference to their SS values.

An unbalanced design has unequal cell sizes — common in observational studies and many experiments where some data points are lost. When cells are unequal, SS are no longer orthogonal and three different decompositions become relevant:

SS TypeWhat It TestsWhen to Use
Type I (Sequential)Each predictor's unique contribution given those entered before itWhen you have a specific theoretical ordering of predictors; results depend on entry order
Type II (Hierarchical)Each predictor's unique contribution given all other main effects but not interactionsWhen the interaction is not significant or not of primary interest
Type III (Marginal/Partial)Each predictor's unique contribution given all other predictors, including interactionsThe default in SPSS and most software; most appropriate when interaction is included in the model

The practical takeaway: with unbalanced data, always report which type of SS your software used, and be aware that Type I results depend on the order you enter predictors.

Effect Size for Two-Way ANOVA

A statistically significant F tells you an effect probably exists; it says nothing about whether the effect is large enough to matter. Effect size measures fill that gap. Use the effect size guide for a broader treatment. For ANOVA specifically, three measures are standard:

MeasureFormulaNotes
Eta squared (η²)SS_effect / SS_TotalProportion of total variance explained by this effect. Overestimates population effect size.
Partial eta squared (ηₚ²)SS_effect / (SS_effect + SS_Error)Proportion of variance explained by this effect after removing other effects. Most commonly reported; default in SPSS.
Omega squared (ω²)(SS_effect − df_effect × MS_Error) / (SS_Total + MS_Error)Less biased estimate of population effect size. Preferred for reporting, especially with smaller samples.

For our worked example:

Sourceηₚ² = SS / (SS + SS_Error)Rough Interpretation
Teaching Method (A)361.25 / (361.25 + 104) = 0.78Large
Environment (B)1531.25 / (1531.25 + 104) = 0.94Very large
A × B Interaction101.25 / (101.25 + 104) = 0.49Large
⚠️
Effect Size Benchmarks Are Contextual

Common guidelines (small ≈ 0.01, medium ≈ 0.06, large ≈ 0.14 for η²) were proposed by Cohen (1988) as rough benchmarks for behavioral science, not universal truths. An effect size that's "small" in one field may be practically important in another. Always interpret effect sizes in light of your specific domain and the cost of the intervention.

Power Analysis for Two-Way ANOVA

Statistical power is the probability of detecting a real effect when one exists. For two-way ANOVA, power depends on sample size, the true effect size in the population, the significance level (α), the number of cells (a × b), and within-cell variance.

Interaction effects typically need substantially larger samples than main effects because the interaction effect size is often smaller and the F-test for the interaction uses fewer degrees of freedom in some designs. A study adequately powered to detect main effects may be underpowered for the interaction.

Before collecting data, use a prospective power analysis to determine the minimum sample size per cell for the interaction effect you care about most — that's usually the effect requiring the largest n. G*Power is a free tool that handles factorial ANOVA power calculations; the sample size calculator covers basic scenarios online.

Two-Way ANOVA vs. One-Way ANOVA

Feature One-Way ANOVA Two-Way ANOVA
Number of factors12
Main effects tested12
Interaction testedNoYes (A×B)
F-statistics produced13
Can examine combined factor effects?NoYes
SS decompositionSS_Between + SS_ErrorSS_A + SS_B + SS_AB + SS_Error
Design cellsa groupsa × b cells
Typical useComparing means across one grouping variableStudying two factors and their possible interaction

Running one-way ANOVA on each factor separately is not equivalent to two-way ANOVA. Separate analyses cannot detect the interaction, inflate the familywise error rate, and may produce misleading estimates if the other factor is associated with the outcome. The correct link to one-way ANOVA is as a special case where b = 1 or the interaction is excluded by design.

Two-Way ANOVA in Statistical Software

SPSS

Navigate to Analyze → General Linear Model → Univariate. Move the outcome to the Dependent Variable box and both factors to Fixed Factors. Click Model to verify the full factorial model includes both main effects and the interaction term. Use Options to request estimated marginal means and descriptive statistics; use Post Hoc for pairwise comparisons; use Plots to generate the interaction plot. SPSS reports Type III SS by default, which is appropriate when the model includes interactions.

R

The aov() function handles two-way ANOVA. The model formula uses the asterisk operator to include both main effects and the interaction simultaneously:

R — Two-Way ANOVA
model <- aov(score ~ method * environment, data = df)
summary(model)

# For estimated marginal means and pairwise comparisons:
library(emmeans)
emmeans(model, pairwise ~ method | environment)

The * in the formula expands to method + environment + method:environment, including both main effects and the interaction. Using + alone would fit only the main effects (the additive model). For Type III SS, use car::Anova(model, type = 3).

Python

Use the statsmodels formula-based interface:

Python — Two-Way ANOVA (statsmodels)
import statsmodels.api as sm
import statsmodels.formula.api as smf
from statsmodels.stats.anova import anova_lm

model = smf.ols('score ~ C(method) * C(environment)', data=df).fit()
anova_lm(model, typ=3)

The C() wrapper tells statsmodels to treat the variable as categorical. typ=3 requests Type III SS. The pingouin library also offers a pg.anova() function with a simpler interface for common factorial designs.

Excel

Excel's Data Analysis add-in supports two-factor ANOVA. Go to Data → Data Analysis → Anova: Two-Factor With Replication (or Without Replication). Arrange your data with Factor A levels as columns and Factor B groups as labeled row blocks. Set the rows-per-sample (n per cell) and α level. Excel returns SS, df, MS, F, and the critical F value for each source. For designs more complex than a simple balanced layout, dedicated statistical software is more reliable.

Two-Way ANOVA Calculator

Two-Way ANOVA Calculator — Balanced Design (Equal Cell Sizes)

Enter cell means and the standard design parameters. All cells must have the same number of observations. For a 2×2 design: cell order is A1B1, A1B2, A2B1, A2B2. Separate values with commas.

ANOVA Table
Source SSdfMSFp-value

Common Two-Way ANOVA Mistakes

Running two separate one-way ANOVAs

This inflates Type I error, cannot detect the interaction, and may produce biased estimates when factors are correlated.

Reporting main effects without checking the interaction first

A significant interaction can make main effect averages misleading. Always examine the interaction before summarizing factor effects.

Assuming parallel lines in an interaction plot prove no interaction

Sample variation creates apparent nonparallelism even with no true interaction. Conversely, visually crossing lines don't prove statistical significance — always check the F-test.

Using the wrong SS type with unbalanced data

Type I SS in unbalanced designs gives results that change when you reorder predictors. Type III is usually appropriate when the model includes an interaction.

Ignoring assumption violations

Especially independence — which is far more damaging than non-normality. If students share a classroom or animals share a litter, standard ANOVA underestimates variance and inflates F.

Reporting p-values without effect sizes

A p < 0.001 with ηₚ² = 0.01 describes a very small effect found in a large sample. Always report effect size alongside significance.

Treating statistical significance as practical importance

A 0.5-point difference in exam scores might be statistically significant with n = 500 per cell but educationally meaningless. Connect results to domain knowledge.

Running all pairwise comparisons without correction

Every additional comparison inflates the chance of a false positive. Use Tukey HSD, Bonferroni, or another multiplicity correction when doing post hoc tests.

How to Report Two-Way ANOVA Results

Standard reporting in psychology, education, and related fields follows APA format: state each F statistic with numerator and denominator degrees of freedom, the p-value, and an effect size. Here's the template applied to our worked example:

APA-Style Reporting — Our Worked Example

Results Section Template

A two-way ANOVA examined the effects of teaching method (traditional vs. interactive) and study environment (quiet vs. noisy) on exam scores (N = 20). There was a statistically significant main effect of teaching method, F(1, 16) = 55.58, p < .001, ηₚ² = .78, with students in the interactive condition scoring higher (M = 74.00) than those in the traditional condition (M = 65.50). There was also a statistically significant main effect of study environment, F(1, 16) = 235.58, p < .001, ηₚ² = .94, with students in quiet environments scoring higher (M = 78.50) than those in noisy environments (M = 61.00). Critically, the Teaching Method × Study Environment interaction was statistically significant, F(1, 16) = 15.58, p = .001, ηₚ² = .49, indicating that the benefit of interactive teaching was greater in quiet environments (ΔM = 13.00 points) than in noisy environments (ΔM = 4.00 points).

When the interaction is not significant: "The Teaching Method × Study Environment interaction was not statistically significant, F(1, 16) = …, p = …, ηₚ² = …, and main effects are interpreted independently."

Frequently Asked Questions

Two-way ANOVA is a statistical test that simultaneously examines how two categorical independent variables (factors) affect a continuous outcome, and whether the two factors interact. It produces three F-tests: one for Factor A's main effect, one for Factor B's main effect, and one for the A×B interaction.

"Two-way" refers to the two categorical factors being analyzed. One-way ANOVA has one factor; two-way has two. The "ANOVA" (analysis of variance) part describes the method: comparing sources of variance in the outcome to determine which factors are driving differences in group means.

Yes. This happens when a factor's effect is positive at one level of the other factor and negative at another, producing a marginal mean close to the grand mean. The main effect averages to near zero, but the interaction reveals the opposite effects at different levels. An interaction plot will show crossing lines in this scenario.

It depends on the nature of the interaction. If the interaction only changes the magnitude of an effect (one factor is always better, just more so at one level of the other factor), reporting the main effect alongside the interaction can still be informative. If the interaction reverses which level is better, the main effect can be misleading and simple effects analysis is the priority.

a = 3, b = 4, N = 3 × 4 × 6 = 72. df_A = 3−1 = 2. df_B = 4−1 = 3. df_AB = (2)(3) = 6. df_Error = 72 − 12 = 60. df_Total = 71.

Tukey's HSD is widely used for pairwise comparisons after a significant main effect with three or more levels, because it controls the family-wise error rate. For a significant interaction, use simple effects analysis — test the effect of Factor A separately at each level of Factor B. Apply a multiplicity correction (such as Bonferroni) when running multiple comparisons on simple effects.

Having more than one observation in each cell. Replication lets you estimate within-cell error variance independently and test the A×B interaction directly. Without replication, the standard model cannot separately estimate interaction and error from the same data, limiting what can be tested.

Two-way ANOVA typically assumes independent observations across cells. Repeated-measures ANOVA — or a mixed-effects model — is needed when the same subjects contribute measurements across multiple factor levels. "Two-way" describes the number of factors, not the dependency structure of observations.

Two-way ANOVA is a specific type of factorial ANOVA — one with exactly two factors. Factorial ANOVA is the general term for any analysis involving two or more crossed factors. A three-way ANOVA (three factors) is also factorial; it produces seven F-tests (three main effects, three two-way interactions, one three-way interaction).

The response depends on which assumption and how severely. Moderate non-normality in balanced designs is usually tolerable. Heterogeneity of variance in unbalanced designs is more problematic — consider variance-stabilizing transformations, Welch's adjusted F, or a generalized linear model. Independence violations are serious and require a model that accounts for clustering (mixed-effects, nested ANOVA).

Partial eta squared (ηₚ²) measures the proportion of variance explained by one effect after removing all other effects. Formula: ηₚ² = SS_effect / (SS_effect + SS_Error). It's the default effect size in SPSS and is reported alongside F in APA-style papers. Values around 0.01, 0.06, and 0.14 are sometimes described as small, medium, and large by convention — but these are rough guidelines, not universal benchmarks.

Use aov(outcome ~ factorA * factorB, data = df) followed by summary(). The * operator includes main effects and the interaction. For Type III SS (needed with unbalanced data or when comparing to SPSS output), use car::Anova(model, type = 3). For estimated marginal means and pairwise comparisons, the emmeans package is standard.

Key Takeaways

⚡ Two-Way ANOVA — Core Points
  • Three F-tests: Factor A main effect, Factor B main effect, and the A×B interaction — each with its own SS, df, MS, and p-value.
  • Interaction first: Check the A×B F-test before interpreting main effects. A significant interaction changes how main effects should be understood.
  • Parallel lines in an interaction plot suggest no interaction; crossing or diverging lines suggest one — but the F-test, not the visual, determines statistical significance.
  • SS partition: SS_Total = SS_A + SS_B + SS_AB + SS_Error. Every source of variation is accounted for.
  • df: df_A = a−1, df_B = b−1, df_AB = (a−1)(b−1), df_Error = N−ab, df_Total = N−1.
  • Effect size: Report partial eta squared (ηₚ²) alongside each F statistic; p-values alone don't communicate practical relevance.
  • Interaction significance requires simple effects analysis, not just reporting main effects or declaring "significant interaction."
  • Unbalanced designs require Type III SS and careful interpretation — consult software documentation and report which SS type you used.