[R] lme plot
p.dalgaard at biostat.ku.dk
Wed Mar 29 11:44:24 CEST 2006
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
> 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)
> >>  "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.
Drats, I never even realised that the problem was that it didn't
> 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,
> works in S-PLUS but not in R (although just list(as.name("data.frame"))
> works in both).
Actually, even this works in R:
x <- c("bar","baz")
l <- lapply(x,as.name)
names(l) <- x
and in Splus 6.2.1 too, substituting Quote() for quote(). (And Quote()
does actually exist in R too as a compatibility alias for quote())
> I think the best fix is to make as.list work on symbols,
Maybe. It does look to me like bad coding, though: if ever the
argument happens not to be a symbol - an unnamed function, say - there
will be differences between what as.list() and list() does and the
latter is more likely to be as intended. It obviously cannot happen
here, but there are applications where you "rip the head off" a
function call and reuse it to build a new one.
> but replacing
> as.list by list in plot.lme appears to fix this (that is, it works and the
> output appears plausible).
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help