Launch StatClinic →
Statistical Tests

How to Perform Two-Way ANOVA in Medical Research Using StatClinic

📖 15 min read 🗓 July 2026 ✓ Updated July 2026
S
StatClinic Editorial Team Statistical content for medical researchers and clinicians
Most clinical questions don't involve just one variable of interest. Does a drug's effect depend on the dose? Does a surgical technique work differently in men and women? Does a rehabilitation program's benefit depend on baseline severity? Whenever your research question involves two categorical factors acting on one continuous outcome — and especially whenever you suspect they might interact — two-way ANOVA is the test built for exactly that. This guide walks through what it tests, when it applies, how to set up your data, a full worked clinical example, and exactly how to run and report it using StatClinic.
Key Takeaways
  • Two-way ANOVA tests the effect of two categorical factors on one continuous outcome simultaneously — and, critically, whether the two factors interact.
  • A significant interaction effect means the effect of one factor genuinely depends on the level of the other — this is information a series of separate one-way ANOVAs can never reveal.
  • When the interaction is significant, main effects must be interpreted cautiously, and a simple-effects analysis is usually the more informative follow-up.
  • Report F statistics, p-values, effect sizes (partial η²), and confidence intervals for both main effects and the interaction — never the p-value alone.
  • Two-way ANOVA assumes independent, between-subjects groups — repeated measurements on the same subjects need a different model entirely.

What Is Two-Way ANOVA?

Two-way ANOVA (analysis of variance) is a statistical test that examines how two categorical independent variables, called factors, jointly affect a single continuous outcome. It extends one-way ANOVA — which handles only one factor — by testing three separate questions at once: does Factor A affect the outcome, does Factor B affect the outcome, and does the combination of A and B produce an effect that neither factor alone would predict.

That third question — the interaction effect — is what makes two-way ANOVA more than just "two one-way ANOVAs run together." It is often the most clinically interesting result in the entire analysis, because it can reveal that a treatment's benefit genuinely depends on a second variable, a pattern a series of separate tests would miss entirely.

In Plain Terms

One-way ANOVA answers "does this one variable make a difference?" Two-way ANOVA answers three questions in a single, correctly structured model: "does Factor A matter, does Factor B matter, and does it matter that they're combined?"

When Should You Use Two-Way ANOVA?

Two-way ANOVA is the right test when your study meets all of the following conditions:

If you only have one factor, use one-way ANOVA. If your outcome is measured repeatedly on the same subjects across factor levels, you need a repeated-measures or mixed-design ANOVA instead, not the standard between-subjects model covered here.

Independent Variables, Factors, Levels, and Continuous Outcomes

Getting the vocabulary precise here prevents a surprising number of downstream errors in both analysis and reporting.

TermDefinitionClinical Example
FactorA categorical independent variableDrug Type; Dose
LevelA specific category within a factorDrug Type: Ibuprofen / New Drug X
CellOne specific combination of factor levelsIbuprofen + High Dose
Continuous outcomeThe dependent variable being measuredPostoperative pain reduction score

A design with two factors, each having two levels, is called a 2×2 factorial design and produces four cells in total. A 2×3 design (two levels of one factor, three of the other) produces six cells, and so on — the number of cells is always the product of the number of levels in each factor.

Main Effects and Interaction Effects

A main effect is the effect of one factor on the outcome, averaged across all levels of the other factor. The main effect of Drug Type, for instance, compares Ibuprofen versus Drug X overall, collapsing across both dose levels.

An interaction effect exists when the effect of one factor changes depending on the level of the other. Visually, this shows up as non-parallel lines on an interaction plot — if increasing the dose helps Drug X far more than it helps Ibuprofen, the lines for the two drugs will diverge or cross rather than running parallel.

Why This Matters Clinically

If Drug X only works well at a high dose, but Ibuprofen's effect barely changes with dose, then the honest, clinically useful conclusion is "the right dose depends on which drug is used" — a conclusion that only the interaction term can reveal. Reporting the two main effects alone, without checking the interaction, would miss the actual clinical story entirely.

Take-Home Points Always check the interaction term first. If it's significant, interpret it before — and instead of — leaning heavily on the main effects, since the main effects can average away exactly the pattern that matters most.

