Repository navigation
Collapse tied predictions in performance_roc() - #1017
Merged
strengejacke merged 3 commits intoNov 24, 2026
Merged
Conversation
| x <- x[ord] | ||
| predictions <- predictions[ord] | ||
|
|
||
| tp <- cumsum(x) |
Member
There was a problem hiding this comment.
Can you write out the object names? I guess it is true_positives and false_positives. I know we often did not use clear names in the past, but now when we rewrite / add code, we can start improving readability :-)
Member
|
Can you add a NEWS item, and increase the dev-version number (to something like 0.20.0.10 or similar - increase the last digit by 1) |
soodoku
force-pushed
the
fix/performance-roc-ties
branch
from
November 24, 2026 13:49
95f9345 to
bbcbf51
Compare
Contributor
Author
|
Thanks for the review! Updated the PR:
|
Member
|
Thanks, LGTM! |
strengejacke
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.performance_roc_numeric()previously emitted one ROC point per observation after sorting bypredictionswithout collapsing ties. When predictions contain ties, the resulting ROC curve and AUC depend on the input row order and diverge from the standard trapezoidal ROC/AUC (e.g.,pROC::auc).Minimal reproducible example
0.9444444form1vs0.9365079form2(row-order dependent), neither matchingpROC::auc(0.9404762).m1andm2return0.9404762, matchingpROC::auc.Fix
In
.performance_roc_numeric(), sort bothxandpredictionsbyorder(predictions, decreasing = TRUE), compute cumulative true positives and false positives, and keep only the last point of each unique prediction value via!duplicated(predictions, fromLast = TRUE). Also drop the redundant trailing1since the final retained cumulative ratio is already1.Updated the hardcoded
Sensitivityvectors in the two existing tests intests/testthat/test-performance_roc.Rwhose fitted models contain tied predictions (glmer(vs ~ mpg + (1 | gear))andglm(y ~ Sepal.Length + Sepal.Width)both have 4 tied predictions).Verification
"performance_roc collapses tied predictions (row-order invariant)"intests/testthat/test-performance_roc.R.testthat::test_file("tests/testthat/test-performance_roc.R"):PASS 10 | FAIL 0 | WARN 0 | SKIP 0.R/performance_roc.R):FAIL 9 | PASS 1; restoringR/performance_roc.R:PASS 10 | FAIL 0 | WARN 0.