trap_roc | R Documentation |
Computes the area under a curve using the trapezoidal rule of numerical integration.
trap_roc(x, y)
x |
Numeric vector (arma::vec) of x-coordinates (should be sorted in increasing order) |
y |
Numeric vector (arma::vec) of y-coordinates corresponding to x-coordinates |
The trapezoidal rule approximates the area under the curve by dividing it into trapezoids. For each pair of adjacent points (x[i], y[i]) and (x[i+1], y[i+1]), it calculates the area of the trapezoid formed. The total AUC is the sum of all these individual trapezoid areas.
Special cases: - Returns 0 if there are fewer than 2 points (no area can be calculated) - Handles both increasing and decreasing x values (though typically x should be increasing for ROC curves)
A numerical value representing the computed area under the curve as a double precision value.
integrate
for R's built-in integration functions
# R code example:
x <- c(0, 0.5, 1, 1.5, 2)
y <- c(0, 0.7, 0.9, 0.95, 1)
trap_roc(x, y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.