# ROC curve and area under it

`stats_roc_curve` · Runs: On the server · Level: Checked against a reference: scikit-learn 1.9.1 and SciPy 1.18.1

Works out the empirical ROC points and area under the curve from scores of positive and negative cases.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Statistics](https://www.drybench.com/mcp/catalogue/statistics)

[Ask your assistant](https://www.drybench.com/mcp/connect)

```cite
ROC curve and area under it (stats_roc_curve), Drybench MCP server 1.0.0; stats-roc@2.0.1 (Checked against a reference); https://www.drybench.com/mcp/tools/stats-roc-curve
```

## What it is

Returns the empirical ROC points and the area under the curve from scores of cases you declare positive and negative. Use when a continuous or rating-scale test is judged against a reference standard and you want sensitivity and specificity at every cut-off. Not for one cut-off's 2 × 2 table: use \`stats\_diagnostic\_accuracy\`. Withholds an interval on the area in this version; never picks a cut-off; up to 500 scores per class. A measurement's unit is required, never assumed: any unit of the kit's table, returned in its canonical spelling; a unit group takes one unit, never converted.

Field: [Statistics and design](https://www.drybench.com/mcp/catalogue/statistics).

## What it does

**You give**

- `positives` (required): The scores of the cases the reference standard calls positive.
- `negatives` (required): The scores of the cases the reference standard calls negative, in the same unit.
- `direction` (required): 'higher-is-positive' or 'lower-is-positive': which way the score points to a positive. Never inferred.

No request is recorded for this tool.

**Limits**

- Research statistics and experimental-design arithmetic on the data, margins, prevalence and settings you supply.
- Not for diagnosis or treatment decisions and not a regulatory analysis.
- It does not choose a design, a margin, a cut-off or a sample size for you.
- 1 to 500 scores per class.
- No interval on the AUC in this version; do not compare AUCs from this output.
- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

**It will not answer when**

- positives, negatives or direction not sent.
- positives or negatives empty.
- more than 500 scores in either group.
- a score that is not a finite number, or a subnormal one (not 0 and smaller in magnitude than 2.2250738585072014e-308); −0.0 is accepted, as the same score as 0.0.

### Every input, with its units

3 inputs

- `positives` (required): The scores of the cases the reference standard calls positive.
- `negatives` (required): The scores of the cases the reference standard calls negative, in the same unit.
- `direction` (required): 'higher-is-positive' or 'lower-is-positive': which way the score points to a positive. Never inferred.

### Every refusal, with its code

7 refusals

| Code | When |
| --- | --- |
| `MISSING_ARGUMENT` | positives, negatives or direction not sent. |
| `TOO_FEW_VALUES` | positives or negatives empty. |
| `TOO_MANY_VALUES` | more than 500 scores in either group. |
| `INVALID_NUMBER` | a score that is not a finite number, or a subnormal one (not 0 and smaller in magnitude than 2.2250738585072014e-308); −0.0 is accepted, as the same score as 0.0. |
| `MISSING_UNIT` | a score without a unit. |
| `UNITS_DIFFER` | a score, in either group, whose unit is not written as positives\[0\]'s is, even an equivalent unit spelled differently (mg/L and µg/mL): no unit is converted; only the kit's spellings of one unit (µg and µg, for one) count as the same. |
| `INVALID_OPTION` | direction other than 'higher-is-positive' or 'lower-is-positive'. The arguments are checked in this order, the first failure answering: an argument not in the schema (UNKNOWN\_ARGUMENT); then positives (sent, then its count, then each score from the first: a finite, non-subnormal number with a unit, in positives\[0\]'s unit); then negatives the same way, its units against positives\[0\]'s; then direction (sent, then one of its two values). |

## The calculation

The method's equations, constants and worked example.

### [The empirical ROC curve and its area (AUC) from scores of declared positives and negatives](https://www.drybench.com/methods/m/stats-roc/2.0.1)

`stats-roc@2.0.1`

**Equation 1**

```text
at threshold c: TP = #{positives called positive}, FP = #{negatives called positive}, TPR = TP/n₁ (sensitivity), FPR = FP/n₀ (1 − specificity)
called positive when score ≥ c (higher-is-positive) or ≤ c (lower-is-positive), so a positive and a negative whose score equals c are both called positive. The thresholds: first, always, the point (0, 0) with threshold 'above-every-score' (higher-is-positive) or 'below-every-score' (lower-is-positive), nothing called positive
then each distinct score of either group, from the most positive in the stated direction, as c in the scores' unit, −0.0 and 0.0 being one score (served as 0)
the last point is (1, 1)
```

| Symbol | Meaning |
| --- | --- |
| `n₁` | positives |
| `n₀` | negatives |
| `c` | threshold (in the caller's unit), as-given |

Source 1.

**Equation 2**

```text
AUC = U/(n₁n₀), U = Σᵢ Σⱼ ψ(xᵢ, yⱼ), ψ = 1 if the positive's score is more positive, ½ if tied, 0 if less, in the stated direction
```

| Symbol | Meaning |
| --- | --- |
| `U` | Mann–Whitney count: a multiple of ½ from 0 to n₁n₀, counted exactly (2U in integers) and served as a number, a whole number or one ending in .5 when an odd number of pairs tie |
| `AUC` | area |
| `xᵢ` | score of positive i (in the caller's unit), as-given |
| `yⱼ` | score of negative j (in the caller's unit), as-given |
| `ψ` | 1, ½ or 0 for each pair, as defined in the text |

Source 1.

**Equation 3**

```text
J = TPR − FPR at each threshold, computed as written
it equals Se + Sp − 1
```

| Symbol | Meaning |
| --- | --- |
| `J` | Youden's index |

Source 1.

**Conventions**

- direction = higher-is-positive: A score at or above the threshold is called positive; points run from the highest score down; the AUC is P(positive's score > negative's) + ½ P(tie).
- direction = lower-is-positive: A score at or below the threshold is called positive; points run from the lowest score up; the AUC is P(positive's score \< negative's) + ½ P(tie).

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

**Worked example**

Worked example: one case of stats-roc\@2.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

**Inputs**

- positives\[0\] = 0.9
- positives\[1\] = 0.8
- positives\[2\] = 0.7
- positives\[3\] = 0.55
- positives\[4\] = 0.52
- positives\[5\] = 0.4
- positives\[6\] = 0.38
- positives\[7\] = 0.34
- negatives\[0\] = 0.6
- negatives\[1\] = 0.51
- negatives\[2\] = 0.39
- negatives\[3\] = 0.33
- negatives\[4\] = 0.3
- negatives\[5\] = 0.2
- negatives\[6\] = 0.1
- direction = higher-is-positive

**Steps**

1. u = 46, from positives, negatives; by equation 2; gives u.
2. auc = 0.82142857, from u; by equation 2; gives auc.

**Answer**

- u = 46
- auc = 0.82142857

Where these values came from: an outside program, scikit-learn; SciPy scikit-learn 1.9.1; scipy 1.18.1; typed scores; scikit-learn 1.9.1 roc\_curve(drop\_intermediate=False) and roc\_auc\_score, AUC checked equal to SciPy 1.18.1 mannwhitneyu U/(n1 n0).

At build the tool returned this answer within the tolerance the file states: counts, U (a half-integer), thresholds and the points' fractions exact; the AUC relative 1e-15 (absolute 1e-215 below 1e-200); Youden's J absolute 1e-15; statuses, states and codes exact.

Who worked this case: not recorded.

## Sources

1. Hajian-Tilaki K. Receiver operating characteristic (ROC) curve analysis for medical diagnostic test evaluation. Caspian J Intern Med 2013;4(2):627-635 Used for: The empirical ROC curve and its area (AUC) from scores of declared positives and negatives. At: section Table 1 (TPF, FPF) and the ROC plot of TPF against FPF across cut-offs; Table 2; section Indices of Accuracy: the AUC as the probability that a randomly chosen diseased subject is ranked as more likely diseased, by the Mann–Whitney U statistic; the ½ for ties is the trapezoidal area's (the builder's algebra, checked against scikit-learn); section Advantage of ROC Curve Analysis and Optimal Cut-off Value, the second method of finding an optimal cut-off: "Youden Index=TPF-FPF= Sensitivity+ Specificity -1"; the source maximises it across cut-offs to choose one, which this method never does: J is reported at each threshold as a description of these data (Drybench ruling, 10 November 2026, names; cases, red line 2). **Read in full, 17 November 2026**

Read by AI-assisted sessions. No person has checked these readings.

## How it is checked

**Level:** Checked against a reference.

**Checked against:** An outside program, scikit-learn; SciPy, scikit-learn 1.9.1; scipy 1.18.1; our own exact-arithmetic script and a hand-worked case; a reference program this project wrote itself, second implementation by a fresh agent (Python 3.13, standard library), 2026-11-14, counts and 2U in integers; the AUC as an exact rational rounded once to a double; the fractions and Youden's J in double precision as the record writes them; not an outside program.

**Cases:** No case set is linked to this version.

**Not checked:** The AUC interval and comparisons of two curves (DeLong 1988, Hanley and McNeil 1982 not read); partial areas; smoothed or parametric curves; the choice of a cut-off, which is never made (no arg-max of Youden's J).

No independent scientist has yet reviewed this.

### Changes to its methods

0 changes

No change is logged for these method versions.
