Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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 2

up vote 4 down vote accepted

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

share|improve this answer
    
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 –  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 –  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]

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

*)
share|improve this answer
    
By looking at the plot provided in the question, I think repeated x values are allowed –  belisarius Oct 18 '12 at 21:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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