kath_oreilly
2009-Oct-15 09:27 UTC
[R] plotting/examining residuals of a mixed generalised linear model
Dear R users, I'm hoping that more experienced users will be able to assist me in examining the model fit of a mixed generalised linear model. The example using the data 'bacteria' within the MASS package will hopefully illustrate what I would like to acheive; library(MASS) library(nlme) attach(bacteria) # y being output and the trt - treatment group being an explanatory variable. There is pseudoreplication as each patient (ID) is sampled multiple times (week) bacteria$y<-1*(bacteria$y=="y") # to make readable in lmer table(bacteria$y,bacteria$trt) hs <- groupedData(y~trt|ID,outer=~trt,data=bacteria) # I don't think this is really necessary model <- lmer(y ~ trt + (week|ID),family=binomial,data=hs) summary(model) Here I would like to examine the fit of the variable trt by examining the residuals. In lm (using lme in "the R book, p. 657"), one would be able to use plot(model,trt~resid(.)) However it doesn't work. If some one would explain why, that would be great. I've come across the package "zelig", which uses simulation to examine model fit. I haven't gotten my head round this yet, and was hoping some one would advise the approp path to take. Many thanks! -- View this message in context: http://www.nabble.com/plotting-examining-residuals-of-a-mixed-generalised-linear-model-tp25905522p25905522.html Sent from the R help mailing list archive at Nabble.com.
Ben Bolker
2009-Oct-15 13:25 UTC
[R] plotting/examining residuals of a mixed generalised linear model
kath_oreilly wrote:> > Dear R users, > > I'm hoping that more experienced users will be able to assist me in > examining the model fit of a mixed generalised linear model. The example > using the data 'bacteria' within the MASS package will hopefully > illustrate what I would like to acheive; > >I think you're a little confused. Thanks for the reproducible example, though. First of all, you're confusing nlme ("old mixed models", described most thoroughly in Pinheiro and Bates 2000, good for correlation and heteroscedasticity models but not capable of doing GLMMs) with lme4 ("new mixed models", not yet thoroughly documented but D. Bates is working on a book ...) Mixing them is usually a bad idea. The plotting capabilities aren't as highly developed for lme4 as for nlme, but you can still get what you want done. The r-sig-mixed-models list may be better for this kind of question. Here's my solution to your problem: library(MASS) data(bacteria) with(bacteria,table(y,trt)) library(lme4) bacteria$pres <- as.numeric(bacteria$y=="y") ## derive 0/1 variable model <- lmer(pres ~ trt + (week|ID),family=binomial,data=bacteria) summary(model) with(bacteria,boxplot(residuals(model)~trt)) ## or boxplot(residuals(model)~bacteria$trt) -- View this message in context: http://www.nabble.com/plotting-examining-residuals-of-a-mixed-generalised-linear-model-tp25905522p25908589.html Sent from the R help mailing list archive at Nabble.com.
kath_oreilly
2009-Oct-15 16:14 UTC
[R] plotting/examining residuals of a mixed generalised linear model
Thanks Ben, that was what I was looking for. I look forward to the lmer book (Pinheiro and Bates 2000 is very good and has already been helpful) -- View this message in context: http://www.nabble.com/plotting-examining-residuals-of-a-mixed-generalised-linear-model-tp25905522p25911559.html Sent from the R help mailing list archive at Nabble.com.