Two-Way ANOVA vs One-Way ANOVA

FeatureOne-Way ANOVATwo-Way ANOVA
Number of factors12
What is testedOne main effect, across 3+ groupsTwo main effects plus one interaction
Example questionDoes pain score differ across 3 drug doses?Does pain score differ by drug type and dose, and do they interact?
Can detect an interactionNoYes
Groups comparedk levels of the single factora×b cells (every factor combination)

Running two separate one-way ANOVAs instead of one two-way ANOVA is a common shortcut that quietly loses the interaction entirely, and also inflates the overall false-positive rate by running multiple tests where one correctly structured test would do — a pattern covered further in common statistical mistakes.

Factorial Study Designs

A study built around two factors and analyzed with two-way ANOVA is called a factorial design. In a fully-crossed factorial design, every level of Factor A is combined with every level of Factor B, so every cell is represented — this is what standard two-way ANOVA assumes.

A balanced design has an equal (or near-equal) number of subjects in every cell; an unbalanced design has unequal cell sizes, which is common in observational or pragmatic clinical research and requires the software to use an appropriate calculation method (commonly Type II or Type III sums of squares) to avoid biased estimates of the main effects and interaction.

Assumptions and Requirements

1

Continuous outcome

The dependent variable should be measured on a continuous (interval or ratio) scale.

2

Independence of observations

Each subject contributes data to exactly one cell; cells are independent of one another.

3

Normality of residuals

The model's residuals (not necessarily the raw outcome) should be approximately normally distributed within each cell — check with Shapiro-Wilk or a Q-Q plot.

4

Homogeneity of variance

Variance of the outcome should be similar across all cells, not just two groups — check with Levene's test across the full set of cells.

5

No severe outliers

Extreme values within a single cell can disproportionately distort that cell's mean and the resulting F statistics.

6

Reasonably adequate cell sizes

A common planning guideline is at least 15–20 subjects per cell for adequate power, particularly to detect the interaction term.

These are the same core assumption categories covered in our statistical assumptions guide, applied specifically across every cell of the factorial design rather than just two groups.

How to Arrange Your Dataset

Two-way ANOVA requires long format: one row per subject, with separate columns for each factor and one column for the continuous outcome — not a cross-tabulated or wide summary table.

Patient IDDrug TypeDosePain Reduction Score
001IbuprofenStandard3.1
002Drug XHigh6.4
003IbuprofenHigh3.8
............

Make sure factor levels are entered as consistent categorical labels (not accidentally coded as numbers that software might treat as continuous), and that each patient appears exactly once, since this model assumes independent, between-subjects groups.

A Realistic Medical Research Example

A research team studies postoperative pain management after knee surgery, comparing two factors: Drug Type (standard ibuprofen vs. a new analgesic, Drug X) and Dose (standard vs. high). Eighty patients are randomized into four groups of 20 (a balanced 2×2 design), and pain reduction is measured on a 0–10 scale 48 hours after surgery.

CellnMean Pain Reduction
Ibuprofen + Standard Dose203.2
Ibuprofen + High Dose203.6
Drug X + Standard Dose203.4
Drug X + High Dose206.1
What This Pattern Suggests

Ibuprofen's benefit barely changes with dose (3.2 → 3.6), but Drug X's benefit nearly doubles at the higher dose (3.4 → 6.1) — exactly the diverging pattern that signals a likely interaction, which the two-way ANOVA will formally confirm or rule out.

Step-by-Step Analysis Using StatClinic

1

Enter your dataset in long format

One row per patient, with Drug Type, Dose, and Pain Reduction Score as three separate columns.

2

Confirm your study design

Tell StatClinic you have two independent categorical factors and one continuous outcome — this routes the analysis to the factorial ANOVA family.

3

Let StatClinic check assumptions automatically

StatClinic tests normality of residuals and homogeneity of variance across all four cells, flagging any violation before you interpret results.

4

Run the Two-Way ANOVA

Confirm the recommended test, or select it directly if you already know it's the right model for your design.

5

Review main effects, interaction, and effect sizes

StatClinic returns F statistics, p-values, partial η² for each term, and confidence intervals for the key mean differences.

6

Follow up a significant interaction

