循环中的qq绘图而不是绘图

时间:2016-09-08 02:24:38

标签: r for-loop jpeg

我正在尝试创建一个循环,用于绘制多个混合模型的诊断图,以便我可以轻松查看是否满足模型的假设。我在5种物种的7个测量中运行模型,因此单独创建所有35个模型的图表真的很糟糕。

我的代码是:

sink("C:\\Users\\*My Name*\\Desktop\\Morph Data\\JAWE\\LMM2\\JAWEj LMM Output.txt")

Names<-names(int)

result.sum <- vector("list",16)
names(result.sum)<-Names

result.aov <- vector("list",16)
names(result.aov)<-Names

for(i in 9:15){
blah<-data.frame(X=int$Year,Y=int[,i],Z=int$Observer)
blah<-blah[complete.cases(blah),]
mod1<-lme(Y~X,random=~1|Z,method="ML",data=blah)
result.sum[[i]]<-summary(mod1)
result.aov[[i]]<-anova(mod1)


mypath=file.path("C:","Users","*My Name*","Desktop","Morph Data","JAWE","LMM2", paste(Names[i],"_qq",".jpg",sep=""))
jpeg(file=mypath)
p<-qqnorm(mod1,main=Names[i])
dev.off()

mypath=file.path("C:","Users","*My Name*","Desktop","Morph Data","JAWE","LMM2", paste(Names[i],"_res-hist",".jpg",sep=""))
jpeg(file=mypath)
hist(mod1$residuals[,1],freq=FALSE,main="Wing")
curve(dnorm(x,mean=mean(mod1$residuals[,1]),sd=sd(mod1$residuals[,1]),log=FALSE), col=2, lwd=4, lty=4, add=TRUE)
dev.off()

mypath=file.path("C:","Users","*My Name*","Desktop","Morph Data","JAWE","LMM2", paste(Names[i],"_res",".jpg",sep=""))
jpeg(file=mypath)
plot(blah$X,mod1$residuals[,1],main="Wing")
dev.off()
}

result.sum
result.aov

对象int是我对这个特殊物种的数据,JAWE。使用此代码,我可以成功保存模型和ANOVA的输出,以及每个模型的3个图中的2个。

我遇到的问题是保存的Q-Q图是空白图。关于如何解决这个问题的任何线索都将非常受欢迎。

谢谢!

0 个答案:

没有答案