Português

Two-way ANOVA

Models and regression · reference distribution: F

When to use it

Assess at once the effect of two factors on a numeric response, and whether they interact, such as dose and sex in a trial.

Null hypothesis

For each factor, the level means are equal; for the interaction, the effect of one factor does not depend on the level of the other.

Assumptions

Test statistic

F_A = \dfrac{MS_A}{MS_{\text{error}}}, \quad F_B = \dfrac{MS_B}{MS_{\text{error}}}, \quad F_{AB} = \dfrac{MS_{AB}}{MS_{\text{error}}}

Effect size

Partial η² of each effect: factor A, factor B and the interaction.

\eta^2_p = \dfrac{SS_A}{SS_A + SS_{\text{error}}}

How to report it

Dose: F(2, 54) = 7.9, p = .001, η²p = .23. Interaction: F(2, 54) = 1.1, p = .34

In R and Python

R
summary(aov(y ~ dose * sex, data = df))
Python
import statsmodels.api as sm
import statsmodels.formula.api as smf
m = smf.ols("y ~ C(dose) * C(sex)", data=df).fit()
sm.stats.anova_lm(m, typ=2)

In Python, stats is scipy.stats and np is numpy.

Variants and alternatives

Where it sits in the catalog

Models and regression. Tests run inside a fitted model: whether a coefficient matters, whether the model explains anything and whether the residuals meet the assumptions.

In the decision tree

  1. What do you want to do? Compare groups, or one group with a reference value
  2. What kind of response did you measure? Numeric: a measurement, such as weight, time or score
  3. How many groups or measurements? Two factors at once, such as dose and sex

Open the decision tree