If the interaction is significant, StatClinic guides you through simple-effects comparisons and generates ready-to-use Methods and Results text.

You can also run the calculation directly with the Two-Way ANOVA Calculator once your cell data are ready.

Interpreting Main Effects, Interaction, F Statistics, P Values, Effect Sizes, and CIs

For the knee surgery example, StatClinic's output might read as follows:

EffectF (df1, df2)P-ValuePartial η²
Main effect: Drug TypeF(1, 76) = 18.42p < .0010.195
Main effect: DoseF(1, 76) = 25.70p < .0010.253
Interaction: Drug Type × DoseF(1, 76) = 14.03p < .0010.156

Reading this in order: the F statistic is the ratio of variance explained by that term to residual (unexplained) variance — larger values indicate a stronger effect relative to noise. The p-value tells you how unlikely this pattern would be if that effect were truly absent. Partial η² tells you the effect's magnitude independent of sample size (0.01 small, 0.06 medium, 0.14 large, by Cohen's convention). Because the interaction is significant here, the two main effects — while also significant — should not be interpreted as if each drug or dose behaves identically across the other factor; a simple-effects analysis, covered next, clarifies what's actually happening. Confidence intervals around each specific mean difference (for example, the 2.7-point gain in Drug X between standard and high dose) should also be reported to convey precision, not just significance.

Simple-Effects and Post Hoc Analysis After a Significant Interaction

When the interaction term is significant, the most informative follow-up is usually a simple-effects analysis: testing the effect of one factor separately at each level of the other, rather than relying on the averaged main effect.

Simple-Effects Results (Example)

Effect of Dose within Drug X: mean difference = 2.7 points, 95% CI [1.9, 3.5], p < .001 — a large, significant benefit of the higher dose. Effect of Dose within Ibuprofen: mean difference = 0.4 points, 95% CI [-0.3, 1.1], p = .28 — no meaningful benefit of the higher dose. This is exactly the pattern the significant interaction predicted, and it's the level of detail the main effects alone could not provide.

Simple-effects comparisons should use an appropriate correction for multiple comparisons (commonly Bonferroni) since several comparisons are being tested from the same dataset. If the interaction is not significant, the main effects can be interpreted directly, and standard post hoc tests such as Tukey's HSD remain appropriate for any factor with three or more levels.

How to Report the Methods and Results

A complete report states the design, the test used, and the full pattern of results — main effects, interaction, and any simple-effects follow-up — following the conventions in our guide to writing statistical results by test.

Sample Methods Text

"A two-way between-subjects ANOVA was conducted to examine the effects of drug type (ibuprofen vs. new analgesic) and dose (standard vs. high) on postoperative pain reduction scores measured 48 hours after surgery."

Sample Results Text

"There was a statistically significant interaction between drug type and dose on pain reduction, F(1, 76) = 14.03, p < .001, partial η² = 0.16. Simple-effects analysis showed that increasing dose significantly improved pain reduction for the new analgesic (mean difference = 2.7, 95% CI [1.9, 3.5], p < .001) but not for ibuprofen (mean difference = 0.4, 95% CI [-0.3, 1.1], p = .28)."

Common Mistakes

Mistake 1: Interpreting Main Effects While Ignoring a Significant Interaction

Reporting "Drug X was significantly better overall" when a significant interaction means that conclusion only holds at one dose level, not across the board.

✓ Fix: Always check the interaction first, and follow up with simple effects when it's significant.

Mistake 2: Running Two One-Way ANOVAs Instead of One Two-Way ANOVA

Analyzing the two factors in two entirely separate one-way ANOVAs, which misses the interaction entirely and inflates the overall Type I error rate.

✓ Fix: Use a single two-way ANOVA model whenever both factors and their possible interaction matter to the research question.

Mistake 3: Treating a Continuous Variable as a Factor Without Justification

Arbitrarily splitting a continuous variable like age into "young" and "old" groups purely to force it into the two-way ANOVA framework, discarding information.

✓ Fix: If a variable is naturally continuous, consider ANCOVA instead of converting it into an artificial categorical factor.

Mistake 4: Ignoring Unbalanced Cell Sizes

Not accounting for unequal numbers of subjects per cell, which can bias estimates of the main effects and interaction if the wrong calculation method is used.

