[R] nlme graphics in a loop problem
Liaw, Andy
andy_liaw at merck.com
Thu Jun 17 21:27:09 CEST 2004
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
>
>
More information about the R-help
mailing list