Message-ID: <CAGoSky9ht6itJQNNRzT2-Z9s3EU58p1-FgCYzxEQ_e_jxJmogA@mail.gmail.com>
Date: 2017-11-28T16:48:04Z
From: Paul Buerkner
Subject: Diagonal covariance matrix of random effects when using natural splines in lme4
In-Reply-To: <HE1PR10MB167641FAEFE9E1149FE7FE26C73A0@HE1PR10MB1676.EURPRD10.PROD.OUTLOOK.COM>
lme4 does not split the random effects after columns, but after terms and
ns(Days, df = 3) forms a single term.
A workaround would be to compute the basis of the spline manually, add it
to the data frame as separate columns, and then write them explicitely into
the model formula.
2017-11-28 17:39 GMT+01:00 xavier piulachs <xavierpiulachs at hotmail.com>:
> Hi everyone,
>
> I'm trying to fit a longitudinal model with natural cubic splines with 2
> inner knots,
> where I want to assume a diagonal covariance matrix for the random effects
> (i.e.
> uncorrelated random effects). Let's say, I'm using the well-known data
> "sleepstudy"
> from the "lme4" package.
>
> First, I run the model trough "nlme" package:
>
> model.nlme <- lme(Reaction ~ ns(Days, df = 3),
> random = list(Subject = pdDiag(form = ~ ns(Days, df =
> 3))),
> data = sleepstudy)
>
> An the output indicates that there is no correlation between random
> effects:
>
> Random effects:
> Formula: ~ns(Days, df = 3) | Subject
> Structure: Diagonal
> (Intercept) ns(Days, df = 3)1 ns(Days, df = 3)2 ns(Days, df = 3)3
> Residual
> StdDev: 25.78 57.12 63.62 46.61
> 20.97
>
> However, I do not know how to run the same model under lme4 package. I
> tried:
>
> model.lme4 <- lmer(Reaction ~ ns(Days, df = 3) + (ns(Days, df = 3) ||
> Subject),
> data = sleepstudy)
>
> But, as shown by the output, I only have independence regarding the random
> intercept effect (which, by default, is not included in the B-spline
> basis):
>
> Random effects:
> Groups Name Variance Std.Dev. Corr
> Subject (Intercept) 605.9 24.62
> Subject.1 ns(Days, df = 3)1 3210.5 56.67
> ns(Days, df = 3)2 4183.9 64.68 0.57
> ns(Days, df = 3)3 2296.3 47.93 0.44 0.72
>
> Any guidance on this issue would be much appreciated.
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
[[alternative HTML version deleted]]