| predict,bam-method | R Documentation | 
predicts species' distribution under suitability changes
## 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 )
| 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 declered 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. Posible 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 | 
## Not run: 
# Load R packages
library(bam)
library(raster)
# rm(list = ls())
# Read raster model for Lepus californicus
model_path <- system.file("extdata/Lepus_californicus_cont.tif",
                          package = "bam")
model <- raster::raster(model_path)
# Convert model to sparse
sparse_mod <- bam::model2sparse(model = model)
# Compute adjacency matrix
adj_mod <- bam::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 <- bam::occs2sparse(modelsparse = sparse_mod,
                                occs = occs_lep_cal)
# Run the bam (sdm) simultation for 100 time steps
smd_lep_cal <- bam::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 = "bam")
niche_mods_stack <- raster::stack(list.files(layers_path,
                                             pattern = ".tif$",
                                             full.names = TRUE)) > 0.1
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
new_preds <- predict(object = smd_lep_cal,
                     niche_layers = niche_mods_stack,
                     nsteps_vec = c(10,10),
                     animate=TRUE,
                     filename="/home/l916o895/Desktop/animacion_01.html",
                     fmt="HTML")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.