Correlated residuals inside a group

Today let's look at what is actually left over once a mixed model's random intercept has finished its job.

Twenty patients are enrolled in a 12 week blood pressure trial, with a check-in every week. A random intercept gives each patient their own starting level: some patients run high on average, some run low, and the intercept is exactly the number that tells them apart.

Simulate the trial, then print patient 1 and patient 2's own 12 readings.

RInteractive R
# Simulate 20 patients over 12 weekly blood pressure visits phi_true <- 0.6 innovation_sd <- 3 start_sd <- innovation_sd / sqrt(1 - phi_true^2) simulate_patients <- function(n_patients, n_weeks) { patient_rows <- list() for (patient_id in 1:n_patients) { random_intercept <- rnorm(1, mean = 0, sd = 5) residual <- numeric(n_weeks) residual[1] <- rnorm(1, mean = 0, sd = start_sd) for (week in 2:n_weeks) { residual[week] <- phi_true * residual[week - 1] + rnorm(1, mean = 0, sd = innovation_sd) } bp <- 140 + random_intercept - 1.2 * (1:n_weeks) + residual patient_rows[[patient_id]] <- data.frame(patient = patient_id, week = 1:n_weeks, bp = bp) } out <- do.call(rbind, patient_rows) out$patient <- factor(out$patient) out } set.seed(42) full <- simulate_patients(n_patients = 20, n_weeks = 12) round(full$bp[full$patient == 1], 1) #> [1] 143.5 144.3 145.0 144.3 141.9 144.8 141.3 145.0 140.5 141.4 144.5 134.8 round(full$bp[full$patient == 2], 1) #> [1] 136.9 137.8 135.1 125.9 120.5 128.1 127.3 121.9 123.0 127.4 131.6 126.6

  

Plot those same two patients to see the shape instead of just the numbers.

RInteractive R
# Plot the two patients side by side library(ggplot2) ggplot(full[full$patient %in% c(1, 2), ], aes(week, bp, color = patient)) + geom_point() + geom_line() + labs(x = "Week", y = "Systolic blood pressure")

  

Both patients drift down over the 12 weeks, which is the treatment working. Patient 2 just happens to run lower overall than patient 1, and a random intercept is built exactly to capture a difference like that: one number per patient that shifts their whole line up or down, fitted straight from the data.

But that one number per patient says nothing about the smaller week to week bounce inside each patient's own 12 readings. Is that bounce independent noise, the way a plain mixed model assumes? Or does a high week still lean on the week right before it, something a random intercept was never built to catch? Measure it properly, rather than guess at it by eye.

Here is patient 1's own run once more, so you can look at that week to week bounce up close.

Switch between the point and line view above. The same twelve readings sit there either way, with whatever link connects one week to the next still hidden inside them.

What a random intercept leaves behind

Fit the familiar random-intercept model across all 20 patients, 12 readings each, and read off the fixed effects.

RInteractive R
# Fit the familiar random-intercept model across all 20 patients library(lme4) m_lmer <- lmer(bp ~ week + (1 | patient), data = full) round(fixef(m_lmer), 3) #> (Intercept) week #> 141.190 -1.211 round(sqrt(diag(vcov(m_lmer))), 3) #> (Intercept) week #> 1.142 0.058

  

The week slope comes out at -1.211, with a standard error of 0.058, close to the true weekly drop of -1.2 used to build the data. So the fixed part of the model, the part that is the same for every patient, looks right.

Now check the part that is specific to each patient: the residuals left over once the model's own fitted line is subtracted out. If the random intercept had already caught everything that keeps a patient's readings together over time, each patient's own 12 residuals should look like independent noise, with no real link between one week's residual and the next.

Split the residuals by patient, and for each patient correlate every residual with the very next week's residual, what statisticians call the lag-1 correlation. Average that correlation across all 20 patients.

RInteractive R
# Check whether each patient's own residuals still move together week to week full$resid <- residuals(m_lmer) lag1_by_patient <- sapply(split(full$resid, full$patient), function(r) cor(r[-length(r)], r[-1])) round(mean(lag1_by_patient), 3) #> [1] 0.314

  

0.314 is nowhere close to zero. A random intercept is a single number per patient, fixed for every one of that patient's 12 weeks, so it cannot create or remove any link between neighbouring weeks on its own. Whatever is producing that 0.314 came from somewhere else, something still sitting inside the week-to-week readings themselves.