I have a series of statistical models in a list and I would like to plot the coefficients of these. I have various responses and explanatory variables within this list of models, as well as various statistical functions (e.g. exponential and linear).
DF<- as.data.frame(matrix(sample(1:50, 1*2000, replace=TRUE), ncol=4))
colnames(DF) <- c("Response_1","Response_2","Explanatory_1","Explanatory_2")
DF$Factor <- rep(c("Control","Impact"), each = 250)
List_models <- list(lm(Response_1~exp(Explanatory_1):Factor, data=DF),
lm(Response_1~Explanatory_2:Factor, data=DF),
lm(Response_2~Explanatory_1:Factor, data=DF),
lm(Response_2~exp(Explanatory_2):Factor, data=DF))
I am guessing some kind of lapply function would work here, but I do not know how to do this while changing the function associated with x or change the Response and Explanatory variable being plotted. The code below produces the ideal outcome, but I would like to create this with some kind of loop function.
par(mfrow=c(2,2))
plot(Response_1~Explanatory_1,data=DF,type="n")
curve(List_models[[1]]$coefficients[1]+List_models[[1]]$coefficients[2]*exp(x), add = TRUE)
plot(Response_1~Explanatory_2,data=DF,type="n")
curve(List_models[[2]]$coefficients[1]+List_models[[2]]$coefficients[2]*x, add = TRUE)
plot(Response_2~Explanatory_1,data=DF,type="n")
curve(List_models[[3]]$coefficients[1]+List_models[[3]]$coefficients[2]*x, add = TRUE)
plot(Response_2~Explanatory_2,data=DF,type="n")
curve(List_models[[4]]$coefficients[1]+List_models[[4]]$coefficients[2]*exp(x), add = TRUE)
Thank you in advance for any help with this.