Re: [R] plotting multilevel / lme lines

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Fri 06 Apr 2007 - 12:24:26 GMT

Rense Nieuwenhuis wrote:
> Dear expeRts,
>
> I am trying to plot a lme-object {package nlme) in such a way, that
> on a selected level the x-axis represents the value on a selected
> predictor and the y-axis represents the predicted-outcome variable.
> The graphs would than consist of several lines that each represent
> one group. I can't find such a plotting function.
>
> I could write such a function myself, based on ranef() and fixef(),
> but it would be a waste of time if such a function would already exist.
>
> Does any of you such a function?

  I don't know of a single function with an lme object as argument, but for what I think you have in mind, here is how you might go about it:

library(nlme)

fm2 <- lme(distance ~ poly(age, 2) * Sex,

                      data = Orthodont, random = ~ 1)

newdat <- expand.grid(age = 8:14, Sex = c("Male","Female"))

newdat$PREDDIST <- predict(fm2, newdat, level = 0)

library(lattice)

xyplot(PREDDIST ~ age, groups=Sex, ylab="Model Predicted Distance",

           data = newdat, xlab="Age",
           panel = function(x, y, ...){
                   panel.grid(h=6,v=6)
                   panel.superpose(x, y, type="l", ...)},
                   main="Orthodont Growth Model",
                   key = simpleKey(levels(newdat$Sex),
                                   lines=TRUE, points=FALSE)
                   )

> Regards,
>
> Rense Nieuwenhuis
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Fri Apr 06 22:31:04 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 07 Apr 2007 - 12:30:57 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.