When we use the mixed effects model for longitudinal data (repeated measures within subjects), with random intercepts for subjects, I know that the shortcoming when using packages such as lme4 in R is that intra-class correlation is constant within subjects. That means that the correlation between time points 1 and 2 is the same as between 1 and 5, but we often expect that the correlation would fall the farther away the time points are.

In this answer by Dimitris Rizopoulos:

What is the procedure to specify a random effects design matrix?

he says:

... in longitudinal data, you want to include functions of time in the random effects design matrix to account for the serial correlations.

Can anyone explain what this means, and perhaps give the example ? Is it as simple (in simple cases!) as specifying a linear random slope for time ?

Also, can anyone explain how this accounts for autocorrelation in mixed models ? I know that some software such as nlme in R allows the specification of and AR1 and other structures, which I can understand. I just don't understand how using specifying "functions of time in the random effects design matrix" works.


1 Answer 1


Indeed, when you include functions of time in the design matrix of the random effects you account for serial correlations in the repeated measurements data. The more complex functions of time you include (e.g., nonlinear time effects), the more flexibility you allow.

A practical illustration of this is given in Chapter 3, Section 3.3 of this shiny app. By selecting something more than random intercepts, and changing the values for the variance components you can see how the serial correlations vary.

In the corresponding sections of my course notes, and in particular, slide 160 you can see the technical justification for this.

  • $\begingroup$ Thank you for a speedy response. And thanks for the links. The course looks fantastic and it's amazing that you provide it for free ! I will definitely check it out soon (and the app). But in the meantime, just so I am clear on it, you are talking about adding random slopes ?? It's just that I have no idea how to change or specify a design matrix for random effects. I assume the software does that when you put something like (time|subj) or (time + time^2|subj) instead of just (1|subj) ? $\endgroup$
    – Lynchian
    Nov 27, 2023 at 19:17
  • 1
    $\begingroup$ Correct, (time | subj) denotes linear random slopes, (time + I(time^2) | subj) denotes linear and quadratic random slopes (it is better to use (poly(time, 2) | subj)), and (ns(time, 2) | subj) denotes a natural cubic spline for the time effect. In all of these expressions, the random intercepts are included by default. $\endgroup$ Nov 27, 2023 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.