[R-sig-ME] lmer code for multiple random slopes
Viechtbauer, Wolfgang (SP)
wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Thu Mar 4 11:45:33 CET 2021
Hi Peter,
In:
response ~ x + (1|G2/G1) + (x|G2)?
the first () term adds random intercepts for each level of G2 and random intercepts for each level of G1 within G2. The second () term actually stands for (1+x|G2), so it again adds random intercepts for each level of G2, and random slopes for x for each level of G2 (and allows these random intercepts and slopes to be correlated). So, you are in essence adding random intercepts for G2 twice; probably not what you intended. Maybe you want:
response ~ x + (1|G2/G1) + (0+x|G2)?
but this implies that the random intercepts and slopes at the G2 level are uncorrelated. Or you could use:
response ~ x + (1|G1:G2) + (x|G2)?
which gives you correlated random intercepts and slopes for G2 and also adds random intercepts for the various G1-G2 level combinations (i.e., random intercepts for each level of G1 within G2).
Best,
Wolfgang
>-----Original Message-----
>From: Peter R Law [mailto:prldb using protonmail.com]
>Sent: Thursday, 04 March, 2021 0:08
>To: Viechtbauer, Wolfgang (SP); r-sig-mixed-models using r-project.org
>Subject: RE: [R-sig-ME] lmer code for multiple random slopes
>
>Many thanks Wolfgang! That does clear up my confusion. That interpretation of
>'random effects' didn't occur to me.
>
>Thanks also for pointing out that the differences in the estimates provided by lme
>and lmer occur because they handle singular models differently and won't occur for
>non-singular examples.
>
>When I have collected enough data, the model I am actually interested in will have
>two nested random factors, G1 within G2, and I only want random slopes (say for a
>covariate x) with respect to G2, but random intercepts for both factors. Am I
>right in thinking the code will take the form
>
>response ~ x + (1|G2/G1) + (x|G2)?
>
>Much appreciated,
>
>Peter
>
>Peter R Law
>Research Associate
>Center for African Conservation Ecology
>Nelson Mandela University
>South Africa
>
>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>On Wednesday, March 3, 2021 7:43 AM, Viechtbauer, Wolfgang (SP)
><wolfgang.viechtbauer using maastrichtuniversity.nl> wrote:
>
>> Dear Peter, Dear All,
>>
>> The error doesn't say 78 variance components, it says 78 random effects. There
>are 26 groups in this dataset and you are estimating random intercepts and two
>sets of random slopes. Hence, there are 3*26 = 78 random effects that are in this
>model. But the dataset has only 74 rows. This is a check built into lmer() to
>avoid fitting overly complex models for a given dataset. You can disable this
>check with (also, use REML=FALSE, not "False"):
>>
>> M2 <- lmer(Response ~ P + A + (P + A | Group), REML=FALSE, data=Trial,
>control=lmerControl(check.nobs.vs.nRE="ignore"))
>>
>> Then it will run and this is the same model as fitted with:
>>
>> M2n <- lme( Response ~ P + A, random = ~ P + A | Group, data=Trial, method="ML")
>>
>> The results differ somewhat though, because both packages handle such ill-
>defined problems in different ways.
>>
>> Best,
>> Wolfgang
More information about the R-sig-mixed-models
mailing list