Venkatraman¶
Use Venkatraman to compare two models' receiver operating characteristic (ROC) curves on the same cases. It can find different trade-offs across cutoffs even when the models have the same AUROC.
| Question | Do the models make different trade-offs across cutoffs? |
| Inputs | y_true known outcomes; predictions from candidate and reference for the same cases |
| Run | Call (); optionally set permutation settings with .set_permutation(...) |
statistic |
Non-negative sum of the gaps between the two curves |
alternative |
two-sided |
import numpy as np
import samesame as ss
y_true = np.array([0, 0, 0, 1, 1, 1])
candidate = np.array([0.1, 0.2, 0.3, 0.7, 0.8, 0.9])
reference = np.array([0.4, 0.5, 0.6, 0.5, 0.6, 0.7])
test = ss.Venkatraman(y_true, candidate, reference)
test = test.set_permutation(seed=np.random.default_rng(12345))
shape = test()
print(shape.pvalue, shape.statistic)
print(shape.extra["auroc"])
Expected output: a non-negative curve gap. A small p-value suggests that the curves differ; it does not show that one model has a higher AUROC.
Null and statistic¶
The test holds the outcomes fixed and swaps the two predictions within each case.
statistic is the non-negative sum of absolute gaps between the empirical ROC curves at rank thresholds; it is 0.0 for identical curves. The two-sided test asks whether the curves differ; it does not say which model is better. Use DeLong to compare AUROC values.
Edge cases¶
- Tied predictions receive midranks (the average rank of the tied observations). The test does not add random jitter.
- The curve gap cannot be negative. The result reports
alternative="two-sided"because a difference in either direction matters. extra["null"]is a read-only array of evaluated statistics. It can be shorter than the requestedn_permutationswhen SciPy enumerates all possible arrangements.extra["n_permutations"]holds the requested count;extra["auroc"]holds each model's AUROC.- The package does not implement
Venkatraman(inference="asymptotic"). The call raisesNotImplementedError.
Reference¶
samesame.Venkatraman
¶
Bases: _PairedScorersBase
Check whether two models have different ROC curves.
Use this test to compare the models' trade-offs across cutoffs on the same cases with known outcomes. It does not say which model is better.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
NDArray[int_]
|
Binary labels ( |
required |
candidate
|
NDArray[float64]
|
Scores under test with shape |
required |
reference
|
NDArray[float64]
|
Baseline scores with shape |
required |
inference
|
Literal['permutation', 'asymptotic']
|
|
'permutation'
|
Notes
The test compares paired empirical ROC curves, not only their AUROC
values. Equal AUROC values do not mean identical curves. The statistic
is the summed absolute gap between the curves at rank thresholds. It
is non-negative and symmetric, and equals 0.0 for identical
scorers. The permutation null swaps candidate and reference within
each observation. A small p-value is evidence against within-case
exchangeability; it does not mean one model has higher AUROC. Compare
AUROC values with DeLong.
See Also
DeLong : Paired comparison of AUROC values. Dsos : One-sided tail-weighted test in a defined harm direction.
Examples:
>>> import numpy as np
>>> import samesame as ss
>>> y_true = np.array([0, 0, 0, 1, 1, 1])
>>> candidate = np.array([0.1, 0.2, 0.3, 0.7, 0.8, 0.9])
>>> reference = np.array([0.4, 0.5, 0.6, 0.5, 0.6, 0.7])
>>> test = ss.Venkatraman(
... y_true, candidate, reference
... ).set_permutation(seed=42, n_permutations=32)
>>> result = test()
>>> result.test_name
'Venkatraman (permutation)'
>>> round(float(result.statistic), 3)
4.0
>>> round(float(result.pvalue), 3)
0.333
>>> round(float(result.extra["auroc"]["candidate"]), 3)
1.0
Source code in src/samesame/_paired.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
__call__()
¶
Run the test for the selected inference.
Returns:
| Type | Description |
|---|---|
TestResult
|
It holds |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/samesame/_paired.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |