4
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ You have 2 points with the same x-axis value, 0. Is this desired? $\endgroup$
    – s0rce
    Commented Oct 18, 2012 at 20:59
  • $\begingroup$ @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) $\endgroup$ Commented Oct 18, 2012 at 23:58

2 Answers 2

5
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ Reminds me... #[[2, 1]] + (#[[2, 2]] - #[[2, 1]])/ 2 ought to be #[[1, 2]] + (#[[2, 2]] - #[[1, 2]])/ 2. $\endgroup$ Commented Oct 18, 2012 at 21:56
  • $\begingroup$ @J.M. shifted to a more readable form $\endgroup$ Commented Oct 19, 2012 at 1:44
  • $\begingroup$ Why not use the form in your other answer? :) $\endgroup$ Commented Oct 19, 2012 at 11:20
  • $\begingroup$ @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 $\endgroup$ Commented Oct 19, 2012 at 11:28
4
$\begingroup$

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

*)
$\endgroup$
1
  • $\begingroup$ By looking at the plot provided in the question, I think repeated x values are allowed $\endgroup$ Commented Oct 18, 2012 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.