dx_auc_pr: Calculate Area Under the Precision-Recall Curve (AUC-PR)

View source: R/dx_metrics.R

dx_auc_prR Documentation

Calculate Area Under the Precision-Recall Curve (AUC-PR)

Description

This function calculates the Area Under the Curve (AUC) for the Precision-Recall curve using the trapezoidal rule. It ensures proper alignment of precision and recall values by adding a starting point at recall=0 with the first observed precision and an ending point at recall=1 with the last observed precision.

Usage

dx_auc_pr(precision, recall, detail = "full")

Arguments

precision

Numeric vector of precision values corresponding to different thresholds.

recall

Numeric vector of recall values corresponding to different thresholds.

detail

Character string specifying the level of detail in the output: "simple" for just the AUC value, "full" for the AUC value along with confidence intervals.

Details

The function prepares the precision and recall vectors by ensuring they are ordered by increasing recall values. It then calculates the AUC using the trapezoidal rule, which is the sum of areas of trapezoids formed between each consecutive pair of points. The first and last points are added to cover the entire recall range from 0 to 1.

Value

Depending on the detail parameter, returns a single numeric value of AUC or a data frame with the AUC and its confidence intervals.

Examples

# Assuming pr_data is your dataframe with precision and recall columns
dx_obj <- dx(
  data = dx_heart_failure,
  true_varname = "truth",
  pred_varname = "predicted",
  outcome_label = "Heart Attack",
  setthreshold = .3
)
auc_pr <- dx_auc_pr(dx_obj$thresholds$precision, dx_obj$thresholds$sensitivity)
print(auc_pr)

overdodactyl/diagnosticSummary documentation built on Jan. 28, 2024, 10:07 a.m.