0

I run a Linear Mixed-Effects Models (LMMs) with a repeated measures design with the lmer function on R.

    mod <- lmer(response ~ factor1*factor2 + (1|ID_repeated), 
                data=db)

What covariance structure is implemented on the lmer function and how I can change it, in case?

I couldn't find any information about that!

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
Alice
  • 31
  • 3

1 Answers1

1

The model as you have written it for lmer() only allows for a Gaussian distribution of the random intercept terms among the individuals, that is, the estimated response when both factor1 and factor2 are at their reference levels (under standard treatment coding).

The lme() function allows for more detailed specification of covariance structure. This page is a useful guide to how these two functions can be called to model the same experimental designs, and for how lme() can be invoked to specify covariance structure.

EdM
  • 57,766
  • 7
  • 66
  • 187
  • Thank you so much for your comment and suggestions! – Alice Aug 16 '20 at 16:23
  • Maybe I applied the wrong function and missed something in the model. Could you please specify what you mean with "when both factor1 and factor2 are at their reference levels (under standard treatment coding)"? My factors are two categorical variables of space and time. Factor 1 has 2 levels (site 1 - site 2) and factor 2 has 4 levels (4 different days). My ID are the replicates. Thanks in advance! – Alice Aug 16 '20 at 16:28
  • @Alice the default in R (unlike some other software) is to take the _lowest_ level of a categorical predictor as the reference. So if `site1` is the reference level for `factor1` and say `day0` is the reference level for `days`, the random intercepts will be the _estimated_ values of `response` if an individual had been at `site1` on `day0`. Those are values estimated by the model; an individual doesn't need to have been at `site1` on `day0` to have such an estimate made. With your model, all effects of `site2`, other `days`, and the interactions will be the same for all individuals. – EdM Aug 16 '20 at 17:28
  • Thanks again for this explanation and thanks for your patience. I'm a newbie both with R and these models. May I ask you another question? How would you modify then the model if you wanted to see the effects of factor 1 (site), factor 2 (time), and their interactions on the response variable? (always with ID as a replicate). If it would take too long to answer, no problem, thanks anyway! – Alice Aug 16 '20 at 19:46
  • @Alice the model as you wrote it will estimate fixed effects for all of those with respect to the response, taking into account the random _intercepts_ among the IDs. If you think that the effect of `site` or `time` might differ among individuals in a way that you need to account for, then you can specify random _slopes_ for `site` or `time`, too. [This page](https://stats.stackexchange.com/q/13166/28500) and its links show how to code such random effects. Just be careful, as you can easily run out of enough data to fit all the effects you might want to consider. – EdM Aug 16 '20 at 20:03
  • Now everything is more clear! Thanks for your patience and your help! – Alice Aug 16 '20 at 20:22
  • 1
    Random slopes can generate some interesting correlation patterns but I prefer to use serial correlation models most of the time, e.g., generalized least squares or Markov models. – Frank Harrell Oct 13 '21 at 12:42