如何在一个循环中绘制多个残差图? [英] How can I plot multiple residuals plots in a loop?

查看:178
本文介绍了如何在一个循环中绘制多个残差图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,我想将每个模型的残差图写入文件中.我不需要在显示器上看到它们.

In the following example, I want to write the residuals plot of each model in a file. I do not need to see them in my display.

for (i in 1:500){
     temp.model<-lme(as.formula(paste("Var",i) ~ X1*X2, sep=""), data = example, random=~1| Exp/Person)
     jpeg(paste("C:/Myfolder", i, ".jpg", sep = ""), quality=50, bg="white")
     plot(temp.model)
     dev.off ()
     graphics.off()
}

当我不循环地运行此代码时,我将获得所需的内容.但是,它会在循环中创建空白文件.

When I run this code without loop, I obtain what I want. However, it creates blank files within the loop.

有什么想法吗?

谢谢.

推荐答案

答案在FAQ中,

The answer is in the FAQ, FAQ 7.22 in fact. However this is not obvious until you realize that the plot.lme function from the nlme package uses lattice/trellis graphics to do the actual plotting (there are references on the help page for plot.lme, but not obvious).

该解决方案的简短形式(但我仍然建议阅读FAQ和其他文档以完全理解该问题)是将plot包装在print命令中.

The short form of the solution (but I still recommend reading the FAQ and the other documentation to fully understand the issue) is to wrap the plot in a print command.

这篇关于如何在一个循环中绘制多个残差图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