Skip to content

Comparing two markers: DeLong, bootstrap and Venkatraman

On the same patients, two AUCs are correlated, and DeLong's test accounts for that. Venkatraman's test asks a different question, about the whole curves.

Advanced ~14 min9 steps

What runs in CodeSplash

You will be able to

  • Explain why comparing two markers on the same subjects needs a paired test
  • Read DeLong's test of equal areas and its interval
  • Choose Venkatraman's test when the curves may cross

Read first

01

Same patients, two markers

Read

In the Wisconsin biopsies, clump thickness and uniformity of cell size were scored on the same 241 malignant and 458 benign tumors. Their AUCs are 0.910 and 0.974.

Because the patients are shared, the estimates move together. DeLong's testDeLong testTests whether two AUCs are equal from placement values, including the covariance when both come from the same subjects. includes that covariance:

z=A^1−A^2V1+V2−2 rV1V2z = \frac{\hat A_1 - \hat A_2}{\sqrt{V_1 + V_2 - 2\,r\sqrt{V_1 V_2}}}

Here VV is each AUC's squared standard error, and rr is the correlation between the two estimates.

ROC comparisonIs one score really better than the other on these rows?
View data
eventnew scoreold score
no−0.80900.0380
no0.92300.6760
no1.1871.591
yes2.0291.891
no0.5620−0.1740
no1.4891.776
yes0.90501.790
no−0.9150−0.1910
yes1.018−0.0840
no1.7200.7810
yes1.3651.736
no−2.757−0.7970
no0.56700.1020
yes1.8501.549
yes1.8673.360
no0.8850−0.3320
no1.0451.212
no−0.41800.8660
no1.857−0.6830
no−0.4750−1.303
yes4.6942.247
yes3.1042.772
no1.388−0.9540
no0.81401.098
no−0.99700.7090
no1.188−0.3270
yes1.7741.216
no1.7450.5400
yes1.8550.8970
no−1.484−0.2460
no−0.18900.4880
no1.9870.7960
no0.06301.117
no0.87702.806
no−0.2320−2.070
yes3.3742.253
no0.33700.2530
yes0.35401.345
no−0.3370−1.845
no−1.1890.1180
no−0.74900.0670
no0.6920−0.9850
no−0.1470−0.4000
yes0.91300.9950
no1.3771.176
yes0.96400.1260
yes0.87300.4830
no−1.098−1.637
no0.81500.6330
yes2.6561.167
no−2.024−1.863
no−1.650−1.037
no−0.7470−0.2360
no−0.98100.8100
yes0.7250−0.0480
no−1.654−0.8090
yes0.6230−0.6370
no0.05300.8150
no−0.57600.0650
no0.41100.4100

First 60 of 300 rows.

02

Ignore the pairing

Predict

Predict first

Weight and fuel economy both predict manual transmission in the same cars: AUCs 0.93 and 0.83, with rr = 0.79.

If you treat the two as independent, how strong is the comparison?

StrongerAbout the sameWeaker
Reveal

Weaker. Without the covariance, the standard error is 0.04812+0.07742≈0.091\sqrt{0.0481^2 + 0.0774^2} \approx 0.091 and z≈1.13z \approx 1.13. With it, the standard error is 0.049 and zz = 2.10, p = .036. Pairing removes shared noise, as it does in a paired t test.

03

Read the card

In the app

Back to the biopsies. The card gives each AUC, the difference with its interval, and a Tests table that names the question each test answers.

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.
The exact R script · R 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
  )
))
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.
The exact Python script · Python 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,
    },
})

The difference is −0.064 (−0.089 to −0.039), zz = −5.03, p < .001.

Set First marker direction and Second marker direction yourself: they're never flipped automatically.

04

When equal areas hide a difference

Predict

Predict first

One marker is better when you need high sensitivity, the other when you need high specificity. Their curves cross and the areas nearly match, so DeLong gives pp = 0.9.

Does that show the markers perform alike?

Yes, the markers perform alikeNo, only their areas are compatible with being equal
Reveal

No. DeLong tests areas, and gains in one region can cancel losses in another. Venkatraman's testVenkatraman's testA permutation test that two ROC curves measured on the same subjects are identical at every threshold, not just equal in area. compares the curves themselves, through the gap between them:

