biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
87 stars 22 forks source link

Help with BIOMOD2_4.2-5 - Error in { : task 1 failed - "task 12 failed - "argomento non numerico passato ad un operatore binario"" #476

Closed gsatta closed 4 months ago

gsatta commented 4 months ago

Hello everyone, for a few days now, when I run the BIOMOD_Modeling() function, the following error appears:

Evaluating Model stuff...Errore in { : task 1 failed - "task 12 failed - "argomento non numerico passato ad un operatore binario"" In aggiunta: Ci sono stati 45 avvertimenti (utilizza warnings() per visualizzarli)

What does it mean? what exactly is the option that can cause this problem?

Thank You

Here is the code and the information:

Code:

# Load the train and test points
myResp_train <- vect("./INPUT/VECTOR/train_data.gpkg")
myResp_test <- vect("./INPUT/VECTOR/test_data.gpkg")

# Load the environmental raster  at 50 m of spatial resolution
myExpl_0 <- rast("./INPUT/RASTER/environmental_50m.tiff")

myExpl <- subset(myExpl_0, c("BIO03", "green",
                             "BIO06", "fla","wo",
                             'roads', "soc",
                             "rivers"))

n_PA_3 <- length(myResp_train) 

# Format Data with pseudo - absences: random method
myBiomodData <- BIOMOD_FormatingData(expl.var = myExpl,
                                     resp.var = myResp_train,
                                     eval.resp.var = myResp_test,
                                     resp.name = "Phytophthora",
                                     PA.nb.rep = 2,
                                     PA.nb.absences = c(n_PA_3, 1000),
                                     PA.strategy = 'random',
                                     filter.raster = TRUE,
                                     dir.name = getwd())
myBiomodData

# plot(myBiomodData)

# Definisci i nomi delle colonne disponibili all'interno di bm.format@PA.table
PA_used <- colnames(myBiomodData@PA.table)

# Definisci i vettori per ciascun modello che indicano quali colonne di pseudo-assenza utilizzare
{
# CTA <- c("PA1")
FDA <- c("PA1")
RF <- c("PA1")
XGBOOST <- c("PA1")
GLM <- c("PA2")
GAM <- c("PA2")
MAXENT <- c("PA2")
MAXNET <- c("PA2")
GBM <- c("PA2")
}

# Costruisci la lista models.pa contenente questi vettori per ciascun modello
models.pa <- list(FDA = FDA, GBM = GBM, RF = RF, XGBOOST = XGBOOST, 
                  GLM = GLM, GAM = GAM, MAXENT = MAXENT)

allModels  <- c("FDA", "GAM", "GBM", "GLM", "MAXENT", "RF", "XGBOOST")

user.rf <- list('_allData_allRun' = list(type = 'classification', importance = TRUE, 
                                         nodesize = 1, oob.prox = T, ntree = 250, 
                                         mtry = 2))

user.maxent <- list('_allData_allRun' = list(visible = TRUE,
                                             beta_threshold = 0))

user.XGBOOST <- list('_allData_allRun' = list(objective = "binary:logistic",
                                              params =list(max_depth = 5, eta = 0.2, gamma = 1 ),
                                              nrounds = 20, subsample = 0.5))

form.GLM <- bm_MakeFormula(resp.name = myBiomodData@sp.name,
                           expl.var = head(myBiomodData@data.env.var),
                           type = 's_smoother',
                           interaction.level = 0)

user.GLM <- list('_allData_allRun' = list(formula = form.GLM))

form.GAM <- bm_MakeFormula(resp.name = myBiomodData@sp.name,
                           expl.var = head(myBiomodData@data.env.var),
                           type = 's_smoother',
                           interaction.level = 0)

user.GAM <- list('_allData_allRun' = list(formula = form.GAM))

user.val <- list(RF.binary.randomForest.randomForest = user.rf,
                 MAXENT.binary.MAXENT.MAXENT = user.maxent,
                 XGBOOST.binary.xgboost.xgboost = user.XGBOOST,
                 GLM.binary.stats.glm= user.GLM,
                 GAM.binary.mgcv.gam= user.GAM)

# bigboss parameters
myBiomodOption <- bm_ModelingOptions(data.type = 'binary',
                            models = allModels,
                            strategy = "user.defined",
                            user.base = 'bigboss',
                            user.val = user.val)

############################# Run the single models ############################
# single models
myBiomodModelOut <- BIOMOD_Modeling(
  bm.format = myBiomodData,
  bm.options = myBiomodOption,
  modeling.id = as.character(format(Sys.time(), "%Y%m%d_%H%M_%S")),
  models = allModels,
  models.pa = models.pa,
  CV.strategy = 'kfold',
  CV.nb.rep = 2,
  CV.k = 5,
  var.import = 3,
  metric.eval = c("ROC", "TSS", "KAPPA", "ACCURACY", "BIAS", "POD", "FAR", "POFD",
                  "SR", "CSI", "ETS", "HK", "HSS", "OR", "ORSS", "BOYCE", "MPA"),
  seed.val = 123,
  do.progress = TRUE,
)

Session info

sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=Italian_Italy.utf8 
[2] LC_CTYPE=Italian_Italy.utf8   
[3] LC_MONETARY=Italian_Italy.utf8
[4] LC_NUMERIC=C                  
[5] LC_TIME=Italian_Italy.utf8    

time zone: Europe/Rome
tzcode source: internal

attached base packages:
[1] splines   stats     graphics  grDevices utils    
[6] datasets  methods   base     

other attached packages:
 [1] xgboost_1.7.7.1      randomForest_4.7-1.1
 [3] maxnet_0.1.4         earth_5.3.3         
 [5] plotmo_3.6.3         plotrix_3.8-4       
 [7] Formula_1.2-5        gbm_2.1.9           
 [9] mgcv_1.9-0           nlme_3.1-163        
[11] gam_1.22-3           foreach_1.5.2       
[13] mda_0.5-4            class_7.3-22        
[15] rpart_4.1.21         nnet_7.3-19         
[17] biomod2_4.2-5        terra_1.7-71        
[19] sf_1.0-16            readr_2.1.5         

loaded via a namespace (and not attached):
 [1] shape_1.4.6.1          gtable_0.3.4          
 [3] xfun_0.44              ggplot2_3.5.1         
 [5] raster_3.6-26          lattice_0.22-5        
 [7] tzdb_0.4.0             vctrs_0.6.5           
 [9] tools_4.3.2            generics_0.1.3        
[11] tibble_3.2.1           proxy_0.4-27          
[13] PresenceAbsence_1.1.11 fansi_1.0.6           
[15] pkgconfig_2.0.3        Matrix_1.6-1.1        
[17] KernSmooth_2.23-22     data.table_1.15.4     
[19] lifecycle_1.0.4        farver_2.1.1          
[21] compiler_4.3.2         stringr_1.5.1         
[23] munsell_0.5.0          dismo_1.3-14          
[25] codetools_0.2-19       glmnet_4.1-8          
[27] tidyr_1.3.1            pillar_1.9.0          
[29] classInt_0.4-10        iterators_1.0.14      
[31] abind_1.4-5            commonmark_1.9.1      
[33] tidyselect_1.2.1       stringi_1.8.3         
[35] purrr_1.0.2            dplyr_1.1.4           
[37] reshape2_1.4.4         grid_4.3.2            
[39] colorspace_2.1-0       cli_3.6.2             
[41] magrittr_2.0.3         survival_3.5-7        
[43] utf8_1.2.4             e1071_1.7-14          
[45] withr_3.0.0            scales_1.3.0          
[47] sp_2.1-3               tidyterra_0.5.2       
[49] ggtext_0.1.2           hms_1.1.3             
[51] markdown_1.12          rlang_1.1.3           
[53] gridtext_0.1.5         Rcpp_1.0.12           
[55] glue_1.7.0             DBI_1.2.2             
[57] xml2_1.3.6             pROC_1.18.5           
[59] jsonlite_1.8.8         rstudioapi_0.15.0     
[61] reshape_0.8.9          R6_2.5.1              
[63] plyr_1.8.9             intervals_0.15.4      
[65] units_0.8-5           

Error and Warnings

Evaluating Model stuff...Errore in { : 
  task 1 failed - "task 12 failed - "argomento non numerico passato ad un operatore binario""
In aggiunta: Ci sono stati 45 avvertimenti (utilizza warnings() per visualizzarli)

> warnings()
Messaggi di avvertimento:
1: In .bm_ModelingOptions.check.args(data.type = data.type,  ... :
  Only one GAM model can be activated. 'GAM.mgcv.gam' has been set (other available : 'GAM.gam.gam' or 'GAM.mgcv.bam')
2: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
3: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
4: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
5: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
6: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
7: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
8: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
9: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
10: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
11: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
12: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
13: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
14: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
15: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
16: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
17: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
18: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
19: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
20: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
21: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
22: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
23: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
24: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
25: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
26: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
27: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
28: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
29: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
30: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
31: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
32: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
33: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
34: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
35: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
36: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
37: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
38: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
39: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
40: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
41: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
42: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
43: In predict.gbm(get_formal_model(object), as.data.frame(newdata[not_na_rows,  ... :
  Number of trees not specified or exceeded number fit so far. Using 100.
44: glm.fit: si sono verificate probabilità stimate numericamente pari a 0 o 1
45: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  ... :
  prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases

Information about myBiomodData

> myBiomodData

-=-=-=-=-=-=-=-= BIOMOD.formated.data -=-=-=-=-=-=-=-=

dir.name =  
D:/DOTTORATO/PROGETTI/PAULLILATINO/PAPER_2/SDM_R_PROJECT/SDM_biomod2_50m

sp.name =  Phytophthora

     31 presences,  0 true absences and  1029 
undefined points in dataset

     8 explanatory variables

     BIO03           green             BIO06      
 Min.   :36.79   Min.   :0.07934   Min.   :3.802  
 1st Qu.:37.83   1st Qu.:0.09657   1st Qu.:4.928  
 Median :38.27   Median :0.10437   Median :5.184  
 Mean   :38.44   Mean   :0.10641   Mean   :5.098  
 3rd Qu.:38.76   3rd Qu.:0.11362   3rd Qu.:5.292  
 Max.   :41.85   Max.   :0.18633   Max.   :5.763  
      fla                wo             roads         
 Min.   :   99.6   Min.   :0.0000   Min.   :  0.7228  
 1st Qu.: 1086.1   1st Qu.:1.0000   1st Qu.: 48.4188  
 Median : 2014.9   Median :1.0000   Median :104.5611  
 Mean   : 3275.5   Mean   :0.8585   Mean   :138.0585  
 3rd Qu.: 3624.6   3rd Qu.:1.0000   3rd Qu.:197.0609  
 Max.   :63286.3   Max.   :1.0000   Max.   :807.1188  
      soc            rivers        
 Min.   : 0.00   Min.   :   1.934  
 1st Qu.:21.25   1st Qu.: 113.952  
 Median :22.91   Median : 254.110  
 Mean   :23.01   Mean   : 316.447  
 3rd Qu.:24.88   3rd Qu.: 434.824  
 Max.   :31.69   Max.   :1458.233  

Evaluation data :

     14 presences,  14 true absences and  0 
undefined points in dataset

     BIO03           green             BIO06      
 Min.   :37.05   Min.   :0.08691   Min.   :4.540  
 1st Qu.:37.81   1st Qu.:0.09492   1st Qu.:5.096  
 Median :38.32   Median :0.10230   Median :5.216  
 Mean   :38.47   Mean   :0.10441   Mean   :5.192  
 3rd Qu.:38.73   3rd Qu.:0.11226   3rd Qu.:5.354  
 Max.   :41.01   Max.   :0.13800   Max.   :5.668  
      fla                wo        roads       
 Min.   :  259.8   Min.   :1   Min.   : 13.30  
 1st Qu.:  750.4   1st Qu.:1   1st Qu.: 44.14  
 Median : 1467.9   Median :1   Median : 91.11  
 Mean   : 2066.2   Mean   :1   Mean   :111.03  
 3rd Qu.: 2503.7   3rd Qu.:1   3rd Qu.:151.07  
 Max.   :10850.0   Max.   :1   Max.   :432.51  
      soc            rivers      
 Min.   :17.99   Min.   : 28.98  
 1st Qu.:20.93   1st Qu.:101.76  
 Median :22.26   Median :270.17  
 Mean   :22.66   Mean   :309.61  
 3rd Qu.:24.33   3rd Qu.:506.55  
 Max.   :30.30   Max.   :745.11  

 2 Pseudo Absences dataset available ( PA1, PA2 
) with  31 (PA1), 1000 (PA2) pseudo absences

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

> summary(myBiomodData)
      dataset run   PA Presences True_Absences
1     initial  NA <NA>        31             0
2  evaluation  NA <NA>        14            14
3 calibration  NA  PA1        31             0
4 calibration  NA  PA2        31             0
  Pseudo_Absences Undefined
1               0      1029
2               0         0
3              31        NA
4            1000        NA
HeleneBlt commented 4 months ago

Hi Gabriele,

Sorry, we remove the metrics "HK" and "HSS" from the list of available metrics. But we haven't changed all the documentation. We will soon push a commit to correct this and add an appropriate warning.

Until now, you can just remove them from your list of metrics and it will be fine.

Sorry 😬

Hélène

gsatta commented 4 months ago

Hi Hélène,

Thank you for the quick reply !