View source: R/prediction_changes.R
| prediction_changes | R Documentation |
Compute changes of suitable areas in other scenarios (single scenario / GCM)
prediction_changes(current_predictions, new_predictions,
predicted_to = "future", fitted_models = NULL,
consensus = "mean", user_threshold = NULL,
force_resample = FALSE, gain_color = "#009E73",
loss_color = "#D55E00", stable_suitable = "#0072B2",
stable_unsuitable = "grey", write_results = FALSE,
output_dir = NULL, overwrite = FALSE,
write_bin_models = FALSE)
current_predictions |
(SpatRaster) A |
new_predictions |
(SpatRaster) A |
predicted_to |
(character) a string specifying whether |
fitted_models |
an object of class |
consensus |
(character) the consensus metric stored in |
user_threshold |
(numeric) an optional threshold for binarizing predictions.
Default is |
force_resample |
(logical) whether to force rasters to have the same
extent and resolution. Default is |
gain_color |
(character) color used to represent gains. Default is "#009E73" (teal green). |
loss_color |
(character) color used to represent losses. Default is "#D55E00" (orange-red). |
stable_suitable |
(character) color used for representing areas that remain suitable across scenarios. Default is "#0072B2" (oxford blue). |
stable_unsuitable |
(character) color used for representing areas that remain unsuitable across scenarios. Default is "grey". |
write_results |
(logical) whether to save the results to disk. Default is FALSE. |
output_dir |
(character) directory path where results will be saved.
Only relevant if |
overwrite |
(logical) whether to overwrite SpatRasters if they already
exist. Only applicable if |
write_bin_models |
(logical) whether to write the binarized models for
each scenario to the disk. Only applicable if |
When projecting a niche model to different temporal scenarios (past or future), species’ areas can be classified into three categories relative to the current baseline: gain, loss and stability. The interpretation of these categories depends on the temporal direction of the projection. When projecting to future scenarios:
Gain: Areas that are currently unsuitable become suitable in the future.
Loss: Areas that are currently suitable become unsuitable in the future.
Stability: Areas that retain their current classification in the future, whether suitable or unsuitable.
When projecting to past scenarios:
Gain: Areas that were unsuitable in the past are now suitable in the present.
Loss: Areas that were suitable in the past are now unsuitable in the present.
Stability: Areas that retain their past classification in the present, whether suitable or unsuitable.
A SpatRaster showing the areas of gain, loss and stability.
# Import an example of fitted models (output of fit_selected())
data("fitted_model_maxnet", package = "kuenm2")
# Import current variables for prediction
present_var <- terra::rast(system.file("extdata", "Current_variables.tif",
package = "kuenm2"))
# Import variables for a single future scenario for prediction
future_var <- terra::rast(system.file("extdata",
"wc2.1_10m_bioc_ACCESS-CM2_ssp585_2081-2100.tif",
package = "kuenm2"))
# Rename variables to match the variable names used in the fitted models
names(future_var) <- sub("bio0", "bio", names(future_var))
names(future_var) <- sub("bio", "bio_", names(future_var))
# Append the static soil variable to the future variables
future_var <- c(future_var, present_var$SoilType)
# Predict under present and future conditions
p_present <- predict_selected(models = fitted_model_maxnet,
new_variables = present_var)
p_future <- predict_selected(models = fitted_model_maxnet,
new_variables = future_var)
# Compute changes between scenarios
p_changes <- prediction_changes(current_predictions = p_present$General_consensus$mean,
new_predictions = p_future$General_consensus$mean,
fitted_models = fitted_model_maxnet,
predicted_to = "future")
# Plot result
terra::plot(p_changes)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.