1

I am trying to specify a linear mixed model using lme4, and do not completely understand how to specify a crossed random effects structure.

The study design looks like this:

  • we have n subjects (id)
  • who were measured twice (time: Pre, Post)
  • in both legs (leg: Dominant, Non-Dominant)
  • and in each measurement (id:time:leg) we took the same measurement 5 times (sample).

I am interested in the effect of time, leg and their interaction. However, as far as I understand, there are some crossed random effects I should take care of, since both explanatory variables have been measured within the same participants... So here begin my doubts:

  1. Is the following model specification correct?
lmer(value ~ time * leg + (1 | id) + (1 | id:leg) + (1 | id:time), data)
  1. Is it reasonable in this case to specify the same variables as fixed as well as random effects?

  2. If not, what alternatives should I consider?

  3. I struggle to understand too, whether I should specify a random intercepts-only model, or include random slopes as well. This might be too much to ask but... could you help me understand the practical difference between random slopes for time (time | id) versus crossed random intercepts for id and time (1 | id) + (1 | id:time) in this example?

Thank you in advance

Robert Long
  • 53,316
  • 10
  • 84
  • 148
rcirer
  • 53
  • 5

1 Answers1

1

Is the following model specification correct?

The model:

value ~ time * leg + (1 | id) + (1 | id:leg) + (1 | id:time)

has the following features:

  • fixed/global intercept
  • fixed effects for time and leg and the interaction between them
  • random intecepts for id
  • random intercepts for leg varying within id
  • random intercepts for time varying within id

This model specifies that leg and time are random factors which are nested within a further random factor id. It seems clear that you have repeated measures within id, but since your research question is specifically about the fixed effects of time and leg and the interaction between them, these variables should not also be random.

Is it reasonable in this case to specify the same variables as fixed as well as random effects?

No, either they should be random (when you don't care about their fixed effects, or when there are a very large number of them, or when they are samples from a larger population, none of which apply here), or they should be fixed (when your research question is speficially about their estimates).

If not, what alternatives should I consider?

I would suggest:

value ~ time * leg + (1 | id)

I struggle to understand too, whether I should specify a random intercepts-only model, or include random slopes as well.

Random slopes are indicated where a fixed effect is expected to vary within subjects that you are specifying a random intercept for. Quite often there is reasonable theoretical grounds to fit many variables are random slopes however this often leads to overfitting and a singular fit.

This might be too much to ask but... could you help me understand the practical difference between random slopes for time (time | id) versus crossed random intercepts for id and time (1 | id) + (1 | id:time) in this example?

When you write: (time | id) you are speciying random intercepts for id, and random slopes for time. That means each subject (id) will have their own slope for time. The soiftware will estimate a global slope (the fixed effect for time and then each id will have their own slope which is an offset from the global slope.

Please note that (1 | id) + (1 | id:time) does not specify crossed random effects. It specifies nested random effects. In particular, it specifies that time is nested within id. For an explanation of the difference between crossed and nested random effects see here:
Crossed vs nested random effects: how do they differ and how are they specified correctly in lme4?

Robert Long
  • 53,316
  • 10
  • 84
  • 148