predict,bam-method {bamm}R Documentation

Predict method of the package bamm.

Description

predicts species' distribution under suitability changes

Usage

## S4 method for signature 'bam'
predict(
  object,
  niche_layers,
  nbgs_vec = NULL,
  nsteps_vec,
  stochastic_dispersal = FALSE,
  disp_prop2_suitability = TRUE,
  disper_prop = 0.5,
  animate = FALSE,
  period_names = NULL,
  fmt = "GIF",
  filename,
  bg_color = "#F6F2E5",
  suit_color = "#0076BE",
  occupied_color = "#03C33F",
  png_keyword = "sdm_sim",
  ani.width = 1200,
  ani.height = 1200,
  ani.res = 300
)

Arguments

object

a of class bam.

niche_layers

A raster or RasterStack with the niche models for each time period

nbgs_vec

A vector with the number of neighbors for the adjacency matrices

nsteps_vec

Number of simulation steps for each time period.

stochastic_dispersal

Logical. If dispersal depends on a probability of visiting neighbor cells (Moore neighborhood).

disp_prop2_suitability

Logical. If probability of dispersal is proportional to the suitability of reachable cells. The proportional value must be declared in the parameter 'disper_prop'.

disper_prop

Probability of dispersal to reachable cells.

animate

Logical. If TRUE a dispersal animation on climate change scenarios will be created

period_names

Character vector with the names of periods that will be animated. Default NULL.

fmt

Animation format. Possible values are GIF and HTML

filename

File name.

bg_color

Color for unsuitable pixels. Default "#F6F2E5".

suit_color

Color for suitable pixels. Default "#0076BE".

occupied_color

Color for occupied pixels. Default "#03C33F".

png_keyword

A keyword name for the png images generated by the function

ani.width

Animation width unit in px

ani.height

Animation height unit in px

ani.res

Animation resolution unit in px

Value

A RasterStack of predictions of dispersal dynamics as a function of environmental change scenarios.

Author(s)

Luis Osorio-Olvera & Jorge SoberĂ³n

Examples

# rm(list = ls())
# Read raster model for Lepus californicus
model_path <- system.file("extdata/Lepus_californicus_cont.tif",
                          package = "bamm")
model <- raster::raster(model_path)
# Convert model to sparse
sparse_mod <- bamm::model2sparse(model = model,threshold=0.1)
# Compute adjacency matrix
adj_mod <- bamm::adj_mat(sparse_mod,ngbs=1)

# Initial points to start dispersal process

occs_lep_cal <- data.frame(longitude = c(-115.10417,
                                         -104.90417),
                           latitude = c(29.61846,
                                        29.81846))
# Convert to sparse the initial points
occs_sparse <- bamm::occs2sparse(modelsparse = sparse_mod,
                                occs = occs_lep_cal)

# Run the bam (sdm) simultation for 100 time steps
smd_lep_cal <- bamm::sdm_sim(set_A = sparse_mod,
                             set_M = adj_mod,
                             initial_points = occs_sparse,
                             nsteps = 10)
#----------------------------------------------------------------------------
# Predict species' distribution under suitability change
# scenarios (could be climate chage scenarios).
#----------------------------------------------------------------------------

# Read suitability layers (two suitability change scenarios)
layers_path <- system.file("extdata/suit_change",
                           package = "bamm")
niche_mods_stack <- raster::stack(list.files(layers_path,
                                             pattern = ".tif$",
                                             full.names = TRUE))
raster::plot(niche_mods_stack)
# Predict
new_preds <- predict(object = smd_lep_cal,
                     niche_layers = niche_mods_stack,
                     nsteps_vec = c(50,100))

# Generate the dispersal animation for time period 1 and 2

if(requireNamespace("animation")){
ani_prd <- tempfile(pattern = "prediction_",fileext = ".gif")
#new_preds <- predict(object = smd_lep_cal,
#                      niche_layers = niche_mods_stack,
#                      nsteps_vec = c(10,10),
#                      animate=TRUE,
#                      filename=ani_prd,
#                    fmt="GIF")

}


[Package bamm version 0.5.0 Index]