ANCOVA

Analytika TeamLast reviewed 7 min read

Analysis of covariance blends ANOVA with regression. It answers questions like “do the groups differ at the end of the study, allowing for where they started?” or “is there a difference between groups beyond what a background variable explains?”.

Two reasons to use ANCOVA

  • Power: a covariate that predicts the outcome (such as a pre-test score) removes noise, making group differences easier to detect. This is the main use in randomised trials.
  • Adjustment: comparing groups that differ on the covariate. This needs more caution, because it only adjusts for what you measured.

Worked example: transmission and fuel economy, adjusting for power

In R’s mtcars data, manual cars average 24.4 mpg and automatics 17.1. But automatics in this sample also tend to be more powerful. How big is the transmission difference among cars of equal horsepower?

Analytika engine output (abridged)
Design: ANCOVA (Type III sums of squares, sum-to-zero contrasts)
Outcome: mpg
Factor: am (2 levels)
Covariate: hp
N: 32
Effect: am || ss=202.2350, df=1, ms=202.2350, F=23.8952, p=3.46e-05, pes=0.4517, ci=[0.1811, 0.6402]
Effect: hp || ss=475.4573, df=1, ms=475.4573, F=56.1779, p=2.92e-08, pes=0.6595, ci=[0.4342, 0.7822]
Residual: ss=245.4393, df=29, ms=8.4634
R-squared: 0.7820
Cell: am=1 || mean=24.3923, sd=6.1665, n=13
Cell: am=0 || mean=17.1474, sd=3.8340, n=19
Adjusted mean: am=1 || mean=23.2239, se=0.8218
Adjusted mean: am=0 || mean=17.9468, se=0.6759
Levene (residuals by cell): F=3.9919, df=1, 30, p=0.05485
Residual normality p: 0.6443
Homogeneity of slopes: F=0.0006, df=1, 28, p=0.9806

These results match R, and the case is part of Analytika’s test suite.

Check the assumptions first

  • Homogeneity of slopes: F(1, 28) = 0.00, p = .981. The horsepower slope is the same for both transmissions, so a single adjustment is valid.
  • Equal variances: Levene p = .055, borderline but acceptable.
  • Residual normality: p = .644, fine.

Interpretation

  • Transmission: F(1, 29) = 23.90, p < .001, partial η² = .45.
  • The raw gap was 7.2 mpg. Adjusted to the same horsepower, the means are 23.2 (manual) and 17.9 (automatic), a difference of 5.3 mpg (95% CI 3.1 to 7.5). Part of the raw gap was due to horsepower, but most of it remains.
  • Horsepower is itself a strong predictor: F(1, 29) = 56.18, p < .001.

APA write-up

An ANCOVA controlling for horsepower showed that fuel economy differed by transmission, F(1, 29) = 23.90, p < .001, η²p = .45. Adjusted for horsepower, manual cars (Madj = 23.22) averaged 5.28 mpg more than automatic cars (Madj = 17.95), 95% CI [3.07, 7.48]. The assumption of homogeneous regression slopes was met, F(1, 28) = 0.00, p = .981.

These are observational data: “adjusted for horsepower” isn’t the same as “caused by transmission”.

Assumptions

  • Independent observations, and normal residuals with equal variances across groups.
  • A linear covariate–outcome relationship.
  • Homogeneity of regression slopes: test the group × covariate interaction. If it’s significant, the group difference depends on the covariate, so use a model with that interaction instead.
  • The covariate is measured before the treatment and isn’t affected by it.

How to run it

  • SPSS: Analyze → General Linear Model → Univariate, with the covariate in Covariate(s). EM Means gives adjusted means.
  • R: car::Anova(lm(y ~ group + covariate), type = 3), plus emmeans for adjusted means.
  • Analytika: ask, for example, “does mpg differ by transmission, controlling for horsepower?”. It reports adjusted means and tests homogeneity of slopes. See also two-way ANOVA.

More in Comparing groups

Run this on your own data

Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.

Try it free