T=∫01∣ROC^1(u)−ROC^2(u)∣duT = \int_0^1 \left|\widehat{\text{ROC}}_1(u) - \widehat{\text{ROC}}_2(u)\right| du
05

Run Venkatraman's test

In the app

Set Test to Venkatraman's permutation test. Its p-value comes from swapping each subject's two ranks at random, not from shuffling outcomes. Permutations / resamples sets how many, and Random seed fixes them, so Python and R match.

On a simulated pair of scores, EE = 462, p = .488, and DeLong gives p = .344. Both results are compatible with no difference.

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

ΔAUC = 0.061, 95% CI [−0.066, 0.188], z = 0.95, p = .344

AUC difference (score1 − score2)
0.0614
z (DeLong)
0.9469
p (DeLong)
.344
Venkatraman E
462
p (Venkatraman)
.488

Effect size

  • AUC difference 0.0614 95% CI [−0.0657, 0.1885]

Plots

ROC curvesHow well does a score separate positives from negatives at every cutoff?
View data
marker1 − specificitySensitivity
score100
score100.0167
score100.0333
score100.0500
score100.0667
score100.0833
score100.1000
score100.1167
score100.1333
score100.1500
score100.1667
score100.1833
score100.2000
score100.2167
score10.01670.2167
score10.01670.2333
score10.01670.2500
score10.03330.2500
score10.05000.2500
score10.05000.2667
score10.05000.2833
score10.05000.3000
score10.05000.3167
score10.06670.3167
score10.06670.3333
score10.08330.3333
score10.08330.3500
score10.10000.3500
score10.10000.3667
score10.11670.3667
score10.11670.3833
score10.11670.4000
score10.11670.4167
score10.11670.4333
score10.11670.4500
score10.11670.4667
score10.11670.4833
score10.13330.4833
score10.15000.4833
score10.15000.5000
score10.15000.5167
score10.15000.5333
score10.15000.5500
score10.16670.5500
score10.16670.5667
score10.18330.5667
score10.18330.5833
score10.18330.6000
score10.20000.6000
score10.21670.6000
score10.23330.6000
score10.25000.6000
score10.25000.6167
score10.26670.6167
score10.26670.6333
score10.26670.6500
score10.28330.6500
score10.30000.6500
score10.31670.6500
score10.33330.6500

First 60 of 242 rows.

score1 against score2Is one score really better than the other on these rows?
View data
score1score2truth = true
0.52061.9060
−1.0802.1320
0.13920.23150
−0.08470.89690
−0.6666−1.7390
−2.5160.46880
−0.7351−0.54410
−1.020−0.16540
0.11360.55220
−0.47381.0330
−0.4082−0.04620
−0.73042.6390
−0.22140.58900
−0.2258−0.20240
−2.5470.44160
1.347−0.10030
0.6164−1.0930
0.21760.50320
−0.80470.94920
0.68970.38280
−0.32870.37160
−0.16470.15720
−1.3920.84790
1.466−1.2830
0.04821.1580
1.908−0.90910
1.7310.33500
0.05810.77590
0.64530.23710
1.726−1.5600
−0.52900.02430
0.16640.33460
−0.25470.98940
0.33280.50040
0.18240.57690
1.1651.1430
0.5935−0.70740
−0.8918−0.61860
0.5773−0.00830
−0.82490.33890
−1.1571.4050
0.7780−0.86530
−1.204−0.87400
0.30670.77430
−0.8337−0.40190
1.418−0.21510
0.71180.60530
−0.4025−0.61460
0.7994−0.72440
0.4265−0.25690
−1.170−0.39210
−0.2062−0.68670
−0.93060.87580
0.4494−0.48110
−0.64480.06840
−0.23140.13700
−1.236−1.8590
−0.96100.34630
0.13401.5020
−0.9991−0.01370

First 60 of 120 rows.

Assumptions

  • Same subjects for both markers — Both curves use the same 120 subjects.
  • Enough cases and non-cases — 60 cases and 60 non-cases.

Areas under the curves

MarkerAUCSE (DeLong)
score10.75830.0431
score20.69690.0482

Tests

