# Area or NIntegrate curves defined by points?

Is there a convenient method to compute the AUC (Area Under the Curve) metric that quantifies a Receiver Operating Characteristic (ROC) like shown here?

The data used to build the ROC are just pairs of real values in [0,1]:

{{1, 1}, {15/64, 30/73}, {5/64, 21/218}, {3/64, 5/109}, {1/64, 3/
109}, {0, 2/109}, {0, 1/109}}


Although this data can be closed to form a polytope, documentation for Area states that polytope edges need to be unit-length, which is not the case in general.

Is there a convenient way to pass this data to NIntegrate, and if so what integration methods (eg, Trapezoid vs ..) and interpolation are appropriate for the ROC AUC problem?

-
You have 2 points with the same x-axis value, 0. Is this desired? – s0rce Oct 18 '12 at 20:59
@s0rce, the map from a threshold parameter to (sensitivity, 1-specificity) need not be injective. Potentially this is an interesting issue as to whether it would affect integration (or duplicate points should be removed - but that introduces a different problem since often the optimal threshold is what is sought) – alancalvitti Oct 18 '12 at 23:58

## 2 Answers

Perhaps just

data = {{1, 1}, {15/64, 30/73}, {5/64, 21/218}, {3/64, 5/109}, {1/64, 3/109}, {0, 2/109},
N@Total[Partition[Sort@data,2,1] /.{{x1_, y1_}, {x2_, y2_}} -> (x2 - x1) (y1 + (y2 - y1)/2)]

(*
-> 0.583492
*)


made by adding up rectangles and triangles:

-
Reminds me... #[[2, 1]] + (#[[2, 2]] - #[[2, 1]])/ 2 ought to be #[[1, 2]] + (#[[2, 2]] - #[[1, 2]])/ 2. – J. M. Oct 18 '12 at 21:56
@J.M. shifted to a more readable form – Dr. belisarius Oct 19 '12 at 1:44
Why not use the form in your other answer? :) – J. M. Oct 19 '12 at 11:20
@J.M. I'm too lazy to visit a link to learn how I calculated this sum before. There are surely a zillion ways to sum these products – Dr. belisarius Oct 19 '12 at 11:28

Since your last data point had the same x-axis value I just dropped it for this answer, I wasn't sure if it was real.

data = {{1, 1}, {15/64, 30/73}, {5/64, 21/218}, {3/64, 5/109}, {1/64,
3/109}, {0, 2/109}, {0, 1/109}};
ListLinePlot[data]


dataint = Interpolation[Most@data, InterpolationOrder -> 2]
NIntegrate[dataint[x], {x, 0, 1}]

(*

7387756019/10816427520

*)

Plot[NIntegrate[dataint[x], {x, 0, y}], {y, 0, 1}]


Alternatively,

Total[data[[All,2]]]

(*

25593/15914

*)

-
By looking at the plot provided in the question, I think repeated x values are allowed – Dr. belisarius Oct 18 '12 at 21:10