Gregory Gentlemen
2010-Jul-02 18:40 UTC
[R] Producing residual plots by time for lme object
Fellow R-users,
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,
library(nlme)
set.seed(1544)
longdata <- data.frame(ID=gl(10,1,50), y=rnorm(50), time =
as.numeric(gl(5,10,50)), x = rnorm(50))
longdata$y[5] <- NA
longdata$x[35] <- NA
modlme<- lme(fixed=y ~ time + x,
random= ~ 1 | ID,
na.action=na.exclude, data=longdata)
plot( modlme, abs( resid(., type = 'p')) ~ fitted(.) | time,
panel = function(x, y, ...) {
panel.xyplot( x, y, ...)
panel.loess( x, y,...)
})
where the last call produces the error message
Error in `[[<-.data.frame`(`*tmp*`, j, value = c(1, 1, 1, 1, 1, 1, 1, :
replacement has 48 rows, data has 50
How do I fix this?
Any help would be greatly appreciated.
Greg
ps my sessioninfo is > sessionInfo()
R version 2.9.1 (2009-06-26)
i386-pc-mingw32
locale:
LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] nlme_3.1-96
loaded via a namespace (and not attached):
[1] grid_2.9.1 lattice_0.17-25>
[[alternative HTML version deleted]]
On Fri, Jul 2, 2010 at 11:40 AM, Gregory Gentlemen <gregory_gentlemen at yahoo.ca> wrote:> Fellow R-users, > > 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, > > library(nlme) > set.seed(1544) > longdata <- data.frame(ID=gl(10,1,50), y=rnorm(50), time = as.numeric(gl(5,10,50)), x = rnorm(50)) > longdata$y[5] <- NA > longdata$x[35] <- NA > > modlme<- lme(fixed=y ~ time + x, > ??????????????? random= ~ 1 | ID, > ??????????????? na.action=na.exclude, data=longdata) > > > plot( modlme, abs( resid(., type = 'p')) ~ fitted(.) | time, > ????????? panel = function(x, y, ...) { > ??????????????? panel.xyplot( x, y, ...) > ??????????????? panel.loess( x, y,...) > ????????? }) > > where the last call produces the error message > Error in `[[<-.data.frame`(`*tmp*`, j, value = c(1, 1, 1, 1, 1, 1, 1,? : > ? replacement has 48 rows, data has 50 > > > How do I fix this?NA-handling is not working right, it seems. Would it make any real difference to your analysis to do modlme<- lme(fixed=y ~ time + x, random= ~ 1 | ID, data = na.omit(longdata)) (in which case the subsequent plot call works)? -Deepayan