TestStatisticpQuestion
DeLong (paired)0.94690.3437Equal areas under the curves?
Venkatraman (999 permutations)4620.4880Identical curves at every operating point?
  • Condition present: truth = true. Correlation between the AUC estimates r = -0.005.
  • 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. Its p-value is a permutation p (999 within-subject swaps, seed 1) and matches in Python and R.
The exact R script · R 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 a11b89162715f774
# Dataset: c3_roc (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/c3_roc.parquet", col_select = c("score1", "score2", "truth")))
n_input <- nrow(df)
df[["truth"]] <- factor(df[["truth"]], levels = c("false", "true"))  # stored level order
df <- df[stats::complete.cases(df[c("score1", "score2", "truth")]), , 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("score1", "score2", "truth"))  # infinite values stop the run (registry/errors.yaml)

# %% Test
m1 <- "score1"
m2 <- "score2"
r <- "truth"
ref_levels <- c("false", "true")  # 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 <- "venkatraman"
reps <- as.integer(999)
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
  )
))
Python

ΔAUC = 0.061, 95% CI [−0.066, 0.188], z = 0.95, p = .344

AUC difference (score1 − score2)
0.0614
z (DeLong)
0.9469
p (DeLong)
.344
Venkatraman E
462
p (Venkatraman)
.488

Effect size

  • AUC difference 0.0614 95% CI [−0.0657, 0.1885]

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 120 subjects.
  • Enough cases and non-cases — 60 cases and 60 non-cases.

Areas under the curves

MarkerAUCSE (DeLong)
score10.75830.0431
score20.69690.0482

Tests

TestStatisticpQuestion
DeLong (paired)0.94690.3437Equal areas under the curves?
Venkatraman (999 permutations)4620.4880Identical curves at every operating point?
  • Condition present: truth = true. Correlation between the AUC estimates r = -0.005.
  • 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. Its p-value is a permutation p (999 within-subject swaps, seed 1) and matches in Python and R.
The exact Python script · Python 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 a11b89162715f774
# Dataset: c3_roc (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/c3_roc.parquet", columns=["score1", "score2", "truth"])
n_input = len(df)
df["truth"] = pd.Categorical(df["truth"], categories=["false", "true"])  # stored level order
df = df.dropna(subset=["score1", "score2", "truth"])  # listwise deletion over the analysis columns
df["truth"] = df["truth"].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, ["score1", "score2", "truth"])  # infinite values stop the run (registry/errors.yaml)

# %% Test
m1, m2, r = "score1", "score2", "truth"
ref_levels = ["false", "true"]  # 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 = "venkatraman"
reps = int(999)
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,
    },
})

In the biopsies it gives p = .002. Rejecting says the curves differ somewhere, which may or may not be at a threshold you'd use.

06

A resampling check

In the app

Paired bootstrap tests equal areas, like DeLong. It resamples cases and non-cases separately, and swaps DeLong's variance formula for the spread of the resampled differences.

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

ΔAUC = 0.061, 95% CI [−0.066, 0.188], z = 0.95, p = .344

AUC difference (score1 − score2)
0.0614
z (DeLong)
0.9469
p (DeLong)
.344
z (bootstrap)
0.9640
p (bootstrap)
.335

Effect size

  • AUC difference 0.0614 95% CI [−0.0657, 0.1885]

Plots

ROC curvesHow well does a score separate positives from negatives at every cutoff?
View data
marker1 − specificitySensitivity
score100
score100.0167
score100.0333
score100.0500
score100.0667
score100.0833
score100.1000
score100.1167
score100.1333
score100.1500
score100.1667
score100.1833
score100.2000
score100.2167
score10.01670.2167
score10.01670.2333
score10.01670.2500
score10.03330.2500
score10.05000.2500
score10.05000.2667
score10.05000.2833
score10.05000.3000
score10.05000.3167
score10.06670.3167
score10.06670.3333
score10.08330.3333
score10.08330.3500
score10.10000.3500
score10.10000.3667
score10.11670.3667
score10.11670.3833
score10.11670.4000
score10.11670.4167
score10.11670.4333
score10.11670.4500
score10.11670.4667
score10.11670.4833
score10.13330.4833
score10.15000.4833
score10.15000.5000
score10.15000.5167
score10.15000.5333
score10.15000.5500
score10.16670.5500
score10.16670.5667
score10.18330.5667
score10.18330.5833
score10.18330.6000
score10.20000.6000
score10.21670.6000
score10.23330.6000
score10.25000.6000
score10.25000.6167
score10.26670.6167
score10.26670.6333
score10.26670.6500
score10.28330.6500
score10.30000.6500
score10.31670.6500
score10.33330.6500

