Why Calculate ROC Area From Coordinates?
A receiver operating characteristic (ROC) curve summarizes how a binary classifier’s sensitivity and false-positive rate change as its decision threshold changes. Its area under the curve, or AUC, reduces that curve to a single measure of ranking performance. Earlier material on ROC coordinates establishes how each operating point is calculated. Here the focus is how to find the area when the ordered coordinates are given.
For a plotted ROC point, the horizontal coordinate is the false-positive rate and the vertical coordinate is the true-positive rate. AUC is therefore an area in the unit square. The calculation must follow the curve from left to right: the false-positive rate must be nondecreasing, even if the original coordinate list was presented in another order.
Each coordinate lies between 0 and 1. In the intended order, \(x_{j+1}\geq x_j\) and \(y_{j+1}\geq y_j\): lowering a threshold can add predicted positives, but should not reduce either cumulative rate. The coordinates need not increase strictly. A repeated false-positive rate creates a vertical segment, and a repeated true-positive rate creates a horizontal segment.
The Trapezoidal Calculation
For a segment joining \((x_j,y_j)\) to \((x_{j+1},y_{j+1})\), its width is \(x_{j+1}-x_j\). Its two endpoint heights are \(y_j\) and \(y_{j+1}\). Thus its area is the width multiplied by the average of those heights. Add the areas of all consecutive segments:
The hat indicates an area calculated from the supplied empirical coordinates. The formula assumes that consecutive points are joined by straight lines for this calculation. It is not a formula for the area under every possible curve between the points unless the curve is linear on each such interval.
Two cases are especially useful for checking work. If \(x_{j+1}=x_j\), the segment is vertical and its width is zero, so its area is zero. If \(y_{j+1}=y_j\), the segment is horizontal and its area is a rectangle with area \((x_{j+1}-x_j)y_j\). The general formula gives both results directly; no separate approximation is needed.
Worked Example: A Curve With Sloping, Vertical, and Horizontal Segments
A hypothetical validation set produces the ordered ROC coordinates \((0,0)\), \((0.15,0.40)\), \((0.15,0.70)\), \((0.50,0.70)\), \((0.75,0.90)\), and \((1,1)\). Calculate the trapezoidal AUC. Name the method and identify the segment that contributes no area.
Method. Apply the trapezoidal formula to every consecutive pair, keeping the false-positive rate as the horizontal coordinate. The segment from \((0.15,0.40)\) to \((0.15,0.70)\) is vertical, so its width is zero.
From \((0,0)\) to \((0.15,0.40)\), the width is \(0.15-0=0.15\), and the average height is \((0+0.40)/2=0.20\). Its area is \(0.15(0.20)=0.0300\).
From \((0.15,0.40)\) to \((0.15,0.70)\), the width is \(0.15-0.15=0\). Its area is \(0(0.40+0.70)/2=0\).
From \((0.15,0.70)\) to \((0.50,0.70)\), the width is \(0.50-0.15=0.35\). The height is constant at \(0.70\), so the area is \(0.35(0.70)=0.2450\).
From \((0.50,0.70)\) to \((0.75,0.90)\), the width is \(0.25\), and the average height is \((0.70+0.90)/2=0.80\). The area is \(0.25(0.80)=0.2000\).
From \((0.75,0.90)\) to \((1,1)\), the width is \(1-0.75=0.25\), and the average height is \((0.90+1)/2=0.95\). The area is \(0.25(0.95)=0.2375\).
Adding the areas gives \(0.0300+0+0.2450+0.2000+0.2375=0.7125\). The result is between 0 and 1, as an area within the unit square must be. The common mistake this method avoids is assigning positive area to the vertical segment: its horizontal width is zero.
Calculating From Threshold Steps
ROC coordinates may be supplied directly, or they may be constructed as the threshold is lowered through ordered cases. For \(P\) positive cases and \(N\) negative cases, each additional positive case increases the true-positive rate by \(1/P\), and each additional negative case increases the false-positive rate by \(1/N\). These increments follow from the definitions: the rates are the cumulative counts of correctly identified positives divided by \(P\), and false positives divided by \(N\).
If one case enters at a time, each step changes one coordinate while holding the other fixed. A positive case creates a vertical step; a negative case creates a horizontal step. Applying the trapezoidal formula then gives zero area on vertical steps and rectangular area on horizontal steps. The example below uses that structure.
Worked Example: Building Coordinates From an Ordered Sequence
A hypothetical validation set contains four positive cases and five negative cases. As the threshold is lowered, cases enter in this order: positive, negative, positive, negative, positive, negative, negative, negative, positive. Calculate the ROC coordinates and trapezoidal AUC. Name the method and check the result.
Method. Begin at \((0,0)\). Each positive case adds \(1/4=0.25\) to the true-positive rate; each negative case adds \(1/5=0.20\) to the false-positive rate. Then add the areas of the horizontal and vertical steps.
After the first positive case the point is \((0,0.25)\). After the first negative case it is \((0.20,0.25)\). After the second positive case it is \((0.20,0.50)\), and after the second negative case it is \((0.40,0.50)\).
After the third positive case the point is \((0.40,0.75)\). The next three negative cases give \((0.60,0.75)\), \((0.80,0.75)\), and \((1,0.75)\). The final positive case gives the endpoint \((1,1)\). Thus the full ordered list, including the start, is \((0,0)\), \((0,0.25)\), \((0.20,0.25)\), \((0.20,0.50)\), \((0.40,0.50)\), \((0.40,0.75)\), \((0.60,0.75)\), \((0.80,0.75)\), \((1,0.75)\), and \((1,1)\).
The first vertical segment has area zero. The horizontal segment at height \(0.25\), from false-positive rate 0 to 0.20, has area \(0.20(0.25)=0.05\). The next vertical segment has area zero. The horizontal segment at height \(0.50\), from 0.20 to 0.40, has area \(0.20(0.50)=0.10\). The next vertical segment has area zero.
The three remaining horizontal segments are each \(0.20\) wide at height \(0.75\), so each has area \(0.20(0.75)=0.15\). The final vertical segment has area zero. Therefore the AUC is \(0.05+0.10+0.15+0.15+0.15=0.60\). As a check, the total horizontal width is \(0.20+0.20+0.20+0.20+0.20=1\), and every contribution is nonnegative, so an area of 0.60 is feasible. The common mistake avoided here is treating vertical increases in sensitivity as additional horizontal width.
Irregular Coordinates and Efficient Checks
For nonuniformly spaced coordinates, calculate each width separately. Do not use one common width for the entire curve unless the data actually have equal spacing. Likewise, use the average of the two endpoint heights for a sloping segment, not just the height at its left or right endpoint.
Worked Example: Unequal Widths and a Horizontal Segment
A hypothetical classifier has ordered ROC coordinates \((0,0)\), \((0.10,0.40)\), \((0.40,0.60)\), \((0.80,0.60)\), and \((1,1)\). Calculate the trapezoidal AUC. Explain why using the same width for each segment would be incorrect.
Method. Calculate each consecutive trapezoid using its actual change in false-positive rate. The four widths are \(0.10\), \(0.30\), \(0.40\), and \(0.20\), so they are not equal.
For the first segment, the average height is \((0+0.40)/2=0.20\), giving area \(0.10(0.20)=0.0200\). For the second segment, the average height is \((0.40+0.60)/2=0.50\), giving area \(0.30(0.50)=0.1500\).
The third segment is horizontal at height \(0.60\), so its area is \(0.40(0.60)=0.2400\). For the final segment, the average height is \((0.60+1)/2=0.80\), giving area \(0.20(0.80)=0.1600\).
The sum is \(0.0200+0.1500+0.2400+0.1600=0.5700\), so the AUC is \(0.57\). The segment widths sum to \(0.10+0.30+0.40+0.20=1\), which checks that the curve runs from false-positive rate 0 to 1. Assigning one repeated width to all four segments would disregard the given coordinates and produce an incorrect area.
Common Calculation Traps
The most reliable exam approach is to write the coordinates in order and show the contribution from each segment. A compact table can help keep the width, endpoint heights, and area distinct.
| Segment type | Coordinate condition | Area contribution |
|---|---|---|
| Vertical | \(x_{j+1}=x_j\) | Zero |
| Horizontal | \(y_{j+1}=y_j\) | \((x_{j+1}-x_j)y_j\) |
| Sloping | Both coordinates change | \((x_{j+1}-x_j)(y_j+y_{j+1})/2\) |
A frequent trap is to reverse the axes and use the change in sensitivity as the width. That calculates an area with the wrong horizontal dimension. Another is to treat every segment as a rectangle at its final height. For a rising straight segment, that generally overstates the area; for a falling segment, it generally understates it. The trapezoidal rule uses the average endpoint height, which handles both cases.
If coordinates are listed from right to left, reorder them by increasing false-positive rate before summing. Check that the first and last coordinates are the ROC endpoints when the full curve is intended, that neither rate decreases as the threshold is lowered, and that the total horizontal width is 1. A result outside \([0,1]\) signals a calculation or coordinate error for a curve inside the unit square. The trapezoidal calculation is aligned with the SOA Exam PA (Predictive Analytics) syllabus.
Check Your Understanding
For each problem, calculate the area from the stated ordered coordinates or threshold sequence. Use the trapezoidal rule and check whether vertical or horizontal segments have been handled correctly.
- A ROC curve has coordinates \((0,0)\), \((0.20,0.50)\), \((0.60,0.50)\), and \((1,1)\). Calculate its trapezoidal AUC. (Answer: \(0.55\))
- A set has two positive and three negative cases. As the threshold is lowered, the cases enter in this order: negative, positive, negative, positive, negative. Calculate the trapezoidal AUC. (Answer: \(0.5000\))
- Calculate the AUC for \((0,0)\), \((0.25,0.40)\), \((0.25,0.80)\), \((0.75,0.80)\), and \((1,1)\). (Answer: \(0.6750\))
- Calculate the AUC for \((0,0)\), \((0.10,0.60)\), \((0.50,0.60)\), and \((1,1)\). (Answer: \(0.6700\))
- A coordinate list is supplied from right to left as \((1,1)\), \((0.60,0.80)\), \((0.20,0.40)\), and \((0,0)\). Reorder it and calculate the AUC. (Answer: \(0.6400\))