Skip to contents

An ensembling method to group different GCMs into one SSP scenario

Usage

gcms_ensembles(i, gcms = NULL)

Arguments

i

A input_sdm object.

gcms

GCM codes in scenarios_names(i) to group scenarios.

Value

A input_sdm object with grouped GCMs.

Author

Luíz Fernando Esser (luizesser@gmail.com) https://luizfesser.wordpress.com

Examples

# Create sdm_area object:
set.seed(1)
sa <- sdm_area(parana, cell_size = 100000, crs = 6933)
#> ! Making grid over study area is an expensive task. Please, be patient!
#>  Using GDAL to make the grid and resample the variables.

# Include predictors:
sa <- add_predictors(sa, bioc)
#> ! Making grid over the study area is an expensive task. Please, be patient!
#>  Using GDAL to make the grid and resample the variables.

# Include scenarios:
sa <- add_scenarios(sa, scen) |> select_predictors(c("bio1", "bio12"))
#> Warning: Some variables in `variables_selected` are not present in `scen`.
#>  Using only variables present in `scen`: bio1, bio4, and bio12

# Create occurrences:
oc <- occurrences_sdm(occ, crs = 6933) |> join_area(sa)
#> Warning: Some records from `occ` do not fall in `pred`.
#>  2 elements from `occ` were excluded.
#>  If this seems too much, check how `occ` and `pred` intersect.

# Create input_sdm:
i <- input_sdm(oc, sa)

# Pseudoabsence generation:
i <- pseudoabsences(i, method="random", n_set = 2)

# Custom trainControl:
ctrl_sdm <- caret::trainControl(method = "boot",
                                number = 1,
                                classProbs = TRUE,
                                returnResamp = "all",
                                summaryFunction = summary_sdm,
                                savePredictions = "all")

# Train models:
i <- train_sdm(i,
               algo = c("naive_bayes"),
               ctrl=ctrl_sdm,
               variables_selected = c("bio1", "bio12")) |>
  suppressWarnings()
#> Loading required package: ggplot2
#> Loading required package: lattice
#> 
#> Attaching package: ‘caret’
#> The following object is masked from ‘package:caretSDM’:
#> 
#>     predictors

# Predict models:
i  <- predict_sdm(i, th=0.8)
#> [1] "Projecting: 1/5"
#> [1] "Projecting: 2/5"
#> [1] "Projecting: 3/5"
#> [1] "Projecting: 4/5"
#> [1] "Projecting: 5/5"
#> [1] "Ensembling..."
#> [1] "ca_ssp245_2090"
#> [1] "Araucaria angustifolia"
#> [1] "ca_ssp585_2090"
#> [1] "Araucaria angustifolia"
#> [1] "mi_ssp245_2090"
#> [1] "Araucaria angustifolia"
#> [1] "mi_ssp585_2090"
#> [1] "Araucaria angustifolia"
#> [1] "current"
#> [1] "Araucaria angustifolia"

#' # Ensemble GCMs:
i <- gcms_ensembles(i, gcms = c("ca", "mi"))
#> New names:
#>  `cell_id` -> `cell_id...1`
#>  `mean_occ_prob` -> `mean_occ_prob...2`
#>  `wmean_AUC` -> `wmean_AUC...3`
#>  `committee_avg` -> `committee_avg...4`
#>  `cell_id` -> `cell_id...5`
#>  `mean_occ_prob` -> `mean_occ_prob...6`
#>  `wmean_AUC` -> `wmean_AUC...7`
#>  `committee_avg` -> `committee_avg...8`
#> New names:
#>  `cell_id` -> `cell_id...1`
#>  `mean_occ_prob` -> `mean_occ_prob...2`
#>  `wmean_AUC` -> `wmean_AUC...3`
#>  `committee_avg` -> `committee_avg...4`
#>  `cell_id` -> `cell_id...5`
#>  `mean_occ_prob` -> `mean_occ_prob...6`
#>  `wmean_AUC` -> `wmean_AUC...7`
#>  `committee_avg` -> `committee_avg...8`
i
#>             caretSDM           
#> ...............................
#> Class                         : input_sdm
#> --------  Occurrences  --------
#> Species Names                 : Araucaria angustifolia 
#> Number of presences           : 418 
#> Pseudoabsence methods         :
#>     Method to obtain PAs      : random 
#>     Number of PA sets         : 2 
#>     Number of PAs in each set : 418 
#> --------  Predictors  ---------
#> Number of Predictors          : 2 
#> Predictors Names              : bio1, bio12 
#> ---------  Scenarios  ---------
#> Number of Scenarios           : 5 
#> Scenarios Names               : ca_ssp245_2090 ca_ssp585_2090 mi_ssp245_2090 mi_ssp585_2090 current 
#> -----------  Models  ----------
#> Algorithms Names              : naive_bayes 
#> Variables Names               : bio1 bio12 
#> Model Validation              :
#>     Method                    : boot 
#>     Number                    : 1 
#>     Metrics                   :
#> $`Araucaria angustifolia`
#>          algo       ROC       TSS Sensitivity Specificity
#> 1 naive_bayes 0.8567781 0.4410403       0.974         0.5
#> 
#> --------  Predictions  --------
#> Ensembles                     :
#>     Scenarios                 : ca_ssp245_2090 ca_ssp585_2090 mi_ssp245_2090 mi_ssp585_2090 current _ssp245_2090 _ssp585_2090 
#>     Methods                   : mean_occ_prob wmean_AUC committee_avg 
#> Thresholds                    :
#>     Method                    : threshold 
#>     Criteria                  : 0.8