[R] xyplot: key inside the plot region / lme: confidence bands for predicted

Michael Friendly friendly at yorku.ca
Fri Jul 2 17:37:08 CEST 2010


I have two questions related to plotting predicted values for a linear 
mixed model using xyplot:

1:  With a groups= argument, I can't seem to get the key to appear 
inside the xyplot. (I have the Lattice book,
but don't find an example that actually does this.)
2: With lme(), how can I generate confidence bands or prediction 
intervals around the fitted values?  Once
I get them, I'd like to add them to the plot. 

Example:

library(nlme)
library(lattice)
Ortho <- Orthodont
Ortho$year <- Ortho$year - 8  # make intercept = initial status

Ortho.mix1 <- lme(distance ~ year * Sex, data=Ortho,
        random = ~ 1 + year | Subject, method="ML",
#        correlation = corAR1 (form = ~ 1 | Subject)
        )
Ortho.mix1

# predicted values
grid <- expand.grid(year=0:6, Sex=c("Male", "Female"))
grid$age <- grid$year+8  # plot vs. age
fm.mix1 <-cbind(grid, distance = predict(Ortho.mix1, newdata = grid, 
level=0))

xyplot(distance ~ age, data=fm.mix1, groups=Sex, type="b", pch=c(15,16), 
cex=1.2,
    auto.key=list(text=c("Male", "Female"), points = TRUE, x=8, y=26),
    main="Linear mixed model: predicted growth")

Can someone help?

-Michael

-- 
Michael Friendly     Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list