Dsos¶
Use Dsos when you have a measure linked to harm and want to check whether the group under review has moved into its high-value range. Higher values must mean more harm.
| Question | Did target move into the high-value range you defined as harmful? |
| Inputs | source reference values; target values under review |
| Run | Call (); optionally set permutation settings with .set_permutation(...) |
statistic |
Tail-weighted AUC; this is not AUROC |
alternative |
greater |
import numpy as np
import samesame as ss
source = np.array([0.10, 0.22, 0.28, 0.35])
target = np.array([0.30, 0.42, 0.55, 0.61])
test = ss.Dsos(source, target)
test = test.set_permutation(seed=np.random.default_rng(12345))
harm = test()
print(harm.pvalue, harm.statistic)
Expected output: p-value 0.028. In this example, higher scores represent more harm.
Choose the direction before testing: higher values must mean more harm. If lower values mean worse outcomes, reverse the sign. See Benign vs harmful shift for examples.
Null and statistic¶
The test compares the observed tail-weighted AUC with results from shuffled group labels, while keeping scores and weights fixed. The greater alternative checks for a larger statistic in the harmful direction.
statistic is between 0 and 1. It is not AUROC. Higher values mean stronger separation in the high-value tail: more of target falls above cutoffs that flag few source cases. Because the test focuses on the tail, it may miss other kinds of change. A small p-value is evidence against the permutation null, not proof of real-world harm.
Edge cases¶
- The curve keeps each distinct threshold with
drop_intermediate=False. - Ties need no jitter.
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.- The package does not implement
inference="asymptotic". The call raisesNotImplementedError.
Reference¶
Kamulete, V. M. (2022). Test for non-negligible adverse shifts (D-SOS). Proceedings of UAI, PMLR 180:959–968.
samesame.Dsos
¶
Bases: _TwoSampleBase
Test for movement into a high-value range linked to harm.
Higher values must mean more harm. Reverse the sign when lower values
mark worse outcomes. The one-sided greater alternative tests for
a larger tail-weighted AUC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
NDArray[float64]
|
Reference scores with shape |
required |
target
|
NDArray[float64]
|
Scores under review with shape |
required |
inference
|
Literal['permutation', 'asymptotic']
|
|
'permutation'
|
Notes
The statistic integrates TPR * (1 - FPR)^2 over the empirical
ROC curve. It labels source as 0 and target as 1.
It gives more weight to separation at high scores. The permutation
distribution permutes labels while keeping scores and weights fixed;
its null assumes label exchangeability. A small p-value is evidence
against that null, not proof of real-world harm.
See Also
MannWhitneyU : Two-sided permutation test of rank separation. DeLong : Paired comparison of two models' AUROCs.
Examples:
>>> import numpy as np
>>> import samesame as ss
>>> test = ss.Dsos(np.array([0.1, 0.2]), np.array([0.4, 0.5]))
>>> test = test.set_permutation(seed=np.random.default_rng(12345))
>>> result = test()
>>> result.test_name
'D-SOS (permutation)'
Source code in src/samesame/_two_sample.py
455 456 457 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 | |
__call__()
¶
Run the test for the selected inference.
Returns:
| Type | Description |
|---|---|
TestResult
|
It holds |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/samesame/_two_sample.py
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 | |