
Rescale a raster stack to reflect posterior beta coefficients from a brms SDM
Source:R/RescaleRastersBayes.R
RescaleRasters_bayes.RdBayesian analogue of RescaleRasters() for use with bayesianSDM() output.
Each predictor raster is centred and scaled using training-data moments, then
multiplied by the absolute value of its posterior beta coefficient, so that
the resulting layers are on a common scale weighted by ecological importance.
Because brms uses autoscale = TRUE by default for regularising priors
(horseshoe, normal, student), the posterior betas are already on a
standardised scale and are directly comparable across predictors - no
additional correction is needed beyond what RescaleRasters() applies to
glmnet output.
Usage
RescaleRasters_bayes(
model,
predictors,
training_data,
pred_mat,
beta_summary = c("mean", "median", "Q2.5", "Q97.5"),
include_uncertainty = FALSE,
uncertainty_wt = 1
)Arguments
- model
A
brmsfitobject frombayesianSDM().- predictors
A
SpatRasterstack. Should be the$Predictorselement frombayesianSDM()output (i.e. already PCA-rotated ifpca_predictorswasTRUE).- training_data
An
sfobject. The$TrainDataelement frombayesianSDM()output. Used to compute per-variable mean and SD for centring/scaling the raster.- pred_mat
A data frame or matrix. The
$PredictMatrixelement frombayesianSDM()output. Column names must match environmental predictor names (GP coordinate columnsgp_x/gp_yare ignored automatically).- beta_summary
Character. Which posterior summary to use as the beta weight. One of
"mean","median","Q2.5","Q97.5". Defaults to"mean".- include_uncertainty
Logical. Whether to append a layer encoding posterior uncertainty of the linear predictor. Defaults to
FALSE.- uncertainty_wt
Numeric. Weight applied to the uncertainty layer relative to the maximum environmental layer range, analogous to
coord_wtinEnvironmentalBasedSample(). Only used wheninclude_uncertainty = TRUE. Defaults to1.
Value
A list with three elements:
RescaledPredictorsSpatRasterof rescaled, beta-weighted predictor layers. Pass this aspred_rescaletoEnvironmentalBasedSample().BetaCoefficientsData frame of posterior summaries for all fixed effects (columns:
Variable,Estimate(mean),Est.Error(SD),Q2.5,Q97.5,BetaWeight(the value actually used for scaling)). Intercept and GP parameters are excluded.UncertaintyLayerSpatRasterof propagated posterior SD, orNULLifinclude_uncertainty = FALSE.
Posterior summary choices
The beta_summary argument controls which posterior summary statistic is
used as the point-estimate beta weight:
"mean"Posterior mean. Minimum MSE estimator; default and recommended for most use cases.
"median"Posterior median. More robust when horseshoe priors produce heavy-tailed marginals for near-zero coefficients.
"Q2.5"/"Q97.5"Credible interval bounds. Useful for sensitivity analysis (e.g. conservative lower-bound weighting).
Uncertainty layer
When include_uncertainty = TRUE an additional raster layer is appended
whose values are the posterior SD of the linear predictor at each cell,
propagated through all environmental betas. This encodes where the model is
most uncertain about environmental conditions,
See also
RescaleRasters() for the glmnet equivalent,
bayesianSDM(), EnvironmentalBasedSample()