Skip to content

Commit

Permalink
Fix -Inf threshold in coords for curves with direction = ">" (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrobin committed Jul 21, 2019
1 parent 46428ae commit d57d5e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -2,6 +2,7 @@
* Fix erroneous error in 'ci.coords' with 'ret="threshold"' (issue #57)
* Fix vdiffr unit tests with ggplot2 3.2.0 (issue #53)
* Keep list order in 'ggroc' (issue #58)
* Fix -Inf threshold in coords for curves with direction = ">" (issue #60)

1.15.0 (2019-06-01)
* 'roc' now prints messages when autodetecting 'levels' and 'direction' by default. Turn off with 'quiet = TRUE' or set these values explicitly
Expand Down
2 changes: 1 addition & 1 deletion R/roc.utils.R
Expand Up @@ -446,7 +446,7 @@ roc.utils.thr.idx <- function(roc, x) {
}
}
else {
cut_points <- c(rev(cut_points), Inf)
cut_points <- c(rev(cut_points), -Inf)
j <- 1
o <- order(x, decreasing = TRUE)
for (i in seq_along(x)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-coords.R
Expand Up @@ -575,3 +575,15 @@ test_that("invalid x", {
expect_error(coords(smooth(r.s100b), x="c", transpose=FALSE))
expect_error(coords(r.s100b, x="c", transpose=FALSE))
})

test_that("Infinite values work with both directions", {
# direction = >
Data <- structure(list(Outcome = c(1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L), Value = c(72L, 65L, 271L, 73L, 87L, 114L, 111L, 47L, 88L, 44L, 121L, 207L, 33L, 138L, 284L, 62L, 120L, 116L, 202L, 172L, 117L, 69L, 102L, 150L, 131L, 77L, 124L, 46L, 579L, 117L, 96L, 83L, 102L)), class = "data.frame", row.names = c(NA, -33L))
ROC <- roc(Outcome~Value, data=Data, ci=TRUE, direction=">")
co <- coords(ROC, x=c(-Inf, Inf), transpose = FALSE)
expect_equivalent(co, data.frame(threshold = c(-Inf, Inf), specificity = c(1, 0), sensitivity = c(0, 1)))

# direction = <
co <- coords(r.s100b, x=c(-Inf, Inf), transpose = FALSE)
expect_equivalent(co, data.frame(threshold = c(-Inf, Inf), specificity = c(0, 1), sensitivity = c(1, 0)))
})

0 comments on commit d57d5e4

Please sign in to comment.