Domanda

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

È stato utile?

Soluzione

I think you approach is a little bit off right now. Doing sample(nrow(dataframe),60) won't give you the desired effect because nrow returns ONE number (not a vector). So you want to do sample(1:nrow(dataframe),60..... instead.

I don't know of a better approach than using a simple for loop if you're sampling indices:

List <- list()
lenght(List) <- 100              ## Growing a list inside a loop is inefficient

for(i in 1:100) {
    DataNew <- Data[sample(1:nrow(Data),60,replace=T),]
    Model <- glm(DataNew....)
    List[i] <- Model
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top