[R-sig-ME] Problems with lme random slope+intercept model

Ben Bolker bbolker at gmail.com
Mon Oct 28 21:40:38 CET 2013


Andreas Nord <andreas.nord at ...> writes:


> Dear all,

> I'm trying to fit a model on ecological data in which I have
> measured a few biotic and abiotic factors over the course of a few
> days in several individuals. Specifically, I'm interested in
> modelling y ~ x1, with x2, x3, and 'factor' as independent
> variables. Because data suggests both slope and intercept (for y
> ~x1) might differ between individuals, I'd want to compare model fit
> for a saturated model with random intercept only, against that of a
> model with random slope + intercept. Data are available in full from
> this link: https://www.dropbox.com/s/mzk8utvgkzp4rtr/data.txt
 
> The random intercept model seems to function appropriately:
> data<-subset(data,data$id!='id225' & data$id!='id237' & data$id!='id233')
> m1.lme<-with(data,lme(y~x1+x2+x3+factor,random=~1|id,na.action=na.omit))
 
> However, fitting the random slope+intercept model produces an error message
>  I can't quite make sense of.
> m2.lme<-with(data,lme(y~x1+x2+x3+factor,random=~1+y|id,na.action=na.omit))
> #Error in chol.default((value + t(value))/2) :
> #  the leading minor of order 2 is not positive definite

  It doesn't really make any sense to use the *response* variable y
as the random-effects response.  It's the effect of the *predictor*
variable that will vary across individuals, so you should try writing it as

m2.lme<- lme(y~x1+x2+x3+factor,random=~1+x1|id,
             data=data,na.action=na.omit)

It's also better/more coherent to include 'data' as an argument
rather than to use with() in this case.

You can also use random=~x1|id since the intercept is included
implicitly (opinions differ about whether it is better to be compact
or explicit).

  Ben Bolker



More information about the R-sig-mixed-models mailing list