[R] Producing residual plots by time for lme object
Deepayan Sarkar
deepayan.sarkar at gmail.com
Wed Jul 7 21:50:35 CEST 2010
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
More information about the R-help
mailing list