First 60 of 242 rows.

score1 against score2Is one score really better than the other on these rows?
View data
score1score2truth = true
0.52061.9060
−1.0802.1320
0.13920.23150
−0.08470.89690
−0.6666−1.7390
−2.5160.46880
−0.7351−0.54410
−1.020−0.16540
0.11360.55220
−0.47381.0330
−0.4082−0.04620
−0.73042.6390
−0.22140.58900
−0.2258−0.20240
−2.5470.44160
1.347−0.10030
0.6164−1.0930
0.21760.50320
−0.80470.94920
0.68970.38280
−0.32870.37160
−0.16470.15720
−1.3920.84790
1.466−1.2830
0.04821.1580
1.908−0.90910
1.7310.33500
0.05810.77590
0.64530.23710
1.726−1.5600
−0.52900.02430
0.16640.33460
−0.25470.98940
0.33280.50040
0.18240.57690
1.1651.1430
0.5935−0.70740
−0.8918−0.61860
0.5773−0.00830
−0.82490.33890
−1.1571.4050
0.7780−0.86530
−1.204−0.87400
0.30670.77430
−0.8337−0.40190
1.418−0.21510
0.71180.60530
−0.4025−0.61460
0.7994−0.72440
0.4265−0.25690
−1.170−0.39210
−0.2062−0.68670
−0.93060.87580
0.4494−0.48110
−0.64480.06840
−0.23140.13700
−1.236−1.8590
−0.96100.34630
0.13401.5020
−0.9991−0.01370

First 60 of 120 rows.

Assumptions

  • Same subjects for both markers — Both curves use the same 120 subjects.
  • Enough cases and non-cases — 60 cases and 60 non-cases.

Areas under the curves

MarkerAUCSE (DeLong)
score10.75830.0431
score20.69690.0482

Tests

TestStatisticpQuestion
DeLong (paired)0.94690.3437Equal areas under the curves?
Paired bootstrap (1,000 resamples)0.96400.3350Equal areas under the curves?
  • Condition present: truth = true. Correlation between the AUC estimates r = -0.005.
  • The bootstrap resamples cases and non-cases separately (1,000 resamples, seed 1); z = ΔAUC / SD of the bootstrap differences.
The exact R script · R 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 9b5a85d4f2a78142
# Dataset: c3_roc (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/c3_roc.parquet", col_select = c("score1", "score2", "truth")))
n_input <- nrow(df)
df[["truth"]] <- factor(df[["truth"]], levels = c("false", "true"))  # stored level order
df <- df[stats::complete.cases(df[c("score1", "score2", "truth")]), , 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("score1", "score2", "truth"))  # infinite values stop the run (registry/errors.yaml)

# %% Test
m1 <- "score1"
m2 <- "score2"
r <- "truth"
ref_levels <- c("false", "true")  # 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 <- "bootstrap"
reps <- as.integer(1000)
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
  )
))
Python

ΔAUC = 0.061, 95% CI [−0.066, 0.188], z = 0.95, p = .344

AUC difference (score1 − score2)
0.0614
z (DeLong)
0.9469
p (DeLong)
.344
z (bootstrap)
0.9640
p (bootstrap)
.335

Effect size

  • AUC difference 0.0614 95% CI [−0.0657, 0.1885]

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 120 subjects.
  • Enough cases and non-cases — 60 cases and 60 non-cases.

Areas under the curves

MarkerAUCSE (DeLong)
score10.75830.0431
score20.69690.0482

Tests

TestStatisticpQuestion
DeLong (paired)0.94690.3437Equal areas under the curves?
Paired bootstrap (1,000 resamples)0.96400.3350Equal areas under the curves?
  • Condition present: truth = true. Correlation between the AUC estimates r = -0.005.
  • The bootstrap resamples cases and non-cases separately (1,000 resamples, seed 1); z = ΔAUC / SD of the bootstrap differences.
