
Calculate Partial and complete Area Under the Curve (AUC) Metrics
Source:R/auc_metrics.R
auc_metrics.Rd
Computes partial AUC ratios between model predictions and random curves at a specified threshold, with options for sampling and iterations. Handles both numeric vectors and SpatRaster inputs.
Usage
auc_metrics(
test_prediction,
prediction,
threshold = 5,
sample_percentage = 50,
iterations = 500,
compute_full_auc = TRUE
)
Arguments
- test_prediction
Numeric vector of test prediction values (e.g., model outputs)
- prediction
Numeric vector or SpatRaster object containing prediction values
- threshold
Percentage threshold for partial AUC calculation (default = 5)
- sample_percentage
Percentage of test data to sample (default = 50)
- iterations
Number of iterations for estimating bootstrap statistics (default = 500)
- compute_full_auc
Logical. If TRUE, the complete AUC values will be computed
Value
A list containing:
If input has no variability: List with NA values for AUC metrics
Otherwise: Matrix of AUC results.
Details
Partial ROC is calculated following Peterson et al. (2008; doi:10.1016/j.ecolmodel.2007.11.008 ). The function calculates partial AUC ratios by:
Validating input types and completeness
Handling NA values and SpatRaster conversion
Checking for prediction variability
Computing AUC metrics using optimized C++ code
When prediction values have no variability (all equal), the function returns NA values with a warning.
References
Peterson, A.T. et al. (2008) Rethinking receiver operating characteristic analysis applications in ecological niche modeling. Ecol. Modell., 213, 63–72.
Examples
# With numeric vectors
test_data <- rnorm(100)
pred_data <- rnorm(100)
result <- fpROC::auc_metrics(test_prediction = test_data, prediction = pred_data)
# With SpatRaster
library(terra)
#> terra 1.8.54
r <- terra::rast(ncol=10, nrow=10)
values(r) <- rnorm(terra::ncell(r))
result <- fpROC::auc_metrics(test_prediction = test_data, prediction = r)