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

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

问题描述

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

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,FAQ 7.22 事实上.然而,这并不明显,直到您意识到 nlme 包中的 plot.lme 函数使用格子/格状图形来进行实际绘图(在帮助页面上有 plot.lme,但不明显).

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).

解决方案的简短形式(但我仍然建议阅读常见问题解答和其他文档以完全理解问题)是将 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天全站免登陆