[R] Plotting individual trajectories from individual growth model

Douglas Bates bates at stat.wisc.edu
Tue Feb 22 16:43:15 CET 2011


On Mon, Feb 21, 2011 at 10:06 PM, dadrivr <dadrivr at gmail.com> wrote:
>
> Thanks Dennis,
>
> The code works for perfectly for the data in the example.  For some reason,
> however, I get the following error message when I use a different data set:
>
>> preds <- expand.grid(age = c(30,36,42), Subject = unique(mydata$id))
>> predict(lmemodel, preds, na.action=na.omit)
>
> Error in predict.lme(lmemodel, preds, na.action = na.omit) :
>  Cannot evaluate groups for desired levels on "newdata"
>
> I searched for the error online, and it appears that it results from missing
> subject IDs (see:
> http://www.mail-archive.com/r-help@r-project.org/msg100649.html).  I checked
> both the newdata file ('preds') and the predicted values of lmemodel
> ('predict(lmemodel)'), however, and the subject IDs appear to be in both
> files.  I'm not sure if it's an issue, but the length of the predicted
> values is shorter (with fewer IDs) than the newdata file (preds) because
> there is missing data.  Any help would be greatly appreciated on this.

Check str(preds) to make sure that Subject is a factor in the output
of expand.grid.  It is possible that expand.grid converts to another
storage mode.

> If it is diagnostic, I attached a .txt file to this message with the
> contents of preds and predict(lmemodel):
> http://r.789695.n4.nabble.com/file/n3318524/lmemodel.txt lmemodel.txt
> --
> View this message in context: http://r.789695.n4.nabble.com/Plotting-individual-trajectories-from-individual-growth-model-tp3315494p3318524.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list