Reputation: 1
I simulated some data and I want to loop the simulation 1000 times. I need to fit the data to a linear model each time and save all the information.
One of my friend told me I can extract the coefficients of standard errors each time and save them to make them a matrix or data frame. However, I want to know if I can save a model. I want to simulate 1000 times and save all the models.
but how do i analyze overall model from the 1000 times? like if the model fit well, i want to use summary(model) and see if each variable significant and if the f statistic is significant or not?
Upvotes: 0
Views: 2758
Reputation: 44330
You can store all your models as a list and then write them to a file with the save
function:
lst <- lapply(1:1000, function(repetition) {
mod <- lm(...) # Replace this with the code you need to train your model
return(mod)
})
save(lst, file="myfile.RData")
Later, you could load the data again with load("myfile.Rdata")
, and then access them with lst[[1]]
, lst[[2]]
, ...
Upvotes: 2