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.
89 stars 22 forks source link

Error in BIOMOD_EnsembleForecasting - Creating suitable Workdir... Error in { : task 1 failed - "NULL value passed as symbol address" #497

Open chenyongpeng1 opened 2 months ago

chenyongpeng1 commented 2 months ago

Error and context Creating suitable Workdir... Error in { : task 1 failed - "NULL value passed as symbol address" Code used to get the error `myBiomodData.r <- BIOMOD_FormatingData(resp.var = myResp, expl.var = myExpl, resp.xy = myRespXY, resp.name = myRespName, PA.nb.rep =2, PA.nb.absences = PA.number, PA.strategy = 'random') plot(myBiomodData.r)

jar=paste0(system.file(package = "dismo"),"/java/maxent.jar") system.file("java",package = "dismo")

define individual models options ----

library(parallel) library(doParallel) cl <- makeCluster(2) registerDoParallel(cl) on.exit(stopCluster(cl))

allModels <- c("ANN", "CTA", "FDA", "GAM", "GBM", "GLM", "MAXNET", "RF", "SRE", "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.r@sp.name, expl.var = head(myBiomodData.r@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.r@sp.name, expl.var = head(myBiomodData.r@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)

myBiomodModelOut <- BIOMODModeling( bm.format = myBiomodData.r, bm.options = myBiomodOption, modeling.id = as.character(format(Sys.time(), "%Y%m%d%H%M_%S")), models = allModels, CV.strategy = 'random', CV.nb.rep = 4, CV.perc = 0.8, OPT.strategy = 'bigboss', var.import = 3, metric.eval = c( "ROC", "TSS", "KAPPA"), seed.val = 123, do.progress = TRUE, )

myBiomodModelOut

Get evaluation scores & variables importance

myBiomodModelEval<-get_evaluations(myBiomodModelOut) myBiomodModelEval get_variables_importance(myBiomodModelOut) dimnames(myBiomodModelEval) write.csv(myBiomodModelEval,file = "./myBiomodModelEval_145.csv")

Model ensemble models

myBiomodEM <- BIOMOD_EnsembleModeling(bm.mod = myBiomodModelOut, models.chosen = 'all', em.by = 'all', metric.select = c("TSS"), metric.select.thresh = c(0.7), var.import = 3, metric.eval = c('TSS', 'TSS'),

em.algo = c('EMmean', 'EMcv', 'EMci', 'EMmedian', 'EMca', 'EMwmean'),

                                  em.algo = c('EMca','EMwmean'),
                                  EMci.alpha = 0.05,
                                  EMwmean.decay = 'proportional')

myBiomodEM

enmyBiomodModelEval<-get_evaluations(myBiomodEM) enmyBiomodModelEval write.csv(enmyBiomodModelEval,file = "./enmyBiomodModelEval_145.csv") envarimportan<-get_variables_importance(myBiomodEM)

write.csv(envarimportan,"./envarimportan_20.csv")

myBiomodProj <- BIOMOD_Projection(bm.mod = myBiomodModelOut, proj.name = 'Current', new.env = myExpl, models.chosen = 'all', metric.binary = 'TSS', metric.filter = 'TSS', build.clamping.mask = TRUE) myBiomodProj

myBiomodEMProj <- biomod2::BIOMOD_EnsembleForecasting(bm.em = myBiomodEM, bm.proj = myBiomodProj,

output.format = ".img",

                                                  models.chosen = 'all',
                                                  metric.binary = 'TSS',
                                                  metric.filter = 'TSS')

myBiomodEMProj

Environment Information

``sessionInfo() R version 4.4.0 (2024-04-24 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale: [1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8
[3] LC_MONETARY=Chinese (Simplified)_China.utf8 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.utf8

time zone: Asia/Shanghai tzcode source: internal

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

other attached packages: [1] doParallel_1.0.17 iterators_1.0.14 sf_1.0-16 terra_1.7-71
[5] fuzzySim_4.10.7 dplyr_1.1.4 ggpubr_0.6.0 maps_3.4.2
[9] rgbif_3.8.0 spThin_0.2.0 knitr_1.48 fields_15.2
[13] viridisLite_0.4.2 spam_2.10-0 rasterVis_0.51.6 lattice_0.22-6
[17] raster_3.6-26 sp_2.1-4 gridExtra_2.3 ggplot2_3.5.1
[21] xgboost_1.7.8.1 randomForest_4.7-1.1 maxnet_0.1.4 earth_5.3.3
[25] plotmo_3.6.3 plotrix_3.8-4 Formula_1.2-5 gbm_2.1.9
[29] mgcv_1.9-1 nlme_3.1-164 gam_1.22-4 foreach_1.5.2
[33] mda_0.5-4 class_7.3-22 rpart_4.1.23 nnet_7.3-19
[37] biomod2_4.2-5-2

loaded via a namespace (and not attached): [1] DBI_1.2.3 deldir_2.0-4 pROC_1.18.5 s2_1.1.7
[5] rlang_1.1.3 magrittr_2.0.3 tidyterra_0.6.1 e1071_1.7-14
[9] compiler_4.4.0 systemfonts_1.1.0 png_0.1-8 vctrs_0.6.5
[13] reshape2_1.4.4 stringr_1.5.1 wk_0.9.2 pkgconfig_2.0.3
[17] backports_1.5.0 labeling_0.4.3 utf8_1.2.4 markdown_1.13
[21] ragg_1.3.2 purrr_1.0.2 xfun_0.47 jsonlite_1.8.8
[25] PresenceAbsence_1.1.11 reshape_0.8.9 jpeg_0.1-10 broom_1.0.6
[29] R6_2.5.1 stringi_1.8.3 RColorBrewer_1.1-3 car_3.1-2
[33] Rcpp_1.0.12 zoo_1.8-12 Matrix_1.7-0 tidyselect_1.2.1
[37] rstudioapi_0.16.0 abind_1.4-5 ggtext_0.1.2 codetools_0.2-20
[41] tibble_3.2.1 plyr_1.8.9 withr_3.0.1 survival_3.5-8
[45] units_0.8-5 proxy_0.4-27 xml2_1.3.6 pillar_1.9.0
[49] carData_3.0-5 KernSmooth_2.23-22 whisker_0.4.1 modEvA_3.13.3
[53] generics_0.1.3 commonmark_1.9.1 munsell_0.5.1 scales_1.3.0
[57] glue_1.7.0 lazyeval_0.2.2 tools_4.4.0 interp_1.1-6
[61] hexbin_1.28.3 data.table_1.16.0 ggsignif_0.6.4 dotCall64_1.1-1
[65] tidyr_1.3.1 latticeExtra_0.6-30 colorspace_2.1-0 cli_3.6.2
[69] textshaping_0.4.0 fansi_1.0.6 gtable_0.3.5 rstatix_0.7.2
[73] oai_0.4.0 classInt_0.4-10 farver_2.1.2 lifecycle_1.0.4
[77] httr_1.4.7 gridtext_0.1.5 `

Additional information Windows

HeleneBlt commented 2 months ago

Hello Chenyong 👋

Thanks for reporting ! I'm sorry: I wasn't able to reproduce your error... I noticed you changed the options for MAXENT without including it in your allModels: did the error the same with and without MAXENT ?

Could you share:

Thanks a lot ! Hélène