Skip to content

HDiagnostic accuracy · diagnostic.roc_compare

Compare two ROC curves (paired)

Does one marker discriminate better than another on the same subjects?

Compares two numeric markers measured on the same subjects: both AUCs, their difference with a DeLong confidence interval and the correlation between the AUC estimates, tested with DeLong's paired test, a paired stratified bootstrap, or Venkatraman's permutation test of identical curves (which also detects curves that cross with equal areas).

Verified in Python and R Python and R agree to 10 decimals Seeded Also called DeLong test, Venkatraman test, roc.test…

A real result

Example “Biopsy two scores”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Comparison of two ROC curvesRecorded · Python and R agreeRecorded 2026-11-17 · 24 values compared
R

ΔAUC = −0.064, 95% CI [−0.089, −0.039], z = −5.03, p < .001

AUC difference (clump − cell size)
−0.0642
z (DeLong)
−5.031
p (DeLong)
< .001

Effect size

  • AUC difference −0.0642 95% CI [−0.0892, −0.0392]

Plots

ROC curvesHow well does a score separate positives from negatives at every cutoff?
View data
marker1 − specificitySensitivity
clump00
clump00.2863
clump00.3444
clump0.00870.5187
clump0.01090.6100
clump0.04590.6846
clump0.23140.8714
clump0.37990.9212
clump0.58950.9710
clump0.69000.9876
clump11
cell size00
cell size00.2780
cell size0.00220.2988
cell size0.00440.4149
cell size0.00660.4896
cell size0.01090.5934
cell size0.01090.7178
cell size0.03060.8465
cell size0.08950.9502
cell size0.17030.9834
cell size11
clump against cell sizeIs one score really better than the other on these rows?
View data
clumpcell sizeclass = malignant
510
540
310
680
410
8101
110
210
210
420
110
210
531
110
871
741
410
410
1071
610
731
1051
310
841
110
521
320
510
210
110
310
210
1071
210
310
210
10101
620
541
251
660
1041
6101
561
10101
110
371
110
410
781
951
531
1031
551
1051
1061
8101
821
521
951

First 60 of 699 rows.

Assumptions

  • Same subjects for both markers — Both curves use the same 699 subjects.
  • Enough cases and non-cases — 241 cases and 458 non-cases.

Areas under the curves

MarkerAUCSE (DeLong)
clump0.90980.0118
cell size0.97400.0059

Tests

TestStatisticpQuestion
DeLong (paired)−5.0314.871e-7Equal areas under the curves?
  • Condition present: class = malignant. Correlation between the AUC estimates r = 0.080.
Python

ΔAUC = −0.064, 95% CI [−0.089, −0.039], z = −5.03, p < .001

AUC difference (clump − cell size)
−0.0642
z (DeLong)
−5.031
p (DeLong)
< .001

Effect size

  • AUC difference −0.0642 95% CI [−0.0892, −0.0392]

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • Same subjects for both markers — Both curves use the same 699 subjects.
  • Enough cases and non-cases — 241 cases and 458 non-cases.

Areas under the curves

MarkerAUCSE (DeLong)
clump0.90980.0118
cell size0.97400.0059

Tests

TestStatisticpQuestion
DeLong (paired)−5.0314.871e-7Equal areas under the curves?
  • Condition present: class = malignant. Correlation between the AUC estimates r = 0.080.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Biopsy two scoresbiopsy · marker_1: clump · marker_2: cell size · reference: class
  • Pima glucose vs bmipima · marker_1: glu · marker_2: body mass index · reference: type
  • Directions booleanmtcars · marker_1: weight (1000 lbs) · marker_2: mpg · reference: manual
  • Venkatraman guidec3_roc · marker_1: score1 · marker_2: score2 · reference: truth
  • Venkatraman biopsybiopsy · marker_1: clump · marker_2: cell size · reference: class
  • Bootstrap guidec3_roc · marker_1: score1 · marker_2: score2 · reference: truth
  • Degenerate single levelbiopsy · marker_1: clump · marker_2: cell size · reference: class

In the guides

Tests from the statistics guide this method runs

