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

Error in BIOMOD_4.2-6-1 - ["argument of length 0"] #528

Closed zali37 closed 1 week ago

zali37 commented 2 weeks ago

Hello I am trying to perform an ENM but I am still learning so I get another error. I made an ensemble model with four algorithms and projections to four futures but when I want to get the boxplot of the importance of the variables I get an error. I think another person already asked for that but the answer was not useful to me.

Code used to get the error bibronii_format <- BIOMOD_FormatingData( resp.name = "bibronii", resp.var = bibronii$presence, resp.xy = bibronii[, c("lon", "lat")], expl.var = stk_current, filter.raster = TRUE ) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.formated.data -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

dir.name = .

sp.name = bibronii

 126 presences,  35 true absences and  0 undefined points in dataset

 4 explanatory variables

clip_bio2 clip_bio5 clip_bio6 clip_bio15
Min. : 4.790 Min. :12.80 Min. :-7.868 Min. : 8.293
1st Qu.: 9.809 1st Qu.:18.88 1st Qu.:-2.692 1st Qu.:22.416
Median :10.771 Median :21.78 Median :-1.044 Median :27.490
Mean :10.268 Mean :20.80 Mean :-1.248 Mean :28.057
3rd Qu.:11.210 3rd Qu.:23.28 3rd Qu.: 0.516 3rd Qu.:31.406
Max. :13.795 Max. :27.05 Max. : 2.884 Max. :60.632

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= bibronii_opt <- bm_ModelingOptions( data.type = "binary", models=c("SRE","RF", "GAM", "ANN"), bm.format = bibronii_format, strategy = "user.defined", user.base = "bigboss", user.val = list(SRE.binary.biomod2.bm_SRE = opt.sre, RF.binary.randomForest.randomForest = user.rf, GAM.binary.mgcv.gam = tuned.gam, ANN.binary.nnet.nnet = tuned.ann) )

bibronii_modelo <- BIOMOD_Modeling( bm.format = bibronii_format, modeling.id = "solo_bibronii", models = c("SRE", "RF", "GAM", "ANN"), CV.strategy = "random", CV.nb.rep = 5, CV.perc = 0.8, var.import = 3, OPT.strategy = "user.defined", OPT.user = bibronii_opt, metric.eval = c("TSS", "ROC") ) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.models.out -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Modeling folder : .

Species modeled : bibronii

Modeling id : solo_bibronii

Considered variables : clip_bio2 clip_bio5 clip_bio6 clip_bio15

Computed Models : bibronii_allData_RUN1_SRE bibronii_allData_RUN1_RF bibronii_allData_RUN1_GAM bibronii_allData_RUN1_ANN bibronii_allData_RUN2_SRE bibronii_allData_RUN2_RF bibronii_allData_RUN2_GAM bibronii_allData_RUN2_ANN bibronii_allData_RUN3_SRE bibronii_allData_RUN3_RF bibronii_allData_RUN3_GAM bibronii_allData_RUN3_ANN bibronii_allData_RUN4_SRE bibronii_allData_RUN4_RF bibronii_allData_RUN4_GAM bibronii_allData_RUN4_ANN bibronii_allData_RUN5_SRE bibronii_allData_RUN5_RF bibronii_allData_RUN5_GAM bibronii_allData_RUN5_ANN bibronii_allData_allRun_SRE bibronii_allData_allRun_RF bibronii_allData_allRun_GAM bibronii_allData_allRun_ANN

Failed Models : none

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= bibronii_ensemble_models <- BIOMOD_EnsembleModeling( bm.mod = bibronii_modelo, models.chosen = "all", em.by = "all", em.algo = c("EMmean", "EMca", "EMcv"), metric.select = c("TSS", "ROC"), metric.select.thresh = c(0.7, 0.7), metric.select.dataset = "calibration", metric.eval = c("TSS", "ROC"), var.import = 0 )

-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.ensemble.models.out -=-=-=-=-=-=-=-=-=-=-=-=-=-= sp.name : bibronii expl.var.names : clip_bio2 clip_bio5 clip_bio6 clip_bio15 models computed: bibronii_EMmeanByTSS_mergedData_mergedRun_mergedAlgo, bibronii_EMcaByTSS_mergedData_mergedRun_mergedAlgo, bibronii_EMcvByTSS_mergedData_mergedRun_mergedAlgo, bibronii_EMmeanByROC_mergedData_mergedRun_mergedAlgo, bibronii_EMcaByROC_mergedData_mergedRun_mergedAlgo, bibronii_EMcvByROC_mergedData_mergedRun_mergedAlgo models failed: none -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= --     |    

