[R] nlme graphics in a loop problem
Liaw, Andy
andy_liaw at merck.com
Thu Jun 17 21:41:53 CEST 2004
Use array for your tables and list for plots; e.g.,
allTable <- array(NA, dim=c(numRow, numCol, numIter))
allPlot <- vector(mode="list", length=numIter)
for (i in 1:numIter) {
...
allPlot[[i]] <- plot(...)
allTable[,,i] <- however you generate the table
}
HTH,
Andy
> From: Jennifer Emond
>
> yes, use the print command, and if you can save each plot in
> the loop,
> that will work.
> I had to do this for a loop and tables I was making. I had
> to save the
> first table to a matrix, then bind each successive table to that
> matrix, then print the final matrix. Not sure how to do this for a
> plot, though...
>
>
> On Jun 17, 2004, at 12:27 PM, Liaw, Andy wrote:
>
> > Could it be that you need print(plot(model)) inside the loop? I
> > believe
> > plot() methods in nlme are mostly lattice graphics, which
> needs to be
> > explicitly print()ed inside functions and loops.
> >
> > Andy
> >
> >> From: Chris Knight
> >>
> >> Hi, I'm fitting mixed effects models using the lme function
> >> of the nlme
> >> package. This involves using the various associated plot functions.
> >> However, when I attempt to fit a number of models using an
> >> loop, whilst
> >> the models work, the plot functions fail. As a trivial example, the
> >> following works:
> >>
> >> library(nlme)
> >>
> >> graphics.off()
> >> x<-c(1:10)
> >> y<-c(1:4,7:12)
> >> b<-as.factor(c(rep("A",5),rep("B",5)))
> >> model<-lme(y~x, random=~1|b)
> >> plot(model)
> >>
> >> however the following, identical code in a loop, doesn't:
> >>
> >> graphics.off()
> >> for(i in 1:2){
> >> x<-c(1:10)
> >> y<-c(1:4,7:12)
> >> b<-as.factor(c(rep("A",5),rep("B",5)))
> >> model<-lme(y~x, random=~1|b)
> >> plot(model)
> >> }
> >>
> >> Mostly this is only inconvenient, since a similar plot may
> be created
> >> successfully within the loop using
> plot(fitted(model),resid(model)),
> >> however, I'd be keen to find out whether this is a general
> >> problem/sign
> >> of something deeper or I'm just missing something easy
> that could sort
> >> it out.
> >>
> >> Thanks,
> >> Chris
> >> --
> >>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> Dr. Christopher Knight Tel:+44
> >> 1865 275111
> >> Dept. Plant Sciences +44
> >> 1865 275790
> >> South Parks Road
> >> Oxford OX1 3RB Fax:+44
> >> 1865 275074
> >> ` · . , ,><(((º>
> >>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >> ______________________________________________
> >> R-help at stat.math.ethz.ch mailing list
> >> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide!
> >> http://www.R-project.org/posting-guide.html
> >>
> >>
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
> Jennifer A. Emond, MS
> Statistician
> Department of Biostatistics, UCSD
> 9500 Gilman Drive
> M/C 0949
> La Jolla, CA 92093-0949
> (858) 622-5877
> jemond at ucsd.edu
>
>
>
More information about the R-help
mailing list