Where it sits in the decision guides

  • Compare ROC curves: ROC/AUC (DeLong) · Statistics Guide · H — Diagnostic accuracy
  • Compare to gold standard: McNemar (paired) · Statistics Guide · H — Diagnostic accuracy

What you need

First markernumeric · 1 column
Scores from the first test or model (higher should mean more likely to have the condition, unless you flip it).
Second markernumeric · 1 column
Scores from the second test or model, measured on the same people.
Reference standardcategorical / boolean · 1 column · 2–2 levels
The true condition (gold standard). Rows missing any of the three columns are left out, so both curves use the same subjects.

Choices you make

hypothesis

Condition-present leveldefault —

The reference level meaning "condition present" (default the last stored level).

First marker directiondefault higher

Whether higher or lower values of the first marker indicate the condition.

  • Higher values indicate the condition(default) — Use it when higher values of the first marker point to the condition.
  • Lower values indicate the condition — Use it when lower values of the first marker point to the condition.
Second marker directiondefault higher

Whether higher or lower values of the second marker indicate the condition.

  • Higher values indicate the condition(default) — Use it when higher values of the second marker point to the condition.
  • Lower values indicate the condition — Use it when lower values of the second marker point to the condition.
Testdefault delong

DeLong and the bootstrap compare the areas; Venkatraman compares the whole curves.

  • DeLong's paired test (equal AUCs)(default) — Asymptotic z test with DeLong's paired variance; the standard choice.
  • Paired bootstrap (equal AUCs) — Resamples cases and non-cases separately; z = ΔAUC / bootstrap SD (pROC's bootstrap test).
  • Venkatraman's permutation test (identical curves) — Rank-based permutation test of the whole curves; rejects crossing curves even when the AUCs are equal.
Confidence leveldefault 0.95

How sure the intervals should be: 0.95 gives 95% confidence intervals. Higher confidence means wider intervals.

options

Permutations / resamplesdefault 2000

Same draws in Python and R (Wichmann–Hill stream).

Random seeddefault 1

Fixes the random numbers so reruns give identical results, in Python and in R.

Checks and remedies

CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.

  • Same subjects for both markers

    DeLong's paired test needs both markers on every subject; unpaired curves need a different test.

  • Enough cases and non-cases

What it reports

  • Tests: The two markers perform equally (the chosen test)
n_pos
How many independent units the analysis used; it sets precision and power.
n_neg
How many independent units the analysis used; it sets precision and power.
auc_1
The chance a random positive scores higher than a random negative; 0.5 is guessing, 1 is perfect ranking.
auc_2
The chance a random positive scores higher than a random negative; 0.5 is guessing, 1 is perfect ranking.
se_1
The typical size of the error in an estimate, the standard deviation of its sampling distribution.
se_2
The typical size of the error in an estimate, the standard deviation of its sampling distribution.
auc_diff
Tests whether two AUCs are equal from placement values, including the covariance when both come from the same subjects.
diff_se
The typical size of the error in an estimate, the standard deviation of its sampling distribution.
diff_ci_low
A range of effect values compatible with your data at the chosen confidence level.
diff_ci_high
A range of effect values compatible with your data at the chosen confidence level.
z
An estimate in standard-error units, compared with the standard normal distribution.
p
How surprising your data would be if the null hypothesis were true, as a probability.
r
A number from −1 to 1 for how closely two variables move together; Pearson measures straight-line association.
positive_level
Which group counts as first (or treated, or positive) decides the sign of differences and ratios on the card.
test
The exact variant that ran (for example Welch vs classic F), shown so the result can be reported and reproduced.
test_label
The exact variant that ran (for example Welch vs classic F), shown so the result can be reported and reproduced.
test_statistic
A single number that summarizes how far your data are from what H₀ predicts.
test_p
How surprising your data would be if the null hypothesis were true, as a probability.
venkatraman_e
A permutation test that two ROC curves measured on the same subjects are identical at every threshold, not just equal in area.
venkatraman_p
A permutation test that two ROC curves measured on the same subjects are identical at every threshold, not just equal in area.
boot_sd
Estimates uncertainty by recomputing a statistic on many samples drawn with replacement from your data.
boot_z
An estimate in standard-error units, compared with the standard normal distribution.
boot_p
How surprising your data would be if the null hypothesis were true, as a probability.
reps
How many samples were simulated for a p-value. More gives a steadier p-value; it does not change what is tested.

Python and R

Python and R agree to 10 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.

Default traps between the two languages

  • DeLong's paired covariance is the codesplash twin in both engines; it equals pROC's roc.test(method = 'delong', paired = TRUE) (biopsy clump vs cell size: Z = −5.031).
  • Venkatraman's statistic is written from Venkatraman & Begg (1996) and equals pROC's (E = 462 on the guide's example, c3_roc); permutations swap each subject's jittered ranks with probability ½ on the shared Wichmann–Hill stream (pROC jitters only one of the swapped values and uses R's RNG), so p-values agree in distribution, not draw by draw (0.488 vs pROC's 0.4885 there).
  • The bootstrap test follows pROC's method = 'bootstrap' (stratified resampling, z = ΔAUC / SD) with resamples from the shared stream.
Python

The exact script CodeSplash ran for example “Biopsy two scores” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Compare two ROC curves (paired)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method diagnostic.roc_compare 1.1.2 · spec 189c7c636a3e9900
# Dataset: biopsy (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.stats import roc as csr  # paired DeLong test (twin of codesplashr::cs_delong_paired)

# %% Data
df = pd.read_parquet("tests/parity/fixtures/biopsy.parquet", columns=["clump", "cell size", "class"])
n_input = len(df)
df["class"] = pd.Categorical(df["class"], categories=["benign", "malignant"])  # stored level order
df = df.dropna(subset=["clump", "cell size", "class"])  # listwise deletion over the analysis columns
df["class"] = df["class"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
    warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["clump", "cell size", "class"])  # infinite values stop the run (registry/errors.yaml)

# %% Test
m1, m2, r = "clump", "cell size", "class"
ref_levels = ["benign", "malignant"]  # stored level order
pos_level = ref_levels[-1]  # default: the last level ("true")
s1 = 1.0 if "higher" == "higher" else -1.0  # explicit directions; never flipped automatically
s2 = 1.0 if "higher" == "higher" else -1.0
is_pos = (df[r].astype(str) == pos_level).to_numpy()
x1, x2 = s1 * df[m1].to_numpy(dtype=float), s2 * df[m2].to_numpy(dtype=float)
npos, nneg = int(is_pos.sum()), int((~is_pos).sum())
if npos == 0 or nneg == 0:
    cs.cs_error("CS_E_TOO_FEW_GROUPS", column=r, min=2, k=1)  # needs positives and negatives
conf = 0.95

res = csr.delong_paired(x1[is_pos], x1[~is_pos], x2[is_pos], x2[~is_pos], conf)
test = "delong"
reps = int(2000)
seed = int(1)
vk = csr.venkatraman_paired(x1, x2, is_pos, reps, seed) if test == "venkatraman" else None
bt = csr.bootstrap_paired(x1, x2, is_pos, reps, seed) if test == "bootstrap" else None
if test == "venkatraman":
    test_label, test_stat, test_p = "Venkatraman's permutation test (equal ROC curves)", vk["e"], vk["p"]
elif test == "bootstrap":
    test_label, test_stat, test_p = "Paired bootstrap test (equal AUCs)", bt["z"], bt["p"]
else:
    test_label, test_stat, test_p = "DeLong's paired test (equal AUCs)", res["z"], res["p"]

# %% Assumptions
assumptions = [
    {"key": "pairing", "label": "Same subjects for both markers", "status": "info", "detail": f"Both curves use the same {npos + nneg} subjects."},
    {"key": "sample_size", "label": "Enough cases and non-cases", "status": "warn" if min(npos, nneg) < 10 else "pass",
     "detail": f"{npos} cases and {nneg} non-cases" + ("; the normal approximation is rough." if min(npos, nneg) < 10 else ".")},
]

# %% Result
curves_fpr, curves_tpr, curves_lab = [], [], []
for name, x in ((m1, x1), (m2, x2)):
    pts = csr.roc_points(x[is_pos], x[~is_pos])
    k = len(pts["tpr"])
    keep = np.unique(np.round(np.linspace(0, k - 1, min(k, 1500))).astype(int))
    curves_fpr += pts["fpr"][keep].tolist()
    curves_tpr += pts["tpr"][keep].tolist()
    curves_lab += [name] * len(keep)
# Both scores on every kept row, oriented so higher means the condition (the chart recomputes DeLong's interval from them).
_rc = np.unique(np.round(np.linspace(0, npos + nneg - 1, min(npos + nneg, 5000))).astype(int))
compare_chart = cs.chart("compare", "roc-compare", f"{m1} against {m2}", {
    "label": cs.col(f"{r} = {pos_level}", [1 if is_pos[i] else 0 for i in _rc], "numeric"),
    "a": cs.col(m1, x1[_rc], "numeric"), "b": cs.col(m2, x2[_rc], "numeric"),
}, controls={"level": conf}, note=None if len(_rc) == npos + nneg else f"Drawn from {len(_rc):,} evenly spaced rows; the tests above use all {npos + nneg:,}.")
cs.publish({
    "method": "diagnostic.roc_compare",
    "methodVersion": "1.1.2",
    "title": "Comparison of two ROC curves",
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": npos + nneg,
    "summary": f"AUC {res['auc_1']:.3f} ({m1}) vs {res['auc_2']:.3f} ({m2}): difference {res['diff']:.3f}, {conf:.0%} CI [{res['low']:.3f}, {res['high']:.3f}]; "
    + (f"Venkatraman E = {vk['e']:.0f}, {cs.fmt_p(vk['p'])}." if vk else f"bootstrap z = {bt['z']:.2f}, {cs.fmt_p(bt['p'])}." if bt
       else f"DeLong z = {res['z']:.2f}, {cs.fmt_p(res['p'])}."),
    "apa": f"ΔAUC = {cs.fmt_num(res['diff'], 3)}, {conf:.0%} CI [{cs.fmt_num(res['low'], 3)}, {cs.fmt_num(res['high'], 3)}], z = {cs.fmt_num(res['z'])}, {cs.fmt_p(res['p'])}",
    "statistics": [
        {"key": "auc_diff", "label": f"AUC difference ({m1} − {m2})", "value": res["diff"]},
        {"key": "z", "label": "z (DeLong)", "value": res["z"]}, {"key": "p", "label": "p (DeLong)", "value": res["p"], "format": "p"},
    ] + ([{"key": "venkatraman_e", "label": "Venkatraman E", "value": vk["e"]}, {"key": "venkatraman_p", "label": "p (Venkatraman)", "value": vk["p"], "format": "p"}] if vk else [])
      + ([{"key": "boot_z", "label": "z (bootstrap)", "value": bt["z"]}, {"key": "boot_p", "label": "p (bootstrap)", "value": bt["p"], "format": "p"}] if bt else []),
    "tables": [{
        "key": "aucs", "title": "Areas under the curves",
        "columns": [{"key": "marker", "label": "Marker", "type": "string"}, {"key": "auc", "label": "AUC", "type": "number"},
                    {"key": "se", "label": "SE (DeLong)", "type": "number"}],
        "rows": [{"marker": m1, "auc": res["auc_1"], "se": res["se_1"]}, {"marker": m2, "auc": res["auc_2"], "se": res["se_2"]}],
    }, {
        "key": "tests", "title": "Tests", "columns": [{"key": "test", "label": "Test", "type": "string"}, {"key": "statistic", "label": "Statistic", "type": "number"},
                                                     {"key": "p", "label": "p", "type": "p"}, {"key": "question", "label": "Question", "type": "string"}],
        "rows": [{"test": "DeLong (paired)", "statistic": res["z"], "p": res["p"], "question": "Equal areas under the curves?"}]
        + ([{"test": f"Venkatraman ({reps:,} permutations)", "statistic": vk["e"], "p": vk["p"], "question": "Identical curves at every operating point?"}] if vk else [])
        + ([{"test": f"Paired bootstrap ({reps:,} resamples)", "statistic": bt["z"], "p": bt["p"], "question": "Equal areas under the curves?"}] if bt else []),
    }],
    "effectSizes": [{"key": "auc_diff", "label": "AUC difference", "value": res["diff"], "ciLow": res["low"], "ciHigh": res["high"], "ciLevel": conf,
                     "method": "DeLong paired variance"}],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"Condition present: {r} = {pos_level}. Correlation between the AUC estimates r = {res['r']:.3f}."]
    + (["Venkatraman's test asks whether the two curves are the same at every threshold, so it can reject when the AUCs are equal but the curves cross. "
        f"Its p-value is a permutation p ({reps:,} within-subject swaps, seed {seed}) and matches in Python and R."] if vk else [])
    + ([f"The bootstrap resamples cases and non-cases separately ({reps:,} resamples, seed {seed}); z = ΔAUC / SD of the bootstrap differences."] if bt else []),
    "charts": [cs.chart("roc", "roc-curve", "ROC curves", {"fpr": cs.col("1 − specificity", curves_fpr), "tpr": cs.col("Sensitivity", curves_tpr),
                                                           "curve": cs.col("marker", curves_lab, levels=[m1, m2])}), compare_chart],
    "values": {
        "n_pos": npos, "n_neg": nneg, "auc_1": res["auc_1"], "auc_2": res["auc_2"], "se_1": res["se_1"], "se_2": res["se_2"],
        "auc_diff": res["diff"], "diff_se": res["se"], "diff_ci_low": res["low"], "diff_ci_high": res["high"], "z": res["z"], "p": res["p"],
        "r": res["r"], "positive_level": pos_level, "test": test, "test_label": test_label, "test_statistic": test_stat, "test_p": test_p,
        "venkatraman_e": vk["e"] if vk else None, "venkatraman_p": vk["p"] if vk else None,
        "boot_sd": bt["sd"] if bt else None, "boot_z": bt["z"] if bt else None, "boot_p": bt["p"] if bt else None, "reps": reps if (vk or bt) else None,
    },
})
R

The exact script CodeSplash ran for example “Biopsy two scores” · R version 4.5.1 (2025-06-13)

# Compare two ROC curves (paired)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method diagnostic.roc_compare 1.1.2 · spec 189c7c636a3e9900
# Dataset: biopsy (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_delong_paired, cs_roc_points (twins of codesplash.stats.roc)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/biopsy.parquet", col_select = c("clump", "cell size", "class")))
n_input <- nrow(df)
df[["class"]] <- factor(df[["class"]], levels = c("benign", "malignant"))  # stored level order
df <- df[stats::complete.cases(df[c("clump", "cell size", "class")]), , drop = FALSE]  # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
  warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("clump", "cell size", "class"))  # infinite values stop the run (registry/errors.yaml)

