I've been attempting to project the habitat suitability for Cassava across Africa using presence data from GBIF (about 5000 records) in Biomod2 in R. I am using a set of 26 environmental variables, including CHELSA bioclimatic variables, topographic variables, and some soil condition variables. When I run my projections at the lowest number of PA replication runs, model evaluation runs, and down to one single model (MAXNET), I still seem to reach the "std::bad_alloc" error. Any help is much appreciated; give thanks! Following is my code:

` sp_occ <- subset(crops,species == unique(crops$species)[[sp]])

  myRespName <- unique(crops$species)[[sp]]
  myResp <- rep(1,nrow(sp_occ))

  myRespXY <- sp_occ[,c("longitude","latitude")]

  myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
                                   expl.var = raster.c1,
                                   resp.xy = myRespXY,
                                   resp.name = myRespName,
                                   PA.nb.rep = 1,
                                   PA.nb.absences = 1000,PA.strategy ="random",
                                   filter.raster = TRUE)

  if (nrow(sp_occ) < 30) {
   DataSplitTable <- bm_CrossValidation(myBiomodData, k=nrow(sp_occ), nb.rep=1, do.full.models=FALSE)
  }

   myBiomodOption <- BIOMOD_ModelingOptions()

  setwd("F:/Results")

  if(nrow(sp_occ)<30){
    myBiomodModelOut <- BIOMOD_Modeling( 
      myBiomodData, 
      modeling.id = paste(myRespName,"FirstModeling",sep=""),
     CV.strategy = "user.defined",
      models = c("MAXNET"),
      bm.options = myBiomodOption, 
     CV.user.table=DataSplitTable,
     prevalence=0.5, 
    var.import=3,
    metric.eval = c("TSS"),
     scale.models= TRUE,
     do.full.models = FALSE)
  } else {
    myBiomodModelOut <- BIOMOD_Modeling( 
    myBiomodData, 
    modeling.id = paste(myRespName,"FirstModeling",sep=""),
    models = c("MAXNET"),#,"GLM","GBM"),
    bm.options = myBiomodOption, 
    nb.rep=1, #10, #1
    data.split.perc=70, 
    prevalence=0.5, 
    var.import=3,
    metric.eval = c("TSS"),
    scale.models= TRUE,
    do.full.models = FALSE,
    seed.val=10)
  }


  myBiomodModelEval <- get_evaluations(myBiomodModelOut)

  myBiomodEM <- BIOMOD_EnsembleModeling(
    bm.mod = myBiomodModelOut,
    models.chosen = 'all',
    em.by = 'PA+run',
    em.algo=c("EMmean"),
    metric.select = 'all',
    metric.select.thresh = 0.5,#0.7
    metric.eval = c('TSS'),
    var.import = 0)


  myBiomodProj <- BIOMOD_Projection(
    bm.mod = myBiomodModelOut,
    new.env = raster.c1,
    proj.name = 'current',
    models.chosen = 'all',
    metric.binary = 'TSS')

   myBiomodEF_Current <- BIOMOD_EnsembleForecasting(
    bm.proj = myBiomodProj,
    bm.em = myBiomodEM,
    metric.binary = 'TSS',
    total.consensus=T)``

I have also tried reducing the spatial resolution by 10x, yet still received the same error, so I am wondering if this is even a memory issue...

0

There are 0 best solutions below