proj_scen <- c("stk_current", "stk_future_ssp370_2060", "stk_future_ssp370_2100", "stk_future_ssp585_2060", "stk_future_ssp585_2100")

for (scen in proj_scen) { cat("\n> projections of", scen) bibronii_proj <- BIOMOD_Projection( bm.mod = bibronii_modelo, proj.name = scen, new.env = get(scen), models.chosen = "all", metric.binary = "TSS", build.clamping.mask = FALSE, do.stack = FALSE, output.format = ".img" ) bibronii_ens_proj <- BIOMOD_EnsembleForecasting( bm.em = bibronii_ensemble_models, bm.proj = bibronii_proj, proj.name = "CurrentENMbibronii", models.chosen = 'all', metric.binary = 'TSS', metric.filter = 'all', do.stack = FALSE, output.format = ".img" ) } -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.projection.out -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Projection directory : ./bibronii/stk_future_ssp585_2100

sp.name : bibronii

expl.var.names : clip_bio2 clip_bio5 clip_bio6 clip_bio15

modeling.id : solo_bibronii ( ./bibronii/bibronii.solo_bibronii.models.out )

models.projected : bibronii_allData_RUN1_SRE, bibronii_allData_RUN1_RF, bibronii_allData_RUN1_GAM, bibronii_allData_RUN1_ANN, bibronii_allData_RUN2_SRE, bibronii_allData_RUN2_RF, bibronii_allData_RUN2_GAM, bibronii_allData_RUN2_ANN, bibronii_allData_RUN3_SRE, bibronii_allData_RUN3_RF, bibronii_allData_RUN3_GAM, bibronii_allData_RUN3_ANN, bibronii_allData_RUN4_SRE, bibronii_allData_RUN4_RF, bibronii_allData_RUN4_GAM, bibronii_allData_RUN4_ANN, bibronii_allData_RUN5_SRE, bibronii_allData_RUN5_RF, bibronii_allData_RUN5_GAM, bibronii_allData_RUN5_ANN, bibronii_allData_allRun_SRE, bibronii_allData_allRun_RF, bibronii_allData_allRun_GAM, bibronii_allData_allRun_ANN

available binary projection : TSS

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.projection.out -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Projection directory : ./bibronii/CurrentENMbibronii

sp.name : bibronii

expl.var.names : clip_bio2 clip_bio5 clip_bio6 clip_bio15

modeling.id : solo_bibronii ( ./bibronii/bibronii.solo_bibronii.ensemble.models.out )

models.projected : bibronii_EMmeanByTSS_mergedData_mergedRun_mergedAlgo, bibronii_EMcaByTSS_mergedData_mergedRun_mergedAlgo, bibronii_EMcvByTSS_mergedData_mergedRun_mergedAlgo, bibronii_EMmeanByROC_mergedData_mergedRun_mergedAlgo, bibronii_EMcaByROC_mergedData_mergedRun_mergedAlgo, bibronii_EMcvByROC_mergedData_mergedRun_mergedAlgo

available binary projection : TSS

available filtered projection : TSS, ROC

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= bm_PlotVarImpBoxplot(bm.out = bibronii_ensemble_models, group.by = c('expl.var', 'full.name', 'full.name')) Error in { : task 1 failed - "argument of length 0" In addition: Warning message: In .local(obj, ...) : No link provided for this object

show(stk_current) class : RasterStack dimensions : 335, 291, 97485, 4 (nrow, ncol, ncell, nlayers) resolution : 0.04166667, 0.04166667 (x, y) extent : -75.70833, -63.58333, -55.95833, -42 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs names : clip_bio2, clip_bio5, clip_bio6, clip_bio15 min values : 3.751515, 0.800000, -14.472000, 6.956398 max values : 14.04067, 29.30000, 3.70000, 67.16410

show(stk_future_ssp370_2060) class : RasterStack dimensions : 335, 291, 97485, 4 (nrow, ncol, ncell, nlayers) resolution : 0.04166667, 0.04166666 (x, y) extent : -75.70833, -63.58333, -55.95833, -42 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs names : clip_bio2, clip_bio5, clip_bio6, clip_bio15 min values : 4.30, 3.98, -10.84, 8.10 max values : 14.44, 30.26, 4.84, 68.50

show(stk_future_ssp370_2100) class : RasterStack dimensions : 337, 293, 98741, 4 (nrow, ncol, ncell, nlayers) resolution : 0.04166666, 0.04166668 (x, y) extent : -75.75, -63.54167, -56, -41.95833 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs names : clip_bio2, clip_bio5, clip_bio6, clip_bio15 min values : 3.76, 4.22, -11.00, 6.56 max values : 14.82, 33.86, 6.40, 71.84

show(stk_future_ssp585_2060) class : RasterStack dimensions : 337, 293, 98741, 4 (nrow, ncol, ncell, nlayers) resolution : 0.04166666, 0.04166668 (x, y) extent : -75.75, -63.54167, -56, -41.95833 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs names : clip_bio2, clip_bio5, clip_bio6, clip_bio15 min values : 3.74, 3.12, -12.38, 7.96 max values : 14.54, 32.12, 5.28, 70.08

show(stk_future_ssp585_2100) class : RasterStack dimensions : 337, 293, 98741, 4 (nrow, ncol, ncell, nlayers) resolution : 0.04166666, 0.04166668 (x, y) extent : -75.75, -63.54167, -56, -41.95833 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs names : clip_bio2, clip_bio5, clip_bio6, clip_bio15 min values : 3.78, 4.86, -10.48, 6.80 max values : 15.04, 34.94, 6.94, 73.16

Environment Information

sessionInfo() R version 4.3.3 (2024-02-29 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/Buenos_Aires tzcode source: internal

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

other attached packages: [1] caret_6.0-94 ggplot2_3.5.1 snowfall_1.84-6.3
[4] snow_0.4-4 biomod2_4.2-6-1 xgboost_1.7.8.1
[7] randomForest_4.7-1.2 maxnet_0.1.4 earth_5.3.3
[10] plotmo_3.6.4 plotrix_3.8-4 Formula_1.2-5
[13] gbm_2.2.2 lattice_0.22-5 doParallel_1.0.17
[16] iterators_1.0.14 ggtext_0.1.2 tidyterra_0.6.1
[19] mgcv_1.9-1 nlme_3.1-166 gam_1.22-5
[22] foreach_1.5.2 raster_3.6-26 sp_2.1-4
[25] mda_0.5-4 class_7.3-22 rpart_4.1.23
[28] nnet_7.3-19 terra_1.7-78

loaded via a namespace (and not attached): [1] tidyselect_1.2.1 viridisLite_0.4.2 timeDate_4032.109
[4] farver_2.1.2 dplyr_1.1.4 reshape_0.8.9
[7] pROC_1.18.5 digest_0.6.35 timechange_0.3.0
[10] lifecycle_1.0.4 sf_1.0-16 survival_3.6-4
[13] magrittr_2.0.3 compiler_4.3.3 rlang_1.1.3
[16] tools_4.3.3 utf8_1.2.4 data.table_1.15.4
[19] labeling_0.4.3 classInt_0.4-10 PresenceAbsence_1.1.11 [22] plyr_1.8.9 xml2_1.3.6 abind_1.4-5
[25] KernSmooth_2.23-22 withr_3.0.1 purrr_1.0.2
[28] stats4_4.3.3 grid_4.3.3 fansi_1.0.6
[31] future_1.34.0 e1071_1.7-13 colorspace_2.1-1
[34] globals_0.16.3 scales_1.3.0 MASS_7.3-60.0.1
[37] cli_3.6.2 generics_0.1.3 rstudioapi_0.16.0
[40] future.apply_1.11.2 reshape2_1.4.4 DBI_1.2.2
[43] proxy_0.4-27 stringr_1.5.1 vctrs_0.6.5
[46] hardhat_1.4.0 Matrix_1.6-1.1 jsonlite_1.8.8
[49] listenv_0.9.1 gower_1.0.1 tidyr_1.3.1
[52] units_0.8-5 recipes_1.1.0 parallelly_1.38.0
[55] glue_1.7.0 codetools_0.2-19 dismo_1.3-14
[58] lubridate_1.9.3 stringi_1.8.4 gtable_0.3.5
[61] munsell_0.5.1 tibble_3.2.1 pillar_1.9.0
[64] ipred_0.9-15 lava_1.8.0 R6_2.5.1
[67] gridtext_0.1.5 Rcpp_1.0.12 prodlim_2024.06.25
[70] ModelMetrics_1.2.2.2 pkgconfig_2.0.3

Additional information Thanks a lot for your help! Natalia

MayaGueguen commented 1 week ago

Hello Natalia,

Thank you for the issue well detailed 🙏

The error you get when calling bm_PlotVarImpBoxplot comes from the fact that, when calling BIOMOD_EnsembleModeling, you set var.import = 0, meaning that no randomisation has been done for calculating the importance of each variable. I'm afraid that you will have to re-run this function if you want to have this information....

Apologies for the error message that is not clear at all, we will try to improve that !

Maya

zali37 commented 1 week ago

Hi Maya You are right! Thank you so much. Natalia