✓ Fix: Confirm your software is using an appropriate method (commonly Type II or III sums of squares) for unbalanced data.

Mistake 5: Checking Homogeneity of Variance for Only Two Groups

Running Levene's test on a simplified two-group comparison instead of across all four (or more) cells of the actual factorial design.

✓ Fix: Test homogeneity of variance across every cell in the full design, not a collapsed subset.

Mistake 6: Skipping Simple-Effects Analysis After a Significant Interaction

Reporting a significant interaction and moving on without ever formally testing where the effect differs, leaving readers to guess from a plot alone.

✓ Fix: Run and report formal simple-effects comparisons with corrected p-values and confidence intervals.
❌ Incorrect

"Drug Type had a significant main effect (p < .001), so Drug X is better than ibuprofen for all patients regardless of dose."

✅ Correct

"There was a significant Drug Type × Dose interaction; Drug X was significantly better than ibuprofen at the high dose, but not at the standard dose" — reflecting what the simple-effects analysis actually showed.

Frequently Asked Questions

What is the difference between a main effect and an interaction effect? +
A main effect is the effect of one factor averaged across all levels of the other factor. An interaction effect exists when one factor's effect depends on the level of the other — for example, a drug working well at high dose but not low dose, while a comparison drug shows the opposite. A significant interaction means main effects alone can be misleading.
Can two-way ANOVA be used with unequal group sizes? +
Yes, but unbalanced designs need care. Software typically uses Type II or Type III sums of squares to handle unequal cell sizes correctly, though severe imbalance can still reduce power, especially for detecting the interaction. A balanced design remains more statistically efficient when achievable.
What does it mean when the interaction is significant but a main effect is not? +
It usually means the averaged effect is hiding genuinely different, sometimes opposite, effects at different levels of the other factor that cancel out when averaged. Don't interpret the non-significant main effect as "no effect" — run a simple-effects analysis to see what's actually happening.
How many factors and levels can two-way ANOVA handle? +
Exactly two factors, each with two or more levels — a 2×2 design is simplest, but 2×3, 3×3, and larger combinations are equally valid. Adding a third factor turns the analysis into a three-way ANOVA, with an additional three-way interaction term.
What effect size should I report for two-way ANOVA? +
Partial eta squared (partial η²) is standard for each main effect and the interaction. Using Cohen's adapted benchmarks, around 0.01 is a small effect, 0.06 medium, and 0.14 or above large — conventions, not fixed clinical cutoffs.
Do I need post hoc tests after two-way ANOVA? +
If a main effect is significant for a factor with 3+ levels, use a post hoc test like Tukey's HSD. If the interaction is significant, a simple-effects analysis is usually more appropriate than a generic post hoc test, since it directly addresses how the factors combine.
What is the non-parametric alternative to two-way ANOVA? +
There's no single universally agreed equivalent that fully replicates the interaction test. The Scheirer-Ray-Hare test extends Kruskal-Wallis logic to two factors, though it's less widely available; many researchers instead transform the data (e.g., log transform) to use standard two-way ANOVA validly.
Can two-way ANOVA be used for repeated measures? +
The standard two-way ANOVA assumes between-subjects groups. When one or both factors involve repeated measurements on the same subjects, a repeated-measures or mixed-design ANOVA is required instead, since these explicitly model the correlation between repeated observations.
How is two-way ANOVA different from ANCOVA? +
Two-way ANOVA examines two categorical factors on a continuous outcome. ANCOVA additionally adjusts for one or more continuous covariates (like baseline severity) that aren't the primary interest but may improve precision. Combining both is sometimes called a two-way ANCOVA.
What sample size do I need for two-way ANOVA? +
It depends on the expected effect sizes, number of cells, and desired power, and should be calculated formally beforehand. A rough planning guideline is at least 15–20 subjects per cell for adequate power, with the interaction typically needing a larger sample than either main effect alone.

Once your two-way ANOVA is run, these guides take you through the surrounding decisions:

Ready to Run Your Two-Way ANOVA?

Let StatClinic's AI Statistical Assistant confirm the right test, run your analysis, and write your results sentence. Free, no registration required.

Try StatClinic Free →