View source: R/forward_simulation.R
forward_simulation | R Documentation |
Simulation of species dispersal to identify areas that could be accessed and colonized based on environmental suitability and user-defined dispersal parameters.
forward_simulation(suit_layer, data = NULL, suit_forward = NULL,
barriers = NULL, starting_proportion = 0.5,
proportion_to_disperse = 1, sampling_rule = "random",
dispersal_kernel = "normal",
kernel_spread = 1, max_dispersers = 4,
dispersal_events = 25, replicates = 10,
threshold = 5, set_seed = 1,
out_format = "GTiff", output_directory,
overwrite = FALSE)
suit_layer |
(character) name of (local) raster layer containing values of suitability for the species of interest in the study region over which the simulation will run. The name of the layer name should include parent directory if needed. |
data |
(optional) data.frame containing geographic coordinates of occurrences of the species of interest. Columns must be: "species", "longitude", "latitude", in that order. |
suit_forward |
(optional) name of (local) raster layer(s) containing
values of suitability for the species of interest in the study region over
which the simulation will run. If more than one, layer names must be
ordered from first to last scenario. These layers must have the same
extent, resolution, number of cells, and projection than |
barriers |
(optional) SpatRaster representing dispersal barriers for
the species. This layer must have the same extent and projection than
|
starting_proportion |
(numeric) proportion of |
proportion_to_disperse |
(numeric) proportion of colonized cells from which dispersers will start a new dispersal event; default = 1. |
sampling_rule |
(character) rule to be used to sample a
|
dispersal_kernel |
(character) dispersal kernel (dispersal function) used to simulate the movement of the species. Options are: "normal", "log_normal". Default = "normal". |
kernel_spread |
(numeric) standard deviation for the
|
max_dispersers |
(numeric) maximum number of dispersers that depart from each colonized pixel. Depending on suitability this number will automatically decrease in areas with low suitability values. Default = 4. |
dispersal_events |
(numeric) number of dispersal events to happen per scenario. A vector of multiple values could be used to define different dispersal events for distinct scenarios. See details; default = 25. |
replicates |
(numeric) number of times to repeat the simulation
per dispersal event, depending on |
threshold |
(numeric) percentage to be considered when excluding accessed or colonized cells with lower values. Default = 5. |
set_seed |
(numeric) a seed to be used when sampling |
out_format |
(character) format of raster layers to be written in
|
output_directory |
(character) name of the output directory to be created in which all results will be written. |
overwrite |
(logical) whether or not to overwrite the
|
Defining a vector of multiple values in dispersal_events
could be
useful when distinct scenarios represent different periods of time, or if
a reduced number of events need to be simulated in the last scenario.
If a vector of values is defined in dispersal_events
, the length of
this vector must match the length of suit_forward
+ 1, otherwise,
the first element in dispersal_events
will be used and a warning
message will be printed.
A list containing:
occurrences found in suitable areas in the scenario where the simulation started.
all scenarios considered for the simulation
a list with the parameters used during the simulation
a SpatRaster with values representing the number of the dispersal event when areas where accessed
a SpatRaster with values representing the number of the dispersal event when areas where colonized
if defined, the SpatRaster used in barriers
, else NULL
The complete set of results derived from data preparation and the simulation
is written in output_directory
. These results include the ones
mentioned above (except barriers), plus:
if needed, a folder containing results from correcting suitability layer(s)
with barriers
other raster layers representing statistics of accessibility: mean and variance
a figure representing accessed and colonized areas per dispersal events, and the occurrences used for simulation
a simple report from the simulation process
The number of dispersal events in results is continuous among scenarios. If
10 dispersal events are defined and multiple scenarios exist in
suit_layers
, the first dispersal event in the second scenario will be
number 11.
# data
data("records", package = "grinnell")
suitability <- system.file("extdata/suitability.tif", package = "grinnell")
# simulation current
f_s <- forward_simulation(suit_layer = suitability, data = records,
dispersal_kernel = "normal",
kernel_spread = 2, max_dispersers = 2,
dispersal_events = 15, replicates = 3,
output_directory = file.path(tempdir(), "eg_fsim"))
# simulation current and future
suitf <- system.file("extdata/suitability_fut.tif", package = "grinnell")
f_s1 <- forward_simulation(suit_layer = suitability, data = records,
suit_forward = suitf, dispersal_kernel = "normal",
kernel_spread = 2, max_dispersers = 2,
dispersal_events = 15, replicates = 3,
output_directory = file.path(tempdir(), "eg_fsim1"))
# simulation current and future using dispersal barriers
barrier <- terra::rast(system.file("extdata/barrier.tif",
package = "grinnell"))
f_s2 <- forward_simulation(suit_layer = suitability, data = records,
suit_forward = suitf, barriers = barrier,
dispersal_kernel = "normal",
kernel_spread = 2, max_dispersers = 2,
dispersal_events = 15, replicates = 3,
output_directory = file.path(tempdir(), "eg_fsim2"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.