I am having some concern regarding the implementation of biomod2 in R. I am testing the script in which I select only a set of algorithms to execute and test, such as RF, ANN, and SRE. However, the biomod2 still tries to run all algorithms. The MARS algorithm just ran all night last time just for the first evaluation (RUN_1) but I decided to terminate the execution. I don't know why such algorithm requires so much time with my test data. That is why I decided to test only for some models, and not all. My test data only covers a portion of Philippines and very limited number of points (~300) using a 1km resolution climate data. In the log messages, you can see that the model still executed GLM and GBR although I did not selected those models.

Here is the portion of the script I am testing:



# import shapefile
DataSpecies_ <- readOGR(dsn = ".", layer = "PHL_Coffee")

# coordinates
e.Mind <- extent(121.529318,126.763690,5.306908,9.807500)
crop_shape <- crop(DataSpecies_,e.Mind)

crop_shape$ValPre <- 1

#DataSpecies <- data.frame(crop_shape)

climateFiles_baseline = list.files("G:/biomod/", pattern=".asc$")

myExpl = stack(climateFiles_baseline)
myExpl.crop_ <- crop(myExpl,e.Mind)
my.ctrl.rst <- myExpl.crop_$bio_1*0 #create raster with 0

#myExpl.crop <- data.frame(myExpl.crop_)

#save crop layer into a new 
#x <- c(names(myExpl.crop))
#for (i in x){
#             print (i)
#             fname <- paste0("clip_",i,".asc")
#             rf <- writeRaster(myExpl.crop$i, filename = fname, overwrite=TRUE)
#            }

my.occ.crop.rst <- rasterize(crop_shape,

my.occ.crop.rst <- my.occ.crop.rst>0

my.occ.crop.shp <- rasterToPoints(my.occ.crop.rst,

DataSpecies <- data.frame(my.occ.crop.shp)

#myRespName <- 'GuloGulo'
myRespName <- 'Coffee'
myResp <- as.numeric(DataSpecies$layer)
myRespXY <- DataSpecies[,c("x","y")] #lon lat coordinates

rf <- writeRaster(myExpl.crop_$bio_1, filename = "clip_bio1.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_2, filename = "clip_bio2.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_3, filename = "clip_bio3.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_4, filename = "clip_bio4.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_5, filename = "clip_bio5.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_6, filename = "clip_bio6.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_7, filename = "clip_bio7.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_8, filename = "clip_bio8.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_9, filename = "clip_bio9.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_10, filename = "clip_bio10.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_11, filename = "clip_bio11.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_12, filename = "clip_bio12.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_13, filename = "clip_bio13.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_14, filename = "clip_bio14.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_15, filename = "clip_bio15.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_16, filename = "clip_bio16.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_17, filename = "clip_bio17.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_18, filename = "clip_bio18.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$bio_19, filename = "clip_bio19.tif", overwrite=TRUE)
rf <- writeRaster(myExpl.crop_$cons_dry_months_v2, filename = "clip_cons_dry_months_v2.tif", overwrite=TRUE)

climateFiles_baseline.crop = list.files("G:/biomod/", pattern="clip")

myExpl.crop = stack(climateFiles_baseline.crop)

myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
                                     expl.var = myExpl.crop,
                                     resp.xy = myRespXY,
                                     resp.name = myRespName,
                                     PA.nb.absences = sum(DataSpecies$layer), #number of Pseudo-absences as presences
                                     PA.strategy = 'random',
                                     PA.dist.min = 0,
                                     PA.dist.max = NULL,
                                     PA.sre.quant = 0.025,
                                     na.rm = TRUE)


myBiomodModelOut <- BIOMOD_Modeling(
                                    Models = c('SRE','ANN','RF'),
                                    model.options = myBiomodOption,
                                    NbRunEval = 3,
                                    DataSplit = 70,
                                    Prevalence = 0.5,
                                    VarImport = 3,
                                    models.eval.meth = c('KAPPA','TSS', 'ROC'),
                                    SaveObj = TRUE,
                                    rescal.all.models = TRUE,
                                    do.full.models = FALSE,
                                    modeling.id = paste(myRespName, "FirstModeling", sep="")

Here are some log messages from the interactive console:

Loading required library...

Checking Models arguments...
Warning in .Models.check.args(data, models, models.options, NbRunEval, DataSplit,  :
  Models will run with 'defaults' parameters

Creating suitable Workdir...

    > Automatic weights creation to rise a 0.5 prevalence

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Coffee Modeling Summary -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

 20  environmental variables ( clip_bio1 clip_bio10 clip_bio11 clip_bio12 clip_bio13 clip_bio14 clip_bio15 clip_bio16 clip_bio17 clip_bio18 clip_bio19 clip_bio2 clip_bio3 clip_bio4 clip_bio5 clip_bio6 clip_bio7 clip_bio8 clip_bio9 clip_cons_dry_months_v2 )
Number of evaluation repetitions : 3
Models selected : GLM GBM GAM CTA ANN SRE FDA MARS RF MAXENT.Tsuruoka 

Total number of model runs : 30 


-=-=-=- Run :  Coffee_AllData 

-=-=-=--=-=-=- Coffee_AllData_RUN1 

Model=GLM ( quadratic with no interaction )
    Stepwise procedure using AIC criteria
    selected formula : Coffee ~ clip_bio9 + clip_bio8 + clip_cons_dry_months_v2
<environment: 0x00000000252f4450>

    Model scaling...
    Evaluating Model stuff...
    Evaluating Predictor Contributions... 

Model=Generalised Boosting Regression 
     2500 maximum different trees and  3  Fold Cross-Validation
    Model scaling...
    Evaluating Model stuff...
    Evaluating Predictor Contributions... 

     GAM_mgcv algorithm chosen
    Automatic formula generation...
    > GAM (mgcv) modelling...
Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) : 
  A term has fewer unique covariate combinations than specified maximum degrees of freedom
In addition: Warning messages:
1: In .Models.check.args(data, models, models.options, NbRunEval, DataSplit,  :
  The maxent.jar file is missing. You need to download this file (http://www.cs.princeton.edu/~schapire/maxent) and put the maxent.jar file in your working directory -> MAXENT.Phillips was switched off
2: glm.fit: algorithm did not converge 
3: glm.fit: fitted probabilities numerically 0 or 1 occurred 
Error in predict(model.bm, Data[, expl_var_names, drop = FALSE], on_0_1000 = TRUE) : 
  object 'model.bm' not found

*** inherits(g.pred,'try-error')
   ! Note :  Coffee_AllData_RUN1_GAM failed!

Model=Classification tree 
     5 Fold Cross-Validation
    Model scaling...
    Evaluating Model stuff...
    Evaluating Predictor Contributions... 

Model=Artificial Neural Network 
     5 Fold Cross Validation + 3 Repetitions
    Model scaling...
    Evaluating Model stuff...
    Evaluating Predictor Contributions... 

Model=Surface Range Envelop
    Evaluating Model stuff...
    Evaluating Predictor Contributions... 

Model=Flexible Discriminant Analysis
    Model scaling...
*** single value predicted
   ! Note :  Coffee_AllData_RUN1_FDA failed!

Model=Multiple Adaptive Regression Splines ( simple with no interaction )

1 Answer 1


From the documentation:

BIOMOD_Modeling( data, 
                  models = c('GLM','GBM','GAM','CTA','ANN',

from your code:

BIOMOD_Modeling( myBiomodData,
                  Models = c('SRE','ANN','RF'),

R is case-sensitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.