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? Regards, Rense Nieuwenhuis
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 at 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
Yesterday, I tried to do exactly this, too. Below is my approach. Unfortunately, I did not find a textbook example against which I could verify my code. Hints, simplifications, and verification highly appreciated!!! ### random slope! model v = lme(POPULAR ~ SEX + TEXP, data=dta, random = ~ SEX | SCHOOL) ### setting up the thing to plot a = matrix(t(cbind(0, coef(v)[,1], 1, coef(v)[,2])), ncol=2, byrow=1) plot(a) ### connecting only the pairs I want to have connected, ie dont connect all dots for (i in 1:(length(a)/4)*2-1) lines(a[i:(i+1),]) Thanks Toby data downloaded from http://www.ats.ucla.edu/stat/examples/ma_hox/default.htm 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? > > Regards, > > Rense Nieuwenhuis > > ______________________________________________ > R-help at 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. >