# %% Test
m1 <- "clump"
m2 <- "cell size"
r <- "class"
ref_levels <- c("benign", "malignant")  # stored level order
pos_level <- ref_levels[length(ref_levels)]  # default: the last level ("true")
s1 <- if ("higher" == "higher") 1 else -1  # explicit directions; never flipped automatically
s2 <- if ("higher" == "higher") 1 else -1
is_pos <- as.character(df[[r]]) == pos_level
x1 <- s1 * as.numeric(df[[m1]])
x2 <- s2 * as.numeric(df[[m2]])
npos <- sum(is_pos)
nneg <- sum(!is_pos)
if (npos == 0 || nneg == 0) cs_error("CS_E_TOO_FEW_GROUPS", column = r, min = 2, k = 1)  # needs positives and negatives
conf <- 0.95

res <- cs_delong_paired(x1[is_pos], x1[!is_pos], x2[is_pos], x2[!is_pos], conf)
test <- "delong"
reps <- as.integer(2000)
seed <- as.integer(1)
vk <- if (test == "venkatraman") cs_venkatraman_paired(x1, x2, is_pos, reps, seed) else NULL
bt <- if (test == "bootstrap") cs_bootstrap_roc_paired(x1, x2, is_pos, reps, seed) else NULL
if (test == "venkatraman") {
  test_label <- "Venkatraman's permutation test (equal ROC curves)"; test_stat <- vk$e; test_p <- vk$p
} else if (test == "bootstrap") {
  test_label <- "Paired bootstrap test (equal AUCs)"; test_stat <- bt$z; test_p <- bt$p
} else {
  test_label <- "DeLong's paired test (equal AUCs)"; test_stat <- res$z; test_p <- res$p
}

