4

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

enter image description 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?

alancalvitti
  • 15,143
  • 3
  • 27
  • 92
  • 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 Answers2

5

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:

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
4

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]

Mathematica graphic

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

(*

7387756019/10816427520

*)

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

Mathematica graphic

Alternatively,

Total[data[[All,2]]]

(*

25593/15914

*)
s0rce
  • 9,632
  • 4
  • 45
  • 78