I am having a hard time trying to create residual plots for multiple models in a loop. I used a loop to create the models:
nameIndex=1
name=character(length=nrow(resp))
for(i in resp$resp){
y=response.data[,i]
df=data.frame(y, modelpredictors) #this creates a temporary data frame for you
nam=paste("MODEL", nameIndex, sep=".") #Create unique model names to use later
model=lm(y~.,data=df)
assign(nam, model)
name[nameIndex]=nam #saving model names in a vector to use later
nameIndex=nameIndex+1
}
Now, I want to do a loop to make residual plots.
par(mfrow=c(2,3))
for(i in nrow(resp)){
plot(fitted(cat("MODEL.",i)),residuals (cat("MODEL.",i)))
}
However, I am getting the error
Error in plot.window(...) : need finite 'xlim' values
I want to know how to call the models that I created in the first loop in a orderly fashion to use in plotting loops and other analysis that I want to do to all of the models.