Which Test?

Draft: This page has not been reviewed by a statistician yet. Use it as a starting point and check important choices with a statistician.

Two-way ANOVA

Compares the mean of a measurement between the groups formed by two factors, and tests whether the effect of one factor depends on the other (an interaction).

Clinical example

Mean hemoglobin one week after treatment with one of two iron supplements, in men and in women. Two factors (supplement and sex), one measurement per patient, and the question is whether the supplement works differently in men and women.

When to use it

  • The outcome is a measurement on a continuous scale, one per patient.
  • The groups are formed by combining two categorical factors, such as supplement and sex, and each patient is in one combination.
  • You want the effect of each factor, or you want to know whether the effect of one factor depends on the other (an interaction).
  • For one factor use one-way ANOVA. To adjust for a baseline value or for continuous variables, see ANCOVA or linear regression.

Assumptions to check

Independent observations

One value per patient, and no clustering. Repeated measurements or clustered patients need a mixed model.

Roughly normal residuals, no extreme outliers

Look at a histogram or Q-Q plot of the residuals. With moderate, similar-sized groups, mild non-normality is usually acceptable. A single extreme value can still drive the result. For a skewed, always-positive outcome, the same model can be fitted on the log scale, and the effects are then ratios.

Equal spread in every combination

Compare the SDs of the combinations. A much larger SD in one of them is a warning sign. It matters most when the numbers per combination differ. Consider a transformation or robust (sandwich) standard errors.

Enough patients in every combination

Empty or very small combinations make the estimates, and especially the interaction, unstable.

Unequal numbers per combination

With unequal numbers, the test of each factor depends on how the sums of squares are calculated. R's anova() uses sequential (Type I) tests, so the main-effect rows depend on the order of the terms, while SPSS uses Type III by default. The interaction row is the same either way. Estimates and CIs from the fitted model (emmeans in R) avoid the problem.

What to report

  • Mean with SD, and the number of patients, for each combination of the two factors
  • The test of the interaction: the F statistic with both degrees of freedom, and the exact p-value
  • If there is no important interaction: the effect of each factor as a difference in means with 95% CI. If there is: the effect of one factor within each level of the other, with 95% CI
  • How pairwise comparisons were adjusted for multiple comparisons
  • How the factors were coded, and the type of sums of squares if the numbers per combination differ
  • The number of patients analyzed, and how many were left out because of missing data

Common mistakes

Don't run many separate tests

Testing every pair of groups, outcome or time point separately piles up false positives. Use one model, prespecify the main comparison, and correct for multiple comparisons where needed.

Don't dichotomize a measurement

Cutting a continuous variable into high and low ("BP above 140") throws away information and power, and the cut-off is often arbitrary.

Reading the main effects as if they applied to everyone when there is an interaction. They are averages over the levels of the other factor.

Concluding that an effect differs between subgroups because it is significant in one and not in the other. Test the interaction, or compare the effects directly.

Reading a non-significant interaction as proof that the effect is the same in every subgroup. Interaction tests usually have low power.

Comparing R and SPSS output with unequal group sizes without noticing that they use different types of sums of squares.

In R, coding a factor as numbers (1, 2, 3) without making it a factor. The model then fits one slope instead of comparing the groups, and gives no error.

Alternatives

If your situation is…Use
Only one factorOne-way ANOVA
A baseline measurement is available, as in a trialANCOVA (adjusting for baseline)
You need to adjust for continuous variablesLinear regression
The same patients are measured under every combination, or patients are clusteredLinear mixed model
Yes/no outcomeLogistic regression

In your software

R
# R
d$supplement <- factor(d$supplement)   # factors, not numbers
d$sex <- factor(d$sex)
fit <- lm(hb ~ supplement * sex, data = d)   # both factors and their interaction
anova(fit)   # the supplement:sex row is the test of the interaction
nobs(fit)    # patients used: missing values are dropped silently
library(emmeans)
# effect of supplement within each sex, with 95% CI (new minus standard)
confint(pairs(emmeans(fit, ~ supplement | sex), reverse = TRUE))
interaction.plot(d$sex, d$supplement, d$hb)   # roughly parallel lines: little interaction
SPSS
* Type III sums of squares are the SPSS default. EMMEANS compares supplement within each sex.
UNIANOVA hb BY supplement sex
  /METHOD=SSTYPE(3)
  /PLOT=PROFILE(sex*supplement)
  /EMMEANS=TABLES(supplement*sex) COMPARE(supplement)
  /PRINT=DESCRIPTIVE HOMOGENEITY
  /CRITERIA=ALPHA(.05)
  /DESIGN=supplement sex supplement*sex.