ConsBiol-unibern / SDMtune

Performs Variables selection and model tuning for Species Distribution Models (SDMs). It provides also several utilities to display results.
https://consbiol-unibern.github.io/SDMtune/
Other
24 stars 8 forks source link

modelReport fails if response_curves = TRUE or jk=TRUE #9

Closed DevinALyons closed 3 years ago

DevinALyons commented 3 years ago

If I set response_curves = TRUE or jk=TRUE, modelReport fails. I get:

plotting univariate response curves...Quitting from lines 84-99 (modelReport.Rmd) Error in apply(pdata, 1, function(rr) !any(apply(ndata, 1, function(r) identical(r, : dim(X) must have a positive length

OR

It seems that something is wrong with data that is being passed to maxnet.

This happens with my data, but it also happens if I try to use the package's example. I didn't previously have this problem. I've recently updated SDMtune and several related packages (maxnet, dismo), though.

sgvignali commented 3 years ago

Could you please provide a short script to reproduce the error using the package dataset?

DevinALyons commented 3 years ago

I literally just cut and pasted the example from the function documentation:

files <- list.files(path = file.path(system.file(package = "dismo"), "ex"), pattern = "grd", full.names = TRUE) predictors <- raster::stack(files)

p_coords <- virtualSp$presence bg_coords <- virtualSp$background

data <- prepareSWD(species = "Virtual species", p = p_coords, a = bg_coords, env = predictors, categorical = "biome")

datasets <- trainValTest(data, test = 0.2, only_presence = TRUE) train <- datasets[[1]] test <- datasets[[2]]

model <- train(method = "Maxnet", data = train, fc = "lq")

modelReport(model, type = "cloglog", folder = "my_folder", test = test, response_curves = TRUE, only_presence = TRUE, jk = TRUE, env = predictors, permut = 2)

and got this:

Plotting univariate response curves...Quitting from lines 84-99 (modelReport.Rmd) Error in apply(pdata, 1, function(rr) !any(apply(ndata, 1, function(r) identical(r, : dim(X) must have a positive length

sgvignali commented 3 years ago

I don't get any error, could you please post the output of the following command: sessionInfo()

Which packages did you load? Maybe you loaded one package that overwrites a SDMtune function?

DevinALyons commented 3 years ago

Hmm. Very strange, perhaps you are correct. Here is the output:

R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

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

other attached packages: [1] matrixStats_0.57.0 ecospat_3.1 gbm_2.1.8 ape_5.4-1 ade4_1.7-16 maptools_1.0-2
[7] blockCV_2.1.1 maxnet_0.1.3 kableExtra_1.3.1 enmSdm_0.5.1.7 dplyr_1.0.2 ENMeval_0.3.1
[13] dismo_1.3-3 raster_3.4-5 sp_1.4-4 SDMtune_1.1.3

loaded via a namespace (and not attached): [1] backports_1.2.0 Hmisc_4.4-1 rasterVis_0.49 plyr_1.8.6 splines_4.0.3
[6] gstat_2.0-6 ggplot2_3.3.2 TH.data_1.0-10 digest_0.6.27 foreach_1.5.1
[11] htmltools_0.5.0 earth_5.3.0 fansi_0.4.1 magrittr_2.0.1 checkmate_2.0.0
[16] tensor_1.5 cluster_2.1.0 doParallel_1.0.16 recipes_0.1.15 gower_0.2.2
[21] xts_0.12.1 sandwich_3.0-0 CircStats_0.2-6 prettyunits_1.1.1 jpeg_0.1-8.1
[26] colorspace_2.0-0 rvest_0.3.6 xfun_0.19 rgdal_1.5-18 crayon_1.3.4
[31] hexbin_1.28.1 spatstat_1.64-1 spatstat.data_1.5-2 survival_3.2-7 zoo_1.8-8
[36] iterators_1.0.13 glue_1.4.2 polyclip_1.10-0 PresenceAbsence_1.1.9 gtable_0.3.0
[41] ipred_0.9-9 webshot_0.5.2 MatrixModels_0.4-1 shape_1.4.5 rms_6.0-1
[46] abind_1.4-5 SparseM_1.78 scales_1.1.1 mvtnorm_1.1-1 DBI_1.1.0
[51] Rcpp_1.0.5 plotROC_2.2.1 plotrix_3.7-8 viridisLite_0.3.0 progress_1.2.2
[56] htmlTable_2.1.0 units_0.6-7 foreign_0.8-80 Formula_1.2-4 intervals_0.15.2
[61] stats4_4.0.3 lava_1.6.8.1 prodlim_2019.11.13 glmnet_4.0-2 ecodist_2.0.7
[66] httr_1.4.2 htmlwidgets_1.5.2 FNN_1.1.3 RColorBrewer_1.1-2 ellipsis_0.3.1
[71] farver_2.0.3 pkgconfig_2.0.3 reshape_0.8.8 nnet_7.3-14 deldir_0.2-3
[76] caret_6.0-86 labeling_0.4.2 tidyselect_1.1.0 rlang_0.4.9 reshape2_1.4.4
[81] munsell_0.5.0 TeachingDemos_2.12 tools_4.0.3 cli_2.2.0 generics_0.1.0
[86] adehabitatHR_0.4.18 evaluate_0.14 stringr_1.4.0 yaml_2.2.1 goftest_1.2-2
[91] ModelMetrics_1.2.2.2 knitr_1.30 purrr_0.3.4 randomForest_4.6-14 ncdf4_1.17
[96] nlme_3.1-149 quantreg_5.75 xml2_1.3.2 biomod2_3.4.6 compiler_4.0.3
[101] rstudioapi_0.13 png_0.1-7 e1071_1.7-4 spatstat.utils_1.17-0 spacetime_1.2-3
[106] tibble_3.0.4 stringi_1.5.3 highr_0.8 plotmo_3.6.0 rgeos_0.5-5
[111] lattice_0.20-41 poibin_1.5 Matrix_1.2-18 classInt_0.4-3 vegan_2.5-6
[116] permute_0.9-5 vctrs_0.3.5 pillar_1.4.7 lifecycle_0.2.0 cowplot_1.1.0
[121] data.table_1.13.2 conquer_1.0.2 R6_2.5.0 latticeExtra_0.6-29 KernSmooth_2.23-17
[126] gridExtra_2.3 codetools_0.2-16 polspline_1.1.19 assertthat_0.2.1 boot_1.3-25
[131] MASS_7.3-53 gtools_3.8.2 withr_2.3.0 multcomp_1.4-15 adehabitatMA_0.3.14
[136] mgcv_1.8-33 parallel_4.0.3 hms_0.5.3 grid_4.0.3 rpart_4.1-15
[141] timeDate_3043.102 adehabitatLT_0.3.25 tidyr_1.1.2 class_7.3-17 rmarkdown_2.5
[146] automap_1.0-14 mda_0.5-2 sf_0.9-6 pROC_1.16.2 snowfall_1.84-6.1
[151] lubridate_1.7.9.2 base64enc_0.1-3 tinytex_0.27

sgvignali commented 3 years ago

Try to restart your R session and load only SDMtune

DevinALyons commented 3 years ago

Yeah, I did that as well. Same result.

sgvignali commented 3 years ago

But your sessionInfo() output is full of loaded packages

DevinALyons commented 3 years ago

Yes, the sessionInfo was from the attempt I made before shutting down, starting a new session and loading only SDMtune.

sgvignali commented 3 years ago

Could you please send the output after you load only SDMtune?

DevinALyons commented 3 years ago

version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

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

other attached packages: [1] kableExtra_1.3.1 SDMtune_1.1.3

loaded via a namespace (and not attached): [1] tinytex_0.27 shape_1.4.5 tidyselect_1.1.0 xfun_0.19 purrr_0.3.4 splines_4.0.3 lattice_0.20-41
[8] colorspace_2.0-0 vctrs_0.3.5 generics_0.1.0 htmltools_0.5.0 viridisLite_0.3.0 yaml_2.2.1 survival_3.2-7
[15] rlang_0.4.9 pillar_1.4.7 glue_1.4.2 sp_1.4-4 plyr_1.8.6 foreach_1.5.1 lifecycle_0.2.0
[22] stringr_1.4.0 munsell_0.5.0 gtable_0.3.0 rvest_0.3.6 raster_3.4-5 codetools_0.2-16 maxnet_0.1.3
[29] evaluate_0.14 labeling_0.4.2 knitr_1.30 fansi_0.4.1 highr_0.8 Rcpp_1.0.5 scales_1.1.1
[36] webshot_0.5.2 farver_2.0.3 ggplot2_3.3.2 digest_0.6.27 stringi_1.5.3 dplyr_1.0.2 dismo_1.3-3
[43] grid_4.0.3 rgdal_1.5-18 cli_2.2.0 tools_4.0.3 magrittr_2.0.1 glmnet_4.0-2 tibble_3.0.4
[50] crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1 Matrix_1.2-18 xml2_1.3.2 assertthat_0.2.1 rmarkdown_2.5
[57] httr_1.4.2 rstudioapi_0.13 iterators_1.0.13 plotROC_2.2.1 R6_2.5.0 compiler_4.0.3

sgvignali commented 3 years ago

It looks like you still have some other loaded packages. A clean environment would look like this:

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

other attached packages: [1] SDMtune_1.1.3

loaded via a namespace (and not attached): [1] Rcpp_1.0.5 lattice_0.20-41 codetools_0.2-16 crayon_1.3.4 grid_4.0.2
[6] R6_2.4.1 lifecycle_0.2.0 gtable_0.3.0 magrittr_1.5 scales_1.1.1
[11] pillar_1.4.6 ggplot2_3.3.2 rlang_0.4.7 rstudioapi_0.11 raster_3.3-13
[16] sp_1.4-2 vctrs_0.3.4 ellipsis_0.3.1 tools_4.0.2 glue_1.4.2
[21] munsell_0.5.0 compiler_4.0.2 pkgconfig_2.0.3 dismo_1.3-3 colorspace_1.4-1 [26] tibble_3.0.3

DevinALyons commented 3 years ago

It seems that some of the extra packages (e.g. maxnet, glmnet) are loaded when I run the example. Does this not happen for you?

So, before loading SDMtune I have:

R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

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

loaded via a namespace (and not attached): [1] compiler_4.0.3 tools_4.0.3 tinytex_0.27 xfun_0.19

After loading SDMtune I have:

R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

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

other attached packages: [1] SDMtune_1.1.3

loaded via a namespace (and not attached): [1] Rcpp_1.0.5 rstudioapi_0.13 raster_3.4-5 magrittr_2.0.1 tidyselect_1.1.0 munsell_0.5.0 colorspace_2.0-0 [8] lattice_0.20-41 R6_2.5.0 rlang_0.4.9 dplyr_1.0.2 tools_4.0.3 grid_4.0.3 gtable_0.3.0
[15] xfun_0.19 dismo_1.3-3 tinytex_0.27 ellipsis_0.3.1 tibble_3.0.4 lifecycle_0.2.0 crayon_1.3.4
[22] purrr_0.3.4 ggplot2_3.3.2 vctrs_0.3.5 codetools_0.2-16 glue_1.4.2 sp_1.4-4 compiler_4.0.3
[29] pillar_1.4.7 generics_0.1.0 scales_1.1.1 pkgconfig_2.0.3

Then, once I run the example I have: R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C LC_TIME=English_Canada.1252

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

other attached packages: [1] kableExtra_1.3.1 SDMtune_1.1.3

loaded via a namespace (and not attached): [1] tinytex_0.27 shape_1.4.5 tidyselect_1.1.0 xfun_0.19 purrr_0.3.4 splines_4.0.3 lattice_0.20-41 colorspace_2.0-0 vctrs_0.3.5
[10] generics_0.1.0 htmltools_0.5.0 viridisLite_0.3.0 yaml_2.2.1 survival_3.2-7 rlang_0.4.9 pillar_1.4.7 glue_1.4.2 sp_1.4-4
[19] plyr_1.8.6 foreach_1.5.1 lifecycle_0.2.0 stringr_1.4.0 munsell_0.5.0 gtable_0.3.0 rvest_0.3.6 raster_3.4-5 codetools_0.2-16 [28] maxnet_0.1.3 evaluate_0.14 labeling_0.4.2 knitr_1.30 fansi_0.4.1 highr_0.8 Rcpp_1.0.5 scales_1.1.1 webshot_0.5.2
[37] farver_2.0.3 ggplot2_3.3.2 digest_0.6.27 stringi_1.5.3 dplyr_1.0.2 dismo_1.3-3 grid_4.0.3 rgdal_1.5-18 cli_2.2.0
[46] tools_4.0.3 magrittr_2.0.1 glmnet_4.0-2 tibble_3.0.4 crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1 Matrix_1.2-18 xml2_1.3.2
[55] assertthat_0.2.1 rmarkdown_2.5 httr_1.4.2 rstudioapi_0.13 iterators_1.0.13 plotROC_2.2.1 R6_2.5.0 compiler_4.0.3

DevinALyons commented 3 years ago

I just solved it. The problem was with maxnet. At some point recently I'd installed the development version version, which changes addsamplestobackground=TRUE by default. I just reverted to the CRAN version and modelReport works fine. I guess this is a heads up that the maxnet default is going to change and that you'll have to work around that when the new version goes onto CRAN.

sgvignali commented 3 years ago

Ok, thanks, I will adjust the code but for the moment I have to rely on the CRAN version.