Learn R Programming

caretSDM (version 1.1.0.1)

add_scenarios: Add scenarios to sdm_area

Description

This function includes scenarios in the sdm_area object.

Usage

add_scenarios(sa, scen = NULL, scenarios_names = NULL, pred_as_scen = TRUE,
                     variables_selected = NULL, stationary = NULL)

set_scenarios_names(i, scenarios_names = NULL)

scenarios_names(i)

get_scenarios_data(i)

select_scenarios(i, scenarios_names = NULL)

Value

add_scenarios returns the input sdm_area or input_sdm object with a new slot called scenarios with scen data as a list, where each slot of the list holds a scenario and each scenario is a sf object. set_scenarios_names sets new names for scenarios in sdm_area/input_sdm

object. scenarios_names returns scenarios' names. get_scenarios_data retrieves scenarios data as a list of sf objects. select_scenarios selects scenarios from sdm_area/input_sdm object.

Arguments

sa

A sdm_area or input_sdm object.

scen

RasterStack, SpatRaster or stars object. If NULL adds predictors as a scenario.

scenarios_names

Character vector with names of scenarios.

pred_as_scen

Logical. If TRUE adds the current predictors as a scenario.

variables_selected

Character vector with variables names in scen to be used as variables. If NULL adds all variables.

stationary

Names of variables from sa that should be used in scenarios as stationary variables.

i

A sdm_area or input_sdm object.

Author

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

Details

The function add_scenarios adds scenarios to the sdm_area or input_sdm object. If scen has variables that are not present as predictors the function will use only variables present in both objects. stationary variables are those that don't change through the scenarios. It is useful for hidrological variables in fish habitat modeling, for example (see examples below). When adding multiple scenarios in multiple runs, the function will always add a new "current" scenario. To avoid that, set pred_as_scen = FALSE.

See Also

sdm_area input_sdm

Examples

Run this code
# Create sdm_area object:
sa <- sdm_area(parana, cell_size = 100000, crs = 6933)

# Include predictors:
sa <- add_predictors(sa, bioc)

# Include scenarios:
sa <- add_scenarios(sa, scen[1:2]) |> select_predictors(c("bio1", "bio12"))

# Set scenarios names:
sa <- set_scenarios_names(sa, scenarios_names = c("future_1", "future_2",
                                                  "current"))
scenarios_names(sa)

# Get scenarios data:
scenarios_grid <- get_scenarios_data(sa)
scenarios_grid

# Select scenarios:
sa <- select_scenarios(sa, scenarios_names = c("future_1"))

# Setting stationary variables in scenarios:
sa <- sdm_area(rivs[c(1:200),], cell_size = 100000, crs = 6933, lines_as_sdm_area = TRUE) |>
  add_predictors(bioc) |>
  add_scenarios(scen, stationary = c("LENGTH_KM", "DIST_DN_KM"))


Run the code above in your browser using DataLab