# %% Assumptions
assumptions <- list(
  list(key = "pairing", label = "Same subjects for both markers", status = "info", detail = sprintf("Both curves use the same %d subjects.", npos + nneg)),
  list(key = "sample_size", label = "Enough cases and non-cases", status = if (min(npos, nneg) < 10) "warn" else "pass",
       detail = sprintf("%d cases and %d non-cases%s", npos, nneg, if (min(npos, nneg) < 10) "; the normal approximation is rough." else "."))
)

# %% Result
curves <- lapply(list(list(m1, x1), list(m2, x2)), function(mx) {
  pts <- cs_roc_points(mx[[2]][is_pos], mx[[2]][!is_pos])
  k <- length(pts$tpr)
  keep <- unique(round(seq(1, k, length.out = min(k, 1500))))
  data.frame(fpr = pts$fpr[keep], tpr = pts$tpr[keep], curve = mx[[1]])
})
curves <- do.call(rbind, curves)
pct <- sprintf("%.0f%%", conf * 100)
# Both scores on every kept row, oriented so higher means the condition (the chart recomputes DeLong's interval from them).
.rc <- unique(round(seq(1, npos + nneg, length.out = min(npos + nneg, 5000))))
compare_chart <- cs_chart("compare", "roc-compare", sprintf("%s against %s", m1, m2), list(
  label = cs_col(sprintf("%s = %s", r, pos_level), as.numeric(is_pos[.rc]), "numeric"),
  a = cs_col(m1, x1[.rc], "numeric"), b = cs_col(m2, x2[.rc], "numeric")
), controls = list(level = conf), note = if (length(.rc) < npos + nneg) sprintf("Drawn from %s evenly spaced rows; the tests above use all %s.", format(length(.rc), big.mark = ","), format(npos + nneg, big.mark = ",")) else NULL)
cs_publish(list(
  method = "diagnostic.roc_compare",
  methodVersion = "1.1.2",
  title = "Comparison of two ROC curves",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = npos + nneg,
  summary = paste0(sprintf("AUC %.3f (%s) vs %.3f (%s): difference %.3f, %s CI [%.3f, %.3f]; ", res$auc_1, m1, res$auc_2, m2, res$diff, pct, res$low, res$high),
                   if (!is.null(vk)) sprintf("Venkatraman E = %.0f, %s.", vk$e, cs_fmt_p(vk$p))
                   else if (!is.null(bt)) sprintf("bootstrap z = %.2f, %s.", bt$z, cs_fmt_p(bt$p))
                   else sprintf("DeLong z = %.2f, %s.", res$z, cs_fmt_p(res$p))),
  apa = sprintf("ΔAUC = %s, %s CI [%s, %s], z = %s, %s", cs_fmt_num(res$diff, 3), pct, cs_fmt_num(res$low, 3), cs_fmt_num(res$high, 3),
                cs_fmt_num(res$z), cs_fmt_p(res$p)),
  statistics = c(list(
    list(key = "auc_diff", label = sprintf("AUC difference (%s − %s)", m1, m2), value = res$diff),
    list(key = "z", label = "z (DeLong)", value = res$z), list(key = "p", label = "p (DeLong)", value = res$p, format = "p")),
    if (!is.null(vk)) list(list(key = "venkatraman_e", label = "Venkatraman E", value = vk$e), list(key = "venkatraman_p", label = "p (Venkatraman)", value = vk$p, format = "p")),
    if (!is.null(bt)) list(list(key = "boot_z", label = "z (bootstrap)", value = bt$z), list(key = "boot_p", label = "p (bootstrap)", value = bt$p, format = "p"))
  ),
  tables = list(list(
    key = "aucs", title = "Areas under the curves",
    columns = list(list(key = "marker", label = "Marker", type = "string"), list(key = "auc", label = "AUC", type = "number"),
                   list(key = "se", label = "SE (DeLong)", type = "number")),
    rows = list(list(marker = m1, auc = res$auc_1, se = res$se_1), list(marker = m2, auc = res$auc_2, se = res$se_2))
  ), list(
    key = "tests", title = "Tests",
    columns = list(list(key = "test", label = "Test", type = "string"), list(key = "statistic", label = "Statistic", type = "number"),
                   list(key = "p", label = "p", type = "p"), list(key = "question", label = "Question", type = "string")),
    rows = c(list(list(test = "DeLong (paired)", statistic = res$z, p = res$p, question = "Equal areas under the curves?")),
             if (!is.null(vk)) list(list(test = sprintf("Venkatraman (%s permutations)", format(reps, big.mark = ",")), statistic = vk$e, p = vk$p,
                                         question = "Identical curves at every operating point?")),
             if (!is.null(bt)) list(list(test = sprintf("Paired bootstrap (%s resamples)", format(reps, big.mark = ",")), statistic = bt$z, p = bt$p,
                                         question = "Equal areas under the curves?")))
  )),
  effectSizes = list(list(key = "auc_diff", label = "AUC difference", value = res$diff, ciLow = res$low, ciHigh = res$high, ciLevel = conf,
                          method = "DeLong paired variance")),
  assumptions = assumptions,
  warnings = warnings,
  notes = c(list(sprintf("Condition present: %s = %s. Correlation between the AUC estimates r = %.3f.", r, pos_level, res$r)),
            if (!is.null(vk)) list(paste("Venkatraman's test asks whether the two curves are the same at every threshold, so it can reject when the AUCs are equal but the curves cross.",
                                         sprintf("Its p-value is a permutation p (%s within-subject swaps, seed %d) and matches in Python and R.", format(reps, big.mark = ","), seed))),
            if (!is.null(bt)) list(sprintf("The bootstrap resamples cases and non-cases separately (%s resamples, seed %d); z = ΔAUC / SD of the bootstrap differences.",
                                           format(reps, big.mark = ","), seed))),
  charts = list(cs_chart("roc", "roc-curve", "ROC curves",
                         list(fpr = cs_col("1 − specificity", curves$fpr), tpr = cs_col("Sensitivity", curves$tpr),
                              curve = cs_col("marker", curves$curve, levels = c(m1, m2)))), compare_chart),
  values = list(
    n_pos = npos, n_neg = nneg, auc_1 = res$auc_1, auc_2 = res$auc_2, se_1 = res$se_1, se_2 = res$se_2,
    auc_diff = res$diff, diff_se = res$se, diff_ci_low = res$low, diff_ci_high = res$high, z = res$z, p = res$p,
    r = res$r, positive_level = pos_level, test = test, test_label = test_label, test_statistic = test_stat, test_p = test_p,
    venkatraman_e = if (is.null(vk)) NULL else vk$e, venkatraman_p = if (is.null(vk)) NULL else vk$p,
    boot_sd = if (is.null(bt)) NULL else bt$sd, boot_z = if (is.null(bt)) NULL else bt$z, boot_p = if (is.null(bt)) NULL else bt$p,
    reps = if (is.null(vk) && is.null(bt)) NULL else reps
  )
))

Sources

  • DeLong, E. R., DeLong, D. M., & Clarke-Pearson, D. L. (1988). Comparing the areas under two or more correlated receiver operating characteristic curves: a nonparametric approach. Biometrics, 44, 837–845.
  • Venkatraman, E. S., & Begg, C. B. (1996). A distribution-free procedure for comparing receiver operating characteristic curves from a paired experiment. Biometrika, 83, 835–848.
  • Robin, X., et al. (2011). pROC: an open-source package for R and S+ to analyze and compare ROC curves. BMC Bioinformatics, 12, 77.

From the CodeSplash method registry · diagnostic.roc_compare v1.1.2.