I hope someone can help me.
I would like to perform several predictions with one model with distinct data.
I’ve created 100 data frames with 60 observations sorted from another data frame as below:
mtz100<-replicate(100,aracaboot[sample(nrow(aracaboot), size=60, replace=T),]
Ok, now I want to fit 100 new models with my model with the new 100 data frames created.
After this I want to predict to raster layers.
Someone can give a start point to automate this in R?
SOLUTION:
RasterImgs <- list()
lenght(RasterImgs) <- 100
for(i in 1:100) {
DataNew <- data[sample(1:nrow(data),60,replace=T),]
Model <- glm(DataNew, ....)
List <- Model
RasterImgs[i] <- predict(list,....)
}
Thanks by the Help @Señor O
I think you approach is a little bit off right now. Doing
sample(nrow(dataframe),60)won’t give you the desired effect becausenrowreturns ONE number (not a vector). So you want to dosample(1:nrow(dataframe),60.....instead.I don’t know of a better approach than using a simple
forloop if you’re sampling indices: