2
$\begingroup$

Are splines of random effects allowed in nlme but not in lme4? How to incorporate splines of random effects in lme4?

>library(nlme)
>library(lme4)
>library(splines)
>ctrl <- lmeControl(opt='optim')
>summary(m1 <- lme(conc ~ ns(time, 3), random = ~ ns(time, 3) |Subject, na.action=na.omit, control = ctrl, data = Quinidine))
>summary(m2 <- lmer(conc ~ ns(time, 3) + (ns(time, 3) | Subject), data = Quinidine))
>Error: number of observations (=361) <= number of random effects (=544) for term (ns(time, 3) | Subject); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable

Additionally, should the terms in random effects always be identical with the terms in fixed effects? Is it OK to have ns(time, 3)" in the fixed effects, but time in the random effects?

$\endgroup$
1
$\begingroup$

The error message suggests that you have included too many random effects compared to the number of subjects you have. This often leads to unstable models, and therefore it is advisable to use a simpler structure for your random-effects part.

Regarding your second question, yes, in principle, you can have a different structure for the time effect in the fixed- and random-effects parts. What you do in the random effects actually translates into correlations among the repeated measurements of your outcome over time.

$\endgroup$
  • $\begingroup$ But the nlme model (m1) gives an output and does not show any error message. Does this mean that lme4 is better than nlme? $\endgroup$ – KuJ Oct 2 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.