[R-sig-ME] lmer code for multiple random slopes
Peter R Law
pr|db @end|ng |rom protonm@||@com
Tue Apr 13 04:45:24 CEST 2021
I used some simulated data to explore the two different models you described in your response to my query:
lmer(y ~ x + (1|G1:G2) + (x|G1))
lmer(y ~ x + (1|G1/G2) + (x|G1))
For my simulated data, the latter model divides the random intercept of G1 into two unequal parts but otherwise the models are almost identical, even with the same deviance.
Apart from replacing the single random intercept due to G1 in the top model by two random intercepts due to G1 in the bottom model, the models seem to be otherwise the same.
If so, is there any situation in which one would consider the top model?
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, March 4, 2021 9:13 PM, Peter R Law via R-sig-mixed-models <r-sig-mixed-models using r-project.org> wrote:
> Many thanks Wolfgang.
> Sent with ProtonMail Secure Email.
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, March 4, 2021 5:45 AM, Viechtbauer, Wolfgang (SP) wolfgang.viechtbauer using maastrichtuniversity.nl wrote:
> > 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
> R-sig-mixed-models using r-project.org mailing list
</r-sig-mixed-models using r-project.org>
More information about the R-sig-mixed-models