R/bm_RangeSize.R
bm_RangeSize.Rd
This function allows to calculate the absolute number of locations (pixels) lost, stable and gained, as well as the corresponding relative proportions, between two (or more) binary projections of (ensemble) species distribution models (which can represent new time scales or environmental scenarios for example).
bm_RangeSize(proj.current, proj.future, ordinal = FALSE)
# S4 method for class 'data.frame,data.frame'
bm_RangeSize(proj.current, proj.future, ordinal = FALSE)
# S4 method for class 'SpatRaster,SpatRaster'
bm_RangeSize(proj.current, proj.future, ordinal = FALSE)
a data.frame
, RasterLayer
or SpatRaster
object containing the initial binary projection(s)
of the (ensemble) species distribution model(s)
a data.frame
, RasterLayer
or SpatRaster
object containing the final binary projection(s)
of the (ensemble) species distribution model(s)
a logical
indicating whether or not the projections should be considered as ordinal data
A list
containing two objects :
a data.frame
containing the summary of range change for each
comparison
Loss
: number of pixels predicted to be lost
Stable_Abs
: number of pixels not currently occupied and not predicted to be
Stable_Pres
: number of pixels currently occupied and predicted to remain
occupied
Gain
: number of pixels predicted to be gained
PercLoss
: percentage of pixels currently occupied and predicted to be lost
(Loss / (Loss + Stable_Pres)
)
PercGain
: percentage of pixels predicted to be gained compare to the
number of pixels currently occupied (Gain / (Loss + Stable_Pres)
)
SpeciesRangeChange
: percentage of pixels predicted to change (loss or gain)
compare to the number of pixels currently occupied (PercGain - PercLoss
)
CurrentRangeSize
: number of pixels currently occupied
FutureRangeSize0Disp
: number of pixels predicted to be occupied, assuming
no migration
FutureRangeSize1Disp
: number of pixels predicted to be occupied, assuming
migration
an object in the same form than the input data (proj.current
and
proj.future
) and containing a value for each point/pixel of each comparison among :
-2
: predicted to be lost
-1
: predicted to remain occupied
0
: predicted to remain unoccupied
1
: predicted to be gained
an object in the same form than the input data (proj.current
and
proj.future
) and containing a value for each point/pixel of each comparison obtain with :
Future - 2* Current
for binary data
Future - Current
for nonbinary
Note that this function is only relevant to compare binary projections, made on the
same area with the same resolution.
Comparison between proj.current
and proj.future
depends
on the number of projection in both objects:
| proj.current
| proj.future
| Comparison |
| ————————- | ———————- | ——————– |
| 1 projection (e.g. data.frame with 1 column, SpatRaster with 1 layer) | 1 projection (e.g. data.frame with 1 column, SpatRaster with 1 layer) | comparison of both projection (e.g. current vs future conditions for the same model ; current vs current condition for two different models) |
| n
projections (e.g. data.frame with n column, SpatRaster with n layer) | n
projections (e.g. data.frame with n column, SpatRaster with n layer) | comparing projection i
in proj.current
to projection i
in proj.future
(e.g. comparing current vs future condition for n models) |
| 1
projection (e.g. data.frame with 1 column, SpatRaster with 1 layer) | n
projections (e.g. data.frame with n column, SpatRaster with n layer) | comparing projection in proj.current
to each projection in proj.future
(e.g. comparing current vs n different future condition (e.g. climate change scenario) for 1 model) |
For binary data,Diff.By.Pixel
object is obtained by applying the simple following formula :
$$proj.future - 2 * proj.current$$
For non binary data, Diff.By.Pixel
object is obtained by rescaling the two projection to a 0 to 1 scale
and applying the simple following formula :
$$proj.future - proj.current$$
BIOMOD_Projection
, BIOMOD_EnsembleForecasting
,
bm_PlotRangeSize
Other Secondary functions:
bm_BinaryTransformation()
,
bm_CrossValidation()
,
bm_FindOptimStat()
,
bm_MakeFormula()
,
bm_ModelingOptions()
,
bm_PlotEvalBoxplot()
,
bm_PlotEvalMean()
,
bm_PlotRangeSize()
,
bm_PlotResponseCurves()
,
bm_PlotVarImpBoxplot()
,
bm_PseudoAbsences()
,
bm_RunModelsLoop()
,
bm_SRE()
,
bm_SampleBinaryVector()
,
bm_SampleFactorLevels()
,
bm_Tuning()
,
bm_VariablesImportance()
library(terra)
# Load species occurrences (6 species available)
data(DataSpecies)
head(DataSpecies)
# Select the name of the studied species
myRespName <- 'GuloGulo'
# Get corresponding presence/absence data
myResp <- as.numeric(DataSpecies[, myRespName])
# Get corresponding XY coordinates
myRespXY <- DataSpecies[, c('X_WGS84', 'Y_WGS84')]
# Load environmental variables extracted from BIOCLIM (bio_3, bio_4, bio_7, bio_11 & bio_12)
data(bioclim_current)
myExpl <- terra::rast(bioclim_current)
DONTSHOW({
myExtent <- terra::ext(0,30,45,70)
myExpl <- terra::crop(myExpl, myExtent)
})
# --------------------------------------------------------------- #
file.out <- paste0(myRespName, "/", myRespName, ".AllModels.models.out")
if (file.exists(file.out)) {
myBiomodModelOut <- get(load(file.out))
} else {
# Format Data with true absences
myBiomodData <- BIOMOD_FormatingData(resp.name = myRespName,
resp.var = myResp,
resp.xy = myRespXY,
expl.var = myExpl)
# Model single models
myBiomodModelOut <- BIOMOD_Modeling(bm.format = myBiomodData,
modeling.id = 'AllModels',
models = c('RF', 'GLM'),
CV.strategy = 'random',
CV.nb.rep = 2,
CV.perc = 0.8,
OPT.strategy = 'bigboss',
metric.eval = c('TSS', 'ROC'),
var.import = 3,
seed.val = 42)
}
models.proj <- get_built_models(myBiomodModelOut, algo = "RF")
# Project single models
myBiomodProj <- BIOMOD_Projection(bm.mod = myBiomodModelOut,
proj.name = 'CurrentRangeSize',
new.env = myExpl,
models.chosen = models.proj,
metric.binary = 'all',
build.clamping.mask = TRUE)
# --------------------------------------------------------------- #
# Load environmental variables extracted from BIOCLIM (bio_3, bio_4, bio_7, bio_11 & bio_12)
data(bioclim_future)
myExplFuture <- terra::rast(bioclim_future)
DONTSHOW({
myExtent <- terra::ext(0,30,45,70)
myExplFuture <- terra::crop(myExplFuture, myExtent)
})
# Project onto future conditions
myBiomodProjectionFuture <- BIOMOD_Projection(bm.mod = myBiomodModelOut,
proj.name = 'FutureRangeSize',
new.env = myExplFuture,
models.chosen = models.proj,
metric.binary = 'TSS')
# Load current and future binary projections
CurrentProj <- get_predictions(myBiomodProj,
metric.binary = "TSS",
model.as.col = TRUE)
FutureProj <- get_predictions(myBiomodProjectionFuture,
metric.binary = "TSS",
model.as.col = TRUE)
# Compute differences
myBiomodRangeSize <- bm_RangeSize(proj.current = CurrentProj, proj.future = FutureProj)
myBiomodRangeSize$Compt.By.Models
plot(myBiomodRangeSize$Diff.By.Pixel)