Explained Variance in Multilevel Models

Mark Andrews

\(R^2\) in ordinary linear regression

Four equivalent definitions, all yielding the same value.

\[ R^2 = 1 - \frac{\mathrm{Var}(\hat\epsilon)}{\mathrm{Var}(y)} = \frac{\mathrm{Var}(\hat y)}{\mathrm{Var}(y)} = \frac{\mathrm{Var}(\hat y)}{\mathrm{Var}(\hat y) + \mathrm{Var}(\hat\epsilon)} \]

m <- lm(dist ~ speed, data = cars)
summary(m)$r.squared
1 - var(residuals(m)) / var(cars$dist)

The complication in mixed models

In a mixed effects model, predictions can be formed in two ways.

Marginal prediction. Fixed effects only: expected outcome for a hypothetical new individual drawn from the population.

Conditional prediction. Fixed plus random effects: expected outcome for a specific individual whose random effects are known.

M7 <- lmer(rt ~ day + (day | id), data = pvtrt)
head(predict(M7))             # conditional
head(predict(M7, re.form = NA))  # marginal

Conditional versus marginal predictions

add_predictions(pvtrt, M7) |>
  ggplot(aes(x = day, y = rt, colour = id)) +
  geom_point() + geom_line(aes(y = pred)) +
  facet_wrap(~id) + theme(legend.position = "none") +
  labs(title = "Conditional predictions (fixed + random effects)")

Marginal \(R^2\) and conditional \(R^2\)

Marginal \(R^2\): proportion of variance explained by fixed effects alone.

Conditional \(R^2\): proportion of variance explained by the full model (fixed plus random effects).

\[ R^2_\mathrm{marginal} = \frac{\mathrm{Var}(\hat y_\text{fixed})}{\mathrm{Var}(y)}, \qquad R^2_\mathrm{conditional} = \frac{\mathrm{Var}(\hat y_\text{full})}{\mathrm{Var}(y)} \]

The gap between them reflects the contribution of the random effects.

Nakagawa and Schielzeth (2013)

The naive formula above is an approximation. The proper method partitions the total variance into components from the model directly:

\[ \sigma^2_\mathrm{total} = \sigma^2_\mathrm{fixed} + \sigma^2_\mathrm{random} + \sigma^2_\mathrm{residual} \]

r2_nakagawa(M7)

Interpreting the values

A low marginal, high conditional \(R^2\) means that most structure in the data is due to individual differences rather than the fixed predictors. The random effects are doing the heavy lifting.

A high marginal \(R^2\) means the fixed effects explain much of the variance even before accounting for individual variation.

M8 <- lmer(rt ~ day + (1 | id), data = pvtrt)
r2_nakagawa(M8)

Comparison across models

M_null <- lmer(rt ~ 1 + (day | id), data = pvtrt)
r2_nakagawa(M_null)
r2_nakagawa(M8)
r2_nakagawa(M7)

Adding day as a fixed effect increases marginal \(R^2\). Conditional \(R^2\) remains high across all models because subject-level random effects capture substantial individual variation regardless of the fixed effects structure.