I am summing data over different time intervals via a loop, and at the end, I'm running it through a linear model. Currently, I'm hardcoding in all the coefficients I want and appending them to a data frame, and once the loop is over, it's exporting a CSV.
The issue is, I have a lot of variables, and would like to export all of them for each iteration.
Is there a way to do this? Ideally, I'd like to pull the coefficients for each independent variable, the P-value of each independent, P-value of the model, and adjusted R2 of the model, and export
Any ideas? This is what the loop looks like:
outputs <- matrix(,ncol=4)
for(size in seq(20,30, by= 10))
{
for(i in 2:nrow(df_first))
{ upperWindow <- as.numeric(df_first$time) <=
(as.numeric(perf$time[i])+g*60)
lowerWindow <- df_first$time >= perf$time[i]
total[i] <- sum(perf$total [upperWindow & lowerWindow])
}
fit <- lm(total ~ x + y)
model_coef <- coefficients$fit
outputs <- rbind(model_coef, size, fit$adj.r.squared)
}
write.table (outputs, file =~ )
Basically, I would like to pull all the coefficients, Rsquareds, and size out of the models I'm running, and export them to a CSV. I keep getting the error message "attributes are not identical across measure variables; they will be dropped"