The exact Python script · Python 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 9b5a85d4f2a78142
# Dataset: c3_roc (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/c3_roc.parquet", columns=["score1", "score2", "truth"])
n_input = len(df)
df["truth"] = pd.Categorical(df["truth"], categories=["false", "true"])  # stored level order
df = df.dropna(subset=["score1", "score2", "truth"])  # listwise deletion over the analysis columns
df["truth"] = df["truth"].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, ["score1", "score2", "truth"])  # infinite values stop the run (registry/errors.yaml)

# %% Test
m1, m2, r = "score1", "score2", "truth"
ref_levels = ["false", "true"]  # 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 = "bootstrap"
reps = int(1000)
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,
    },
})

The bootstrap's spread is 0.064, against DeLong's 0.065. Its result is p = .335, against p = .344. When they disagree, look at the sample size and the ties before trusting either.

07

Same tests, two dialects

Read

pROC offers all three. Python has no standard DeLong function, and the placement values below are short enough to write yourself. Permutation results differ from the card's, because these tools use their own random numbers.

Python
import numpy as np
import pandas as pd
from scipy import stats


def placements(pos, neg):
    h = (pos[:, None] > neg) + 0.5 * (pos[:, None] == neg)
    return h.mean(axis=1), h.mean(axis=0)


df = pd.read_csv("biopsy.csv")
malignant = df["class"] == "malignant"
v10, v01 = [], []
for col in ["clump", "cell size"]:
    a, b = placements(df.loc[malignant, col].to_numpy(float), df.loc[~malignant, col].to_numpy(float))
    v10.append(a)
    v01.append(b)

s = np.cov(v10) / malignant.sum() + np.cov(v01) / (~malignant).sum()
diff = v10[0].mean() - v10[1].mean()
z = diff / np.sqrt(s[0, 0] + s[1, 1] - 2 * s[0, 1])
print(diff, z, 2 * stats.norm.sf(abs(z)))
R
library(pROC)
df <- read.csv("biopsy.csv", check.names = FALSE)

r1 <- roc(df$class, df$clump, levels = c("benign", "malignant"), direction = "<")
r2 <- roc(df$class, df[["cell size"]], levels = c("benign", "malignant"), direction = "<")

roc.test(r1, r2, paired = TRUE, method = "delong")
roc.test(r1, r2, paired = TRUE, method = "venkatraman", boot.n = 499)
08

Check your understanding

Checkpoint

Check yourself

What is the null hypothesis of DeLong's paired test?

Show the answer

Answer: a

DeLong compares one summary of each curve. Curves can differ a lot and still have equal areas.

Check yourself

Two AUCs have variances 0.0004 and 0.0009, and their covariance is 0.0003. What is the standard error of their difference? Give four decimals.

Show the answer

Answer: 0.0265

Variance of the difference: 0.0004 + 0.0009 − 2 × 0.0003 = 0.0007. Its square root is 0.0265.

Check yourself

Two markers were each measured on different patients. How does DeLong's approach change?

Show the answer

Answer: b

With independent samples there's no shared noise, so the covariance is zero. The app's method compares markers on the same subjects only.

Check yourself

You expect marker A to do better at high sensitivity and marker B at high specificity. Which test fits?

Show the answer

Answer: c

The two AUC tests compare areas, and crossing curves can have equal areas.

Check yourself

How does Venkatraman's paired test build its null distribution?

Show the answer

Answer: b

If the markers perform the same, swapping them within a subject shouldn't matter. Shuffling outcomes would test a different null: that a marker has no relation to the disease.

Check yourself

Venkatraman's test rejects, while DeLong's doesn't. What's a fair next step?

Show the answer

Answer: c

The rejection says the curves differ somewhere. It doesn't say the difference falls where your decision is made.

09

Recap

Recap
  • Markers on the same subjects need a paired test: DeLong includes the covariance.
  • DeLong and the paired bootstrap test equal areas.
  • Venkatraman tests identical curves, and it can see a crossing that areas hide.
  • Choose the test before you look, and set each marker's direction yourself.

Concepts in this lesson