8
$\begingroup$

I have a repeated measures from clusters, over several years, and I expect the cluster effect to vary each year. Year is coded as a factor, with '1' as reference level. I have tried the following:

mod1 <- lmer(y ~ x + year + (year|cluster))

and

mod2 <- lmer(y ~ x + year + (1|cluster:year))

My first example specifies the following random effects:

ranef(mod1)
$cluster
    (Intercept)  year2         year3        year4         year5
AA   0.03721015  0.0573160920 -0.114709171  0.1588302187  0.125329740
AB  -0.12958994 -0.0458997003  0.216455596  0.2345170893  0.248950509
AC  -5.10692972 -0.1311546328  1.130347798  2.5215580167  5.070106525
AD   0.10087455 -0.2677088515 -0.345583355 -0.2442831982 -0.257074662
....

Second one specifies:

ranef(mod2)
$`cluster:year`
              (Intercept)
AA:year2  0.0838186244
AA:year3 -0.1197284361
AA:year4  0.1944488619
AA:year5  0.1562090690

I assumed they would be equivalent, given year is a factor, but I must not understand the random effect specification of lme4 well enough. Can anyone help me understand the difference between the two parameterizations?

$\endgroup$

1 Answer 1

11
$\begingroup$

At first sight, there are two main differences:

  1. mod1 is a random intercept and random slope model while mod2 is a random intercept model (without random slope): (year|cluster) implicitly includes the intercept and thus expands to (1 + year|cluster). In this case you assume a different baseline for each cluster and allow the clusters to vary with respect to the year effect.
  2. mod2 includes an interaction, mod1 doesn't: As mod2 only includes a random intercept for the cluster*year interaction you get the estimates for every unique combination of the factor levels (i.e. AA:year2, AA:year3, ...)

Note that mod1 estimates $k$ variances and $k(k-1)/2$ correlations for the $k$ random effects per cluster. If you constrain the cluster-related variances to be equal and all the correlations also to be equal (this is called compound symmetry), you get a model with many fewer (only two) variance/covariance parameters:

mod3 <- lmer(y ~ x + year + (1|cluster) + (1|year:cluster))

(note the similarity/difference compared to mod2) which can be useful when there is not enough information in the data to estimate mod1. For more on this see this excellent post by Reinhold Kliegl and also my follow-up question: Equivalence of (0 + factor|group) and (1|group) + (1|group:factor) random effect specifications in case of compound symmetry.

So mod3 can be seen as a restricted version of mod1. Your mod2 is restricted even further, but this one-parameter parametrization is arguably less realistic.

$\endgroup$
5
  • $\begingroup$ Thanks @statmars, that makes it clearer. I'd confused the 'every unique combination' element with each intercept having 5 variations. I'd be warned not to refer to it as a slope, when using a factor, as it's not continuous. Would you agree? May I suggest a small edit to 2.? I think you mean 'mod2 includes an interaction, mod1 doesn't...' $\endgroup$
    – Mainard
    Commented Sep 13, 2017 at 20:30
  • 1
    $\begingroup$ You are right, it's 'mod1 doesn't'! Note my edit (mod3): maybe you just forgot the (1|cluster) term. Mod3 can be an option given the constraints I mentioned. $\endgroup$
    – statmerkur
    Commented Sep 24, 2017 at 10:02
  • $\begingroup$ +1. Related: stats.stackexchange.com/questions/304374 $\endgroup$
    – amoeba
    Commented Dec 28, 2017 at 14:02
  • 2
    $\begingroup$ (+1) You probably meant that the correlations should be constrained to be equal, not zero. I made this edit, make sure that you agree. I also inserted a link to your own Q about compound symmetry, it looks directly relevant. $\endgroup$
    – amoeba
    Commented Jan 17, 2018 at 12:26
  • $\begingroup$ @amoeba I meant that mod3 estimates 0 correlation parameters and yes, you are right, thus constrains the cluster-related correlations to be equal. Thanks for linking to my Q. $\endgroup$
    – statmerkur
    Commented Jan 17, 2018 at 16:45

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.