Dear,
I'm using a loop (for) to generate many linear models, and I'm have a problem with output of the parameters.
I need of the parameters (Interceptor, R squared and angular) within in a data.frame to each model, but I only did can done the output as a list.
Follow below my code:
library(readxl)
precipitacao <- read_excel("preenchimento_falhas.xlsx",
col_types = c("numeric", "numeric", "numeric",
"numeric", "numeric"))
parameters <- numeric()
for (i in 3:ncol(precipitacao)) {
reglin <- lm(as.matrix(precipitacao[,2]) ~ as.matrix(precipitacao[,i]),
data = precipitacao)
r_sqrd <- summary.lm(reglin)$r.squared
a_b <- coefficients(reglin)
parameters[i] <- data.frame(c(r_sqrd,a_b))
}
How I can do this? Put the output for each model (each reglin) as a data.frame? I know that is banal, but, I'm learning yet.
Obviously, I didn't have your data set, so had to use a existing one and I chose mtcars. Here, I stored the r^2, a and b of each model in a row. If you want, you can store in columns too.