On Fri, 24 Mar 2006, Dieter Menne wrote: > Leonardo D Bacigalupe <L.Bacigalupe <at> sheffield.ac.uk> writes: > >> I'm trying to plot e.g. fitted vs residuals for each level of the >> random effects, and i'm getting the same error. >> I guess this might be a problem of the graphic capabilities of R. >> >> Is there any way to obtain those plots? >> >> library(nlme) >> attach(ergoStool) >> names(ergoStool) >> [1] "effort" "Type" "Subject" >> m1<-lme(effort~Type,random=~1|Subject) >> plot(m1,form=resid(.,type="p")~fitted(.)|Subject,abline=0)#resid and >> fitted for each level of subject >> Error in as.vector(x, "list") : cannot coerce to vector >> > > I don't believe your idea is wrong, and I don't understand why this does not > work, but a similar line on page 176 of Pinheiro/Bates does (there, the call > to > getData returns non-null). The lines I don't understand in plot.lme are > > alist <- lapply(as.list(allV), as.name) > names(alist) <- allV > # next line > alist <- c(as.list(as.name("data.frame")), alist) > mode(alist) <- "call" > data <- eval(alist, sys.parent(1)) > > This code turn up again and again in nlme, but I admit I don't understand what > it means. > > Anybody taking the challenge to dissect it?
It's a bug. The first two lines sets up a list, in this case, list(Subject=Subject). The idea is then to call data.frame(Subject=Subject) in the parent environment, but whenever you see things like data <- eval(alist, sys.parent(1)) you might want to suspect code copied from S-PLUS. And indeed, as.list(as.name("data.frame")) works in S-PLUS but not in R (although just list(as.name("data.frame")) works in both). I think the best fix is to make as.list work on symbols, but replacing as.list by list in plot.lme appears to fix this (that is, it works and the output appears plausible). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html