
Extract model predictions at presence and absence/background points
Source:R/extract.R
extract_predictions.RdBuilds the observation/prediction table that all evaluation metrics are computed from. Points are re-projected to each raster's CRS when needed.
Usage
extract_predictions(
models,
presence,
absence,
coords = NULL,
points_crs = "EPSG:4326",
na_action = c("common", "per_model"),
rescale = TRUE,
crs = NULL
)Arguments
- models
Model predictions: a terra::SpatRaster (one layer per model), file path(s) to rasters, or a named list of these.
- presence
Presence points (data.frame, CSV path,
sforSpatVector).- absence
Absence points or, for presence-only data, background / pseudo-absence points (same formats as
presence).- coords
Optional names of the x/longitude and y/latitude columns when points are tabular. Detected automatically if
NULL.- points_crs
CRS of tabular coordinates (default WGS84,
"EPSG:4326").- na_action
How to handle points that fall on
NAcells."common"(default) drops a point for all models if it isNAin any model, so every model is evaluated on exactly the same points (a fair comparison)."per_model"keeps points independently for each model (this reproduces the original 2021 script).- rescale
Bring predictions to the 0-1 scale. Algorithms write their output on different scales (0-1, 0-100, 0-1000); the scale of each model is recognised from its largest value, and models on 0-100 or 0-1000 are divided by 100 or 1000, with a message.
FALSEkeeps the values and warns when they are not on the 0-1 scale. Models whose scale cannot be recognised (negative values or above 1000, e.g. raw Maxent output) are left as they are, with a warning.- crs
Deprecated: the former name of
points_crs, still accepted with a warning.
Value
A data.frame with columns obs (1 = presence, 0 = absence) and one
column of predicted values per model. Attribute "n_dropped" holds the
number of points removed because of NA predictions, and "scales"
the recognised scale of each model and what it was divided by.
Examples
sim <- simulate_enm_data(seed = 1)
tab <- extract_predictions(sim$models, sim$presence, sim$absence)
head(tab)
#> obs Maxent_LQ Maxent_H_rm4 GLM RandomForest BIOCLIM Random
#> 1 1 0.2979312 0.4337935 0.6526770 0.1466617 0.5514160 0.20221411
#> 2 1 0.9796628 0.8719577 1.0000000 0.4620941 1.0000000 0.08439184
#> 3 1 0.4368495 0.4779061 0.7857962 0.2294358 0.9026098 0.05459043
#> 4 1 0.9883641 0.9499223 1.0000000 0.7200858 0.9610085 0.91074815
#> 5 1 0.8972504 0.5913426 0.9432208 0.5846884 0.9695164 0.67316815
#> 6 1 0.9173116 0.8838167 0.8973709 0.4702934 1.0000000 0.34535315
#> GBM
#> 1 0.4934240
#> 2 0.8953851
#> 3 0.6478384
#> 4 0.8499142
#> 5 1.0000000
#> 6 0.6642130