Predict suitability and Mahalanobis distance from a nicheR ellipsoid
Source:R/predict.R
predict.nicheR_ellipsoid.RdComputes Mahalanobis distance and optional suitability values from a
nicheR_ellipsoid for either (1) environmental samples provided as a
data.frame or matrix, (2) a SpatRaster stack of
predictors, or (3) virtual samples drawn in environmental space when
newdata = NULL.
Usage
# S3 method for class 'nicheR_ellipsoid'
predict(
object,
newdata,
adjust_truncation_level = NULL,
include_suitability = TRUE,
suitability_truncated = FALSE,
include_mahalanobis = TRUE,
mahalanobis_truncated = FALSE,
keep_data = NULL,
verbose = TRUE
)Arguments
- object
A
nicheR_ellipsoidobject produced bybuild_ellipsoid.- newdata
Environmental predictors. One of:
A
SpatRaster(or legacyrasterclasses, coerced automatically).A
data.frame,tibble, ormatrixwith columns named to matchobject$var_names.
- adjust_truncation_level
Optional numeric confidence level in
(0, 1)to overrideobject$clwhen computing truncated outputs. Default isNULL(uses the level stored inobject).- include_suitability
Logical. If
TRUE(default), returns suitability values (\(\exp(-0.5 D^2)\)).- suitability_truncated
Logical. If
TRUE, returns a truncated suitability layer where values outside the chi-square contour are set to0. Default isFALSE.- include_mahalanobis
Logical. If
TRUE(default), returns Mahalanobis distance (\(D^2\)).- mahalanobis_truncated
Logical. If
TRUE, returns a truncated Mahalanobis layer where values outside the chi-square contour are set toNA. Default isFALSE.- keep_data
Logical or
NULL. IfTRUE, includes the original predictors in the output. Default isNULL:FALSEforSpatRasterinput,TRUEfor tabular input.- verbose
Logical. If
TRUE(default), prints progress messages.
Value
If newdata is a SpatRaster, returns a SpatRaster with
the requested prediction layers (and optionally the original predictor
layers if keep_data = TRUE).
If newdata is tabular, returns a data.frame of class
"nicheR_prediction" with the requested prediction columns (and
optionally the original predictor columns if keep_data = TRUE).
Details
Suitability is computed as \(\exp(-0.5 D^2)\), where \(D^2\) is the
squared Mahalanobis distance from the niche centroid. Truncated outputs use
a chi-square cutoff based on the ellipsoid confidence level (cl).
For tabular inputs, coordinate columns (e.g., x, y,
lon, lat) are detected and retained when
keep_data = TRUE. Extra non-predictor columns are ignored.