Skip to content

Commit

Permalink
update of biomod2 arguments the in vignette 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalavi committed Jan 28, 2024
1 parent 5ffdeac commit 6cc3fe2
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 153 deletions.
24 changes: 14 additions & 10 deletions inst/doc/tutorial_2.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## ----echo=FALSE---------------------------------------------------------------
options(scipen = 10)

## ---- fig.height=5, fig.width=7.2, warning=FALSE, message=FALSE---------------
## ----fig.height=5, fig.width=7.2, warning=FALSE, message=FALSE----------------
library(sf) # working with spatial vector data
library(terra) # working with spatial raster data
library(tmap) # plotting maps
Expand All @@ -13,16 +13,16 @@ rasters <- system.file("extdata/au/", package = "blockCV") |>
terra::rast()


## ---- fig.height=4.5, fig.width=7.1-------------------------------------------
## ----fig.height=4.5, fig.width=7.1--------------------------------------------
# load species presence-asence data and convert to sf
points <- read.csv(system.file("extdata/", "species.csv", package = "blockCV"))
head(points)


## ---- fig.height=4.5, fig.width=7.1-------------------------------------------
## ----fig.height=4.5, fig.width=7.1--------------------------------------------
pa_data <- sf::st_as_sf(points, coords = c("x", "y"), crs = 7845)

## ---- fig.height=4.5, fig.width=7.1-------------------------------------------
## ----fig.height=4.5, fig.width=7.1--------------------------------------------
tm_shape(rasters[[1]]) +
tm_raster(legend.show = FALSE, n = 30, palette = gray.colors(10)) +
tm_shape(pa_data) +
Expand All @@ -33,7 +33,7 @@ tm_shape(rasters[[1]]) +
library(blockCV)


## ---- fig.keep='all', warning=FALSE, message=FALSE, fig.height=5, fig.width=7----
## ----fig.keep='all', warning=FALSE, message=FALSE, fig.height=5, fig.width=7----
scv1 <- cv_spatial(
x = pa_data,
column = "occ", # the response column (binary or multi-class)
Expand Down Expand Up @@ -81,7 +81,7 @@ cv_plot(
num_plots = c(1, 10, 100) # three of folds to plot
)

## ---- eval=FALSE--------------------------------------------------------------
## ----eval=FALSE---------------------------------------------------------------
# # loading the libraries
# library(randomForest)
# library(precrec)
Expand Down Expand Up @@ -120,7 +120,7 @@ cv_plot(
read.csv("../man/figures/roc_rf.csv")


## ---- eval=FALSE, fig.height=3.7, fig.width=7---------------------------------
## ----eval=FALSE, fig.height=3.7, fig.width=7----------------------------------
# library(ggplot2)
#
# autoplot(precrec_obj)
Expand All @@ -144,21 +144,25 @@ read.csv("../man/figures/roc_rf.csv")
# # 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.
# # 3. Defining Models Options; using default options here. You can use your own settting here.
# biomod_options <- BIOMOD_ModelingOptions()
#
# # 4. Model fitting
# biomod_model_out <- BIOMOD_Modeling(biomod_data,
# models = c('GLM','MARS','GBM'),
# bm.options = biomod_options,
# data.split.table = spatial_cv_folds,
# CV.strategy = "user.defined",
# CV.user.table = spatial_cv_folds,
# var.import = 0,
# metric.eval = c('ROC'),
# do.full.models = TRUE)
#

## ---- eval=FALSE--------------------------------------------------------------
## ----eval=FALSE---------------------------------------------------------------
# # 5. Model evaluation
# biomod_model_eval <- get_evaluations(biomod_model_out)
# biomod_model_eval[c("run", "algo", "metric.eval", "calibration", "validation")]
Expand Down
10 changes: 7 additions & 3 deletions inst/doc/tutorial_2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ autoplot(precrec_obj)

### Using `blockCV` in `biomod2` package

Package [`biomod2`](https://CRAN.R-project.org/package=biomod2) (Thuiller et al., 2017) is a commonly used platform for modelling species distributions in an ensemble framework. In this example, we show how to use `blockCV` folds in `biomod2`. In this example, the `data.split.table` generated by `cv_spatial` is used to evaluate three modelling methods implemented in `biomod2`. The `data.split.table` can be generated by both `cv_spatial` and `cv_cluster` functions and it is stored as `biomod_table` in their output objects.
Package [`biomod2`](https://CRAN.R-project.org/package=biomod2) (Thuiller et al., 2017) is a commonly used platform for modelling species distributions in an ensemble framework. In this example, we show how to use `blockCV` folds in `biomod2`. In this example, the folds generated by `cv_spatial` is used to evaluate three modelling methods implemented in `biomod2`. The `CV.user.table` can be generated by both `cv_spatial` and `cv_cluster` functions and it is stored as `biomod_table` in their output objects (note: in the older versions of the `biomod2` package, the argument `data.split.table` was used for external CV folds. This has now changed to `CV.user.table` that also requires `CV.strategy = "user.defined"` and new column names. See the example below).

```{r eval=FALSE}
# loading the library
Expand All @@ -236,15 +236,19 @@ biomod_data <- BIOMOD_FormatingData(resp.var = pa_data$occ,
# 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.
# 3. Defining Models Options; using default options here. You can use your own settting here.
biomod_options <- BIOMOD_ModelingOptions()
# 4. Model fitting
biomod_model_out <- BIOMOD_Modeling(biomod_data,
models = c('GLM','MARS','GBM'),
bm.options = biomod_options,
data.split.table = spatial_cv_folds,
CV.strategy = "user.defined",
CV.user.table = spatial_cv_folds,
var.import = 0,
metric.eval = c('ROC'),
do.full.models = TRUE)
Expand Down
282 changes: 145 additions & 137 deletions inst/doc/tutorial_2.html

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions vignettes/tutorial_2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ autoplot(precrec_obj)

### Using `blockCV` in `biomod2` package

Package [`biomod2`](https://CRAN.R-project.org/package=biomod2) (Thuiller et al., 2017) is a commonly used platform for modelling species distributions in an ensemble framework. In this example, we show how to use `blockCV` folds in `biomod2`. In this example, the `data.split.table` generated by `cv_spatial` is used to evaluate three modelling methods implemented in `biomod2`. The `data.split.table` can be generated by both `cv_spatial` and `cv_cluster` functions and it is stored as `biomod_table` in their output objects.
Package [`biomod2`](https://CRAN.R-project.org/package=biomod2) (Thuiller et al., 2017) is a commonly used platform for modelling species distributions in an ensemble framework. In this example, we show how to use `blockCV` folds in `biomod2`. In this example, the folds generated by `cv_spatial` is used to evaluate three modelling methods implemented in `biomod2`. The `CV.user.table` can be generated by both `cv_spatial` and `cv_cluster` functions and it is stored as `biomod_table` in their output objects (note: in the older versions of the `biomod2` package, the argument `data.split.table` was used for external CV folds. This has now changed to `CV.user.table` that also requires `CV.strategy = "user.defined"` and new column names. See the example below).

```{r eval=FALSE}
# loading the library
Expand All @@ -236,15 +236,19 @@ biomod_data <- BIOMOD_FormatingData(resp.var = pa_data$occ,
# 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.
# 3. Defining Models Options; using default options here. You can use your own settting here.
biomod_options <- BIOMOD_ModelingOptions()
# 4. Model fitting
biomod_model_out <- BIOMOD_Modeling(biomod_data,
models = c('GLM','MARS','GBM'),
bm.options = biomod_options,
data.split.table = spatial_cv_folds,
CV.strategy = "user.defined",
CV.user.table = spatial_cv_folds,
var.import = 0,
metric.eval = c('ROC'),
do.full.models = TRUE)
Expand Down

0 comments on commit 6cc3fe2

Please sign in to comment.