Skip to contents

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:

  1. Validating input types and completeness

  2. Handling NA values and SpatRaster conversion

  3. Checking for prediction variability

  4. 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)