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: no species selected #387

Closed anackr closed 10 months ago

anackr commented 10 months ago

Context and question Hi everyone. I am modeling a mosquito species for my research and am having some trouble including an evaluation dataset. Before I included it the models ran, but now every single model fails. When I open the .stderr file, all of them say "Error: No species selected". _Obs: I replaced NAs (background) points of the evaluation dataset for 0 because I was running into the error "Error in .check_formatingresp.var(resp.var = eval.sp, eval.data = TRUE) : Evaluation response data must have both presences and absences" and this issue says the NAs should be replaced for 0, even though they are only background points. Obs2: 'bioclimaticas' is a rasterstack object Could anyone help, please?

Code used

Creating datasets

Training presences

myResp <- treino$VECTOR

myRespXY <- data.frame(X_WGS84 = treino$lon, Y_WGS84 = treino$lat)

Evaluation presences + replacing background (NA) for true absence (0)

teste <- rbind(sc_teste, pa) %>% mutate(VECTOR = ifelse(is.na(VECTOR), 0, VECTOR))

myResp_eval <- teste$VECTOR

myResp_eval.XY <- data.frame(X_WGS84 = teste$lon, Y_WGS84 = teste$lat)

PA

myPAtable <- data.frame( column = ifelse(is.na(myResp), T, ifelse(myResp == 1, F, T)))

FORMATING DATA

myBiomodData <- BIOMOD_FormatingData( resp.var = myResp, expl.var = bioclimaticas, resp.xy = myRespXY, eval.resp.var = myResp_eval, eval.expl.var = bioclimaticas, eval.resp.xy = myResp_eval.XY, resp.name = 'Sabethes chloropterus', PA.strategy = 'user.defined', PA.user.table = myPAtable )

MODELING

Model options

L1 <- BIOMOD_ModelingOptions(MAXENT = list( linear = T, quadratic = F, product = F, threshold = F, hinge = F, betamultiplier = 1))

Model

maxent_l1 <- BIOMOD_Modeling( bm.format = myBiomodData, models = 'MAXENT', bm.options = L1, CV.strategy = 'kfold', CV.nb.rep = 4, CV.k = 4, metric.eval = c('ROC', 'POD', 'TSS') )

Data I put the 'treino' and 'teste' object in this drive link. Also the summary(myBiomodData) shows the following:

summary(myBiomodData) dataset run PA Presences True_Absences Pseudo_Absences Undefined 1 initial NA 24 0 0 9997 2 evaluation NA 10 9997 0 0 3 calibration NA PA1 0 0 9997 NA

Interesting parts of the outputs `Checking Cross-Validation arguments...

k-fold cross-validation selection !!! Some calibration dataset do not have both presences and absences: _PA1_RUN1, _PA1_RUN2, _PA1_RUN3, _PA1_RUN4, _PA1_RUN5, _PA1_RUN6, _PA1_RUN7, _PA1_RUN8, _PA1_RUN9, _PA1_RUN10, _PA1_RUN11, _PA1_RUN12, _PA1_RUN13, _PA1_RUN14, _PA1_RUN15, _PA1_RUN16 !!! Some validation dataset do not have both presences and absences: _PA1_RUN1, _PA1_RUN2, _PA1_RUN3, _PA1_RUN4, _PA1_RUN5, _PA1_RUN6, _PA1_RUN7, _PA1_RUN8, _PA1_RUN9, _PA1_RUN10, _PA1_RUN11, _PA1_RUN12, _PA1_RUN13, _PA1_RUN14, _PA1_RUN15, _PA1_RUN16 Model=MAXENT MAXENT modeling... Creating Maxent Temp Proj Data... Error in MAXENT, more info available in ./Sabethes.chloropterus/models/1703192218/Sabethes.chloropterus_PA1_RUN1_MAXENT_outputs/maxent.stderr inherits(g.pred,'try-error') ! Note : Sabethes.chloropterus_PA1_RUN1_MAXENT failed!`

Session info `R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 22621)

Matrix products: default

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

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

other attached packages: [1] dismo_1.3-9 dplyr_1.1.0 rasterVis_0.51.5 lattice_0.20-45 [5] raster_3.6-20 sp_1.6-0 gridExtra_2.3 ggplot2_3.4.1
[9] biomod2_4.2-4-10

loaded via a namespace (and not attached): [1] tidyr_1.3.0 jsonlite_1.8.4 viridisLite_0.4.1
[4] splines_4.2.2 foreach_1.5.2 Formula_1.2-4
[7] latticeExtra_0.6-30 pillar_1.8.1 glue_1.6.2
[10] pROC_1.18.4 gridtext_0.1.5 RColorBrewer_1.1-3
[13] randomForest_4.7-1.1 colorspace_2.1-0 gbm_2.1.8.1
[16] Matrix_1.5-3 plyr_1.8.8 pkgconfig_2.0.3
[19] maxnet_0.1.4 PresenceAbsence_1.1.11 earth_5.3.2
[22] purrr_1.0.1 scales_1.2.1 terra_1.7-18
[25] jpeg_0.1-10 TeachingDemos_2.12 tibble_3.1.8
[28] proxy_0.4-27 mgcv_1.8-41 mda_0.5-3
[31] farver_2.1.1 generics_0.1.3 xgboost_1.7.5.1
[34] tidyterra_0.4.0 withr_2.5.0 nnet_7.3-18
[37] hexbin_1.28.3 cli_3.6.0 survival_3.5-0
[40] magrittr_2.0.3 deldir_1.0-6 ggtext_0.1.2
[43] fansi_1.0.4 nlme_3.1-162 MASS_7.3-58.1
[46] xml2_1.3.3 class_7.3-21 tools_4.2.2
[49] data.table_1.14.6 lifecycle_1.0.3 stringr_1.5.0
[52] interp_1.1-3 munsell_0.5.0 plotrix_3.8-2
[55] compiler_4.2.2 e1071_1.7-13 rlang_1.1.0
[58] plotmo_3.6.2 classInt_0.4-9 units_0.8-1
[61] grid_4.2.2 iterators_1.0.14 rstudioapi_0.14
[64] gtable_0.3.1 codetools_0.2-19 abind_1.4-5
[67] DBI_1.1.3 reshape_0.8.9 markdown_1.5
[70] reshape2_1.4.4 R6_2.5.1 zoo_1.8-11
[73] rgdal_1.6-5 utf8_1.2.3 commonmark_1.8.1
[76] KernSmooth_2.23-20 stringi_1.7.12 parallel_4.2.2
[79] Rcpp_1.0.10 vctrs_0.5.2 sf_1.0-12
[82] rpart_4.1.19 png_0.1-8 xfun_0.37
[85] tidyselect_1.2.0 `

HeleneBlt commented 10 months ago

Hello there, Thanks for sharing directly your code and data : I was able to reproduce your error. However, I didn't find that's your dataset evaluation is the problem, but more your choice of pseudo-absences. With your myPAtable, you exclude all presences and therefore prevent the model from running. I will advise you to change your Pseudo-Absence strategy or change your column in myPAtable by TRUE for all observations. You could find more information about Pseudo-absences here or in the help of the function BIOMOD_FormatingData. Don't hesitate if it's not clear or if you still find an error. Hélène

anackr commented 10 months ago

@HeleneBlt it worked! thank you so much!