Skip to content

Commit

Permalink
biomod2 from 4.2-4 to 4.2-5
Browse files Browse the repository at this point in the history
Change BIOMOD_ModelingOptions to bm_ModelingOptions
  • Loading branch information
MayaGueguen committed Apr 30, 2024
1 parent 6cc3fe2 commit 1e27734
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 160 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Suggests:
rmarkdown,
testthat (>= 3.0.0),
covr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
Config/testthat/edition: 3
LinkingTo:
Expand Down
2 changes: 1 addition & 1 deletion R/cv_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ cv_cluster <- function(
train_test_table[i, which(cl %in% names(countrain))] <- countrain
train_test_table[i, clen + which(cl %in% names(countest))] <- countest
}
if(biomod2){ # creating a biomod2 data.split.table for validation
if(biomod2){ # creating a biomod2 CV.user.table for validation
colm <- paste0("RUN", i)
biomod_table[,colm] <- FALSE
biomod_table[train_set, colm] <- TRUE
Expand Down
6 changes: 3 additions & 3 deletions R/cv_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#' This argument is necessary if you choose the 'predefined' selection.
#' @param deg_to_metre integer. The conversion rate of metres to degree. See the details section for more information.
#' @param biomod2 logical. Creates a matrix of folds that can be directly used in the \pkg{biomod2} package as
#' a \emph{data.split.table} for cross-validation.
#' a \emph{CV.user.table} for cross-validation.
#' @param offset two number between 0 and 1 to shift blocks by that proportion of block size.
#' This option only works when \code{size} is provided.
#' @param extend numeric; This parameter specifies the percentage by which the map's extent is
Expand All @@ -76,7 +76,7 @@
#'
#'
#' @seealso \code{\link{cv_buffer}} and \code{\link{cv_cluster}}; \code{\link{cv_spatial_autocor}} and \code{\link{cv_block_size}} for selecting block size
#' @seealso For \emph{data.split.table} see \code{\link[biomod2]{BIOMOD_cv}} in \pkg{biomod2} package
#' @seealso For \emph{CV.user.table} see \code{\link[biomod2]{BIOMOD_Modeling}} in \pkg{biomod2} package
#'
#' @references Bahn, V., & McGill, B. J. (2012). Testing the predictive performance of distribution models. Oikos, 122(3), 321-331.
#'
Expand Down Expand Up @@ -369,7 +369,7 @@ cv_spatial <- function(
train_test_table[p, which(cl %in% names(countrain))] <- countrain
train_test_table[p, clen + which(cl %in% names(countest))] <- countest
}
if(biomod2){ # creating a biomod2 data.split.table for validation
if(biomod2){ # creating a biomod2 CV.user.table for validation
colm <- paste0("RUN", p)
biomod_table[, colm] <- FALSE
biomod_table[train_set, colm] <- TRUE
Expand Down
44 changes: 22 additions & 22 deletions inst/doc/tutorial_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ scv1 <- cv_spatial(
progress = FALSE, # turn off progress bar
biomod2 = TRUE, # also create folds for biomod2
raster_colors = terrain.colors(10, rev = TRUE) # options from cv_plot for a better colour contrast
)
)


## -----------------------------------------------------------------------------
Expand Down Expand Up @@ -85,22 +85,22 @@ cv_plot(
# # loading the libraries
# library(randomForest)
# library(precrec)
#
#
# # extract the raster values for the species points as a dataframe
# model_data <- terra::extract(rasters, pa_data, df = TRUE, ID = FALSE)
# # adding species column to the dataframe
# model_data$occ <- as.factor(pa_data$occ)
# head(model_data)
#
#
# # extract the fold indices from buffering object
# # created in the previous section
# # the folds_list works for all four blocking strategies
# folds <- scv2$folds_list
#
#
# # create a data.frame to store the prediction of each fold (record)
# test_table <- pa_data
# test_table$preds <- NA
#
#
# for(k in seq_len(length(folds))){
# # extracting the training and testing indices
# # this way works with folds_list list (but not folds_ids)
Expand All @@ -109,67 +109,67 @@ cv_plot(
# rf <- randomForest(occ ~ ., model_data[trainSet, ], ntree = 500) # model fitting on training set
# test_table$preds[testSet] <- predict(rf, model_data[testSet, ], type = "prob")[,2] # predict the test set
# }
#
#
# # calculate Area Under the ROC and PR curves and plot the result
# precrec_obj <- evalmod(scores = test_table$preds, labels = test_table$occ)
# auc(precrec_obj)
#
#

## ----echo=FALSE---------------------------------------------------------------
# to not run the model and reduce run time; result are calculated and loaded
read.csv("../man/figures/roc_rf.csv")
read.csv("../man/figures/roc_rf.csv")


## ----eval=FALSE, fig.height=3.7, fig.width=7----------------------------------
# library(ggplot2)
#
#
# autoplot(precrec_obj)
#
#

## ----eval=FALSE---------------------------------------------------------------
# # loading the library
# library(biomod2)
#
#
# # extract the raster values for the species points as a dataframe
# raster_values <- terra::extract(rasters, pa_data, df = TRUE, ID = FALSE)
#
#
# # 1. Formatting Data
# biomod_data <- BIOMOD_FormatingData(resp.var = pa_data$occ,
# expl.var = raster_values,
# resp.xy = sf::st_coordinates(pa_data),
# resp.name = "occ",
# na.rm = TRUE)
#
# # 2. Defining the folds for data.split.table
#
# # 2. Defining the folds for CV.user.table
# # note that biomod_table should be used here not folds
# # use generated folds from cv_spatial in previous section
# spatial_cv_folds <- scv1$biomod_table
# # the new update of the package biomod2 (v4.2-3 <) requires the names to be as below
# # and the `data.split.table` argument is depricated.
# colnames(spatial_cv_folds) <- paste0("_allData_RUN", 1:ncol(spatial_cv_folds))
#
#
# # 3. Defining Models Options; using default options here. You can use your own settting here.
# biomod_options <- BIOMOD_ModelingOptions()
#
# biomod_options <- bm_ModelingOptions(data.type = "binary",
# strategy = "bigboss")
#
# # 4. Model fitting
# biomod_model_out <- BIOMOD_Modeling(biomod_data,
# models = c('GLM','MARS','GBM'),
# bm.options = biomod_options,
# CV.strategy = "user.defined",
# CV.user.table = spatial_cv_folds,
# OPT.user = biomod_options,
# var.import = 0,
# metric.eval = c('ROC'),
# do.full.models = TRUE)
#
#

## ----eval=FALSE---------------------------------------------------------------
# # 5. Model evaluation
# biomod_model_eval <- get_evaluations(biomod_model_out)
# biomod_model_eval[c("run", "algo", "metric.eval", "calibration", "validation")]
#
#

## ----echo=FALSE---------------------------------------------------------------
# to not run the model and reduce run time; result are calculated and loaded
read.csv("../man/figures/evl_biomod.csv")
read.csv("../man/figures/evl_biomod.csv")


9 changes: 4 additions & 5 deletions inst/doc/tutorial_2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,22 @@ biomod_data <- BIOMOD_FormatingData(resp.var = pa_data$occ,
resp.name = "occ",
na.rm = TRUE)
# 2. Defining the folds for data.split.table
# 2. Defining the folds for CV.user.table
# note that biomod_table should be used here not folds
# use generated folds from cv_spatial in previous section
spatial_cv_folds <- scv1$biomod_table
# the new update of the package biomod2 (v4.2-3 <) requires the names to be as below
# and the `data.split.table` argument is depricated.
colnames(spatial_cv_folds) <- paste0("_allData_RUN", 1:ncol(spatial_cv_folds))
# 3. Defining Models Options; using default options here. You can use your own settting here.
biomod_options <- BIOMOD_ModelingOptions()
biomod_options <- bm_ModelingOptions(data.type = "binary", strategy = "bigboss")
# 4. Model fitting
biomod_model_out <- BIOMOD_Modeling(biomod_data,
models = c('GLM','MARS','GBM'),
bm.options = biomod_options,
CV.strategy = "user.defined",
CV.user.table = spatial_cv_folds,
OPT.user = biomod_options,
var.import = 0,
metric.eval = c('ROC'),
do.full.models = TRUE)
Expand Down Expand Up @@ -276,6 +275,6 @@ The `validation` column shows the result of spatial cross-validation and each RU

- Roberts, D.R., Bahn, V., Ciuti, S., Boyce, M.S., Elith, J., Guillera-Arroita, G., Hauenstein, S., Lahoz-Monfort, J.J., Schröder, B., Thuiller, W., others, 2017. Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography. 40: 913-929.

- Thuiller, W., Georges, D., Engler, R., & Breiner, F. (2017). biomod2: Ensemble Platform for Species Distribution Modeling. R package version 3.3-7. https://CRAN.R-project.org/package=biomod2.
- Thuiller W, Georges D, Guéguen M, Engler R, Breiner F, Lafourcade B, Patin R, Blancheteau H (2024). biomod2: Ensemble Platform for Species Distribution Modeling. R package version 4.2-5. https://CRAN.R-project.org/package=biomod2.

- Valavi R, Elith J, Lahoz-Monfort JJ, Guillera-Arroita G. **blockCV: An R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models**. *Methods Ecol Evol.* 2019; 10:225–232. [doi: 10.1111/2041-210X.13107](https://doi.org/10.1111/2041-210X.13107)
240 changes: 120 additions & 120 deletions inst/doc/tutorial_2.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions man/blockCV.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cv_cluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cv_spatial.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions vignettes/tutorial_2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,22 @@ biomod_data <- BIOMOD_FormatingData(resp.var = pa_data$occ,
resp.name = "occ",
na.rm = TRUE)
# 2. Defining the folds for data.split.table
# 2. Defining the folds for CV.user.table
# note that biomod_table should be used here not folds
# use generated folds from cv_spatial in previous section
spatial_cv_folds <- scv1$biomod_table
# the new update of the package biomod2 (v4.2-3 <) requires the names to be as below
# and the `data.split.table` argument is depricated.
colnames(spatial_cv_folds) <- paste0("_allData_RUN", 1:ncol(spatial_cv_folds))
# 3. Defining Models Options; using default options here. You can use your own settting here.
biomod_options <- BIOMOD_ModelingOptions()
biomod_options <- bm_ModelingOptions(data.type = "binary", strategy = "bigboss")
# 4. Model fitting
biomod_model_out <- BIOMOD_Modeling(biomod_data,
models = c('GLM','MARS','GBM'),
bm.options = biomod_options,
CV.strategy = "user.defined",
CV.user.table = spatial_cv_folds,
OPT.user = biomod_options,
var.import = 0,
metric.eval = c('ROC'),
do.full.models = TRUE)
Expand Down Expand Up @@ -276,6 +275,6 @@ The `validation` column shows the result of spatial cross-validation and each RU

- Roberts, D.R., Bahn, V., Ciuti, S., Boyce, M.S., Elith, J., Guillera-Arroita, G., Hauenstein, S., Lahoz-Monfort, J.J., Schröder, B., Thuiller, W., others, 2017. Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography. 40: 913-929.

- Thuiller, W., Georges, D., Engler, R., & Breiner, F. (2017). biomod2: Ensemble Platform for Species Distribution Modeling. R package version 3.3-7. https://CRAN.R-project.org/package=biomod2.
- Thuiller W, Georges D, Guéguen M, Engler R, Breiner F, Lafourcade B, Patin R, Blancheteau H (2024). biomod2: Ensemble Platform for Species Distribution Modeling. R package version 4.2-5. https://CRAN.R-project.org/package=biomod2.

- Valavi R, Elith J, Lahoz-Monfort JJ, Guillera-Arroita G. **blockCV: An R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models**. *Methods Ecol Evol.* 2019; 10:225–232. [doi: 10.1111/2041-210X.13107](https://doi.org/10.1111/2041-210X.13107)

0 comments on commit 1e27734

Please sign in to comment.