[R] Producing residual plots by time for lme object
Anne York
york at zipcon.net
Fri Jul 9 01:21:47 CEST 2010
The plot also works if you replace "na.exclude" with
"na.omit".
On Wed, 7 Jul 2010, Deepayan Sarkar wrote:
DS > On Fri, Jul 2, 2010 at 11:40 AM, Gregory Gentlemen
DS > <gregory_gentlemen at yahoo.ca> wrote:
DS > > Fellow R-users,
DS > >
DS > > I have a longitudinal data set with missing values in it. I would like to produce a residual plot for each time using panel.xyplot function but I get an error message. Here's a simple example,
DS > >
DS > > library(nlme)
DS > > set.seed(1544)
DS > > longdata <- data.frame(ID=gl(10,1,50), y=rnorm(50), time = as.numeric(gl(5,10,50)), x = rnorm(50))
DS > > longdata$y[5] <- NA
DS > > longdata$x[35] <- NA
DS > >
DS > > modlme<- lme(fixed=y ~ time + x,
DS > > random= ~ 1 | ID,
DS > > na.action=na.exclude, data=longdata)
DS > >
DS > >
DS > > plot( modlme, abs( resid(., type = 'p')) ~ fitted(.) | time,
DS > > panel = function(x, y, ...) {
DS > > panel.xyplot( x, y, ...)
DS > > panel.loess( x, y,...)
DS > > })
DS > >
DS > > where the last call produces the error message
DS > > Error in `[[<-.data.frame`(`*tmp*`, j, value = c(1, 1, 1, 1, 1, 1, 1, :
DS > > replacement has 48 rows, data has 50
DS > >
DS > >
DS > > How do I fix this?
DS >
DS > NA-handling is not working right, it seems. Would it make any real
DS > difference to your analysis to do
DS >
DS > modlme<- lme(fixed=y ~ time + x,
DS > random= ~ 1 | ID, data = na.omit(longdata))
DS >
DS > (in which case the subsequent plot call works)?
DS >
DS > -Deepayan
DS >
DS > ______________________________________________
DS > R-help at r-project.org mailing list
DS > https://stat.ethz.ch/mailman/listinfo/r-help
DS > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
DS > and provide commented, minimal, self-contained, reproducible code.
DS >
More information about the R-help
mailing list