Skip to content

Commit

Permalink
Added lr_pos and lr_neg to coords (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrobin committed Jul 7, 2024
1 parent 74db873 commit 2f3b8e3
Show file tree
Hide file tree
Showing 8 changed files with 3,106 additions and 2,676 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pROC
Type: Package
Title: Display and Analyze ROC Curves
Version: 1.18.5
Date: 2023-11-01
Version: 1.18.9999
Date: 2024-07-07
Encoding: UTF-8
Depends: R (>= 2.14)
Imports: methods, plyr, Rcpp (>= 0.11.1)
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.18.9999
* Added "lr_pos" and "lr_neg" to 'coords' (issue #102)

1.18.5 (2023-11-01):
* Fixed formula input when given as variable and combined with `with` (issue #111)
* Fixed formula containing variables with spaces (issue #120)
Expand Down
8 changes: 7 additions & 1 deletion R/roc.utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ roc.utils.valid.coords <- c("specificity", "sensitivity", "accuracy",
"npv", "ppv", "fdr",
"fpr", "tpr", "tnr", "fnr",
"1-specificity", "1-sensitivity", "1-accuracy", "1-npv", "1-ppv",
"precision", "recall",
"precision", "recall", "lr_pos", "lr_neg",
"youden", "closest.topleft")

# Arguments which can be returned by coords
Expand Down Expand Up @@ -472,6 +472,8 @@ roc_utils_calc_coords <- function(roc, thr, se, sp, best.weights) {
"1-ppv"=substr.percent-ppv,
precision=precision,
recall=recall,
"lr_pos"=(se / substr.percent) / (1 - sp / substr.percent),
"lr_neg"=(1 - se / substr.percent) / (sp / substr.percent),
youden=youden,
closest.topleft=closest.topleft
))
Expand Down Expand Up @@ -565,6 +567,8 @@ coord.is.monotone <- c(
"1-ppv"=FALSE,
"precision"=FALSE,
"recall"=TRUE,
"lr_pos"=FALSE,
"lr_neg"=FALSE,
"youden"=FALSE,
"closest.topleft"=FALSE
)
Expand Down Expand Up @@ -592,6 +596,8 @@ coord.is.decreasing <- c(
"1-ppv"=NA,
"precision"=NA,
"recall"=TRUE,
"lr_pos"=NA,
"lr_neg"=NA,
"youden"=NA,
"closest.topleft"=NA
)
Expand Down
2 changes: 2 additions & 0 deletions man/coords.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ as.matrix=FALSE, ...)
\code{tnr} \tab True Negative Rate \tab tn / (tn + fp) \tab specificity \tab Yes \cr
\code{fnr} \tab False Negative Rate \tab fn / (tp + fn) \tab 1-sensitivity \tab Yes \cr
\code{fdr} \tab False Discovery Rate \tab fp / (tp + fp) \tab 1-ppv \tab No \cr
\code{lr_pos} \tab Positive Likelihood Ratio \tab se / (1 - sp) \tab - \tab No \cr
\code{lr_neg} \tab Negative Likelihood Ratio \tab (1 - se) / (sp) \tab - \tab No \cr
\code{youden} \tab Youden Index \tab
se + r * sp
\tab - \tab No \cr
Expand Down
4,683 changes: 2,490 additions & 2,193 deletions tests/testthat/helper-coords-expected-smooth.R

Large diffs are not rendered by default.

676 changes: 410 additions & 266 deletions tests/testthat/helper-coords-expected.R

Large diffs are not rendered by default.

77 changes: 43 additions & 34 deletions tests/testthat/helper-roc.utils-expected.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
expected_roc_utils_calc_coords <-
structure(c(-1, -2, -3, -4, 1, 0.5, 0.1, 0, 0, 0.5, 0.9, 1, 0.36283185840708,
0.5, 0.609734513274336, 0.63716814159292, 0, 36, 64.8, 72, 41,
20.5, 4.1, 0, 0, 20.5, 36.9, 41, 72, 36, 7.2, 0, NaN, 0.63716814159292,
0.63716814159292, 0.63716814159292, 0.36283185840708, 0.36283185840708,
0.36283185840708, NaN, 1, 0.5, 0.1, 0, 0, 0.5, 0.9, 1, 1, 0.5,
0.1, 0, 0, 0.5, 0.9, 1, 0.63716814159292, 0.63716814159292, 0.63716814159292,
NaN, 1, 0.5, 0.1, 0, 0, 0.5, 0.9, 1, 0.63716814159292, 0.5, 0.390265486725664,
0.36283185840708, NaN, 0.36283185840708, 0.36283185840708, 0.36283185840708,
0.63716814159292, 0.63716814159292, 0.63716814159292, NaN, 0.36283185840708,
0.36283185840708, 0.36283185840708, NaN, 1, 0.5, 0.1, 0, 1, 0.50462962962963,
0.108333333333333, 0.00925925925925926, 0.00925925925925926,
0.252314814814815, 0.810092592592593, 1), .Dim = c(4L, 24L), .Dimnames = list(
NULL, c("threshold", "sensitivity", "specificity", "accuracy",
"tn", "tp", "fn", "fp", "npv", "ppv", "tpr", "tnr", "fpr",
"fnr", "fdr", "1-specificity", "1-sensitivity", "1-accuracy",
"1-npv", "1-ppv", "precision", "recall", "youden", "closest.topleft"
)))
structure(c(-1, -2, -3, -4, 1, 0.5, 0.10000000000000001, 0, 0,
0.5, 0.90000000000000002, 1, 0.36283185840707965, 0.5, 0.60973451327433625,
0.63716814159292035, 0, 36, 64.799999999999997, 72, 41, 20.5,
4.1000000000000005, 0, 0, 20.5, 36.899999999999999, 41, 72, 36,
7.2000000000000028, 0, NaN, 0.63716814159292035, 0.63716814159292035,
0.63716814159292035, 0.36283185840707965, 0.36283185840707965,
0.36283185840707954, NaN, 1, 0.5, 0.10000000000000001, 0, 0,
0.5, 0.90000000000000002, 1, 1, 0.5, 0.099999999999999978, 0,
0, 0.5, 0.89999999999999991, 1, 0.63716814159292035, 0.63716814159292035,
0.63716814159292035, NaN, 1, 0.5, 0.099999999999999978, 0, 0,
0.5, 0.90000000000000002, 1, 0.63716814159292035, 0.5, 0.39026548672566375,
0.36283185840707965, NaN, 0.36283185840707965, 0.36283185840707965,
0.36283185840707965, 0.63716814159292035, 0.63716814159292035,
0.63716814159292046, NaN, 0.36283185840707965, 0.36283185840707965,
0.36283185840707954, NaN, 1, 0.5, 0.10000000000000001, 0, 1,
1, 1.0000000000000002, NaN, NaN, 1, 1, 1, 1, 0.50462962962962965,
0.10833333333333334, 0.009259259259259257, 0.009259259259259257,
0.25231481481481483, 0.8100925925925927, 1), .Dim = c(4L, 26L
), .Dimnames = list(NULL, c("threshold", "sensitivity", "specificity",
"accuracy", "tn", "tp", "fn", "fp", "npv", "ppv", "tpr", "tnr",
"fpr", "fnr", "fdr", "1-specificity", "1-sensitivity", "1-accuracy",
"1-npv", "1-ppv", "precision", "recall", "lr_pos", "lr_neg",
"youden", "closest.topleft")))

expected_roc_utils_calc_coords.percent <-
structure(c(-1, -2, -3, -4, 100, 50, 10, 0, 0, 50, 90, 100, 36.283185840708,
50, 60.9734513274336, 63.716814159292, 0, 36, 64.8, 72, 41, 20.5,
4.1, 0, 0, 20.5, 36.9, 41, 72, 36, 7.2, 0, NaN, 63.716814159292,
63.716814159292, 63.716814159292, 36.283185840708, 36.283185840708,
36.283185840708, NaN, 100, 50, 10, 0, 0, 50, 90, 100, 100, 50,
10, 0, 0, 50, 90, 100, 63.716814159292, 63.716814159292, 63.716814159292,
NaN, 100, 50, 10, 0, 0, 50, 90, 100, 63.716814159292, 50, 39.0265486725664,
36.283185840708, NaN, 36.283185840708, 36.283185840708, 36.283185840708,
63.716814159292, 63.716814159292, 63.716814159292, NaN, 36.283185840708,
36.283185840708, 36.283185840708, NaN, 100, 50, 10, 0, 100, 50.462962962963,
10.8333333333333, 0.925925925925926, 0.925925925925926, 25.2314814814815,
81.0092592592593, 100), .Dim = c(4L, 24L), .Dimnames = list(NULL,
c("threshold", "sensitivity", "specificity", "accuracy",
"tn", "tp", "fn", "fp", "npv", "ppv", "tpr", "tnr", "fpr",
"fnr", "fdr", "1-specificity", "1-sensitivity", "1-accuracy",
"1-npv", "1-ppv", "precision", "recall", "youden", "closest.topleft"
)))
structure(c(-1, -2, -3, -4, 100, 50, 10, 0, 0, 50, 90, 100, 36.283185840707965,
50, 60.973451327433622, 63.716814159292035, 0, 36, 64.799999999999997,
72, 41, 20.5, 4.0999999999999996, 0, 0, 20.5, 36.899999999999999,
41, 72, 36, 7.2000000000000028, 0, NaN, 63.716814159292035, 63.716814159292042,
63.716814159292035, 36.283185840707965, 36.283185840707965, 36.283185840707951,
NaN, 100, 50, 10, 0, 0, 50, 90, 100, 100, 50, 10, 0, 0, 50, 90,
100, 63.716814159292035, 63.716814159292035, 63.716814159292042,
NaN, 100, 50, 10, 0, 0, 50, 90, 100, 63.716814159292035, 50,
39.026548672566378, 36.283185840707965, NaN, 36.283185840707965,
36.283185840707958, 36.283185840707965, 63.716814159292035, 63.716814159292035,
63.716814159292049, NaN, 36.283185840707965, 36.283185840707965,
36.283185840707951, NaN, 100, 50, 10, 0, 1, 1, 1.0000000000000002,
NaN, NaN, 1, 1, 1, 100, 50.462962962962962, 10.833333333333334,
0.92592592592592571, 0.92592592592592571, 25.231481481481481,
81.009259259259267, 100), .Dim = c(4L, 26L), .Dimnames = list(
NULL, c("threshold", "sensitivity", "specificity", "accuracy",
"tn", "tp", "fn", "fp", "npv", "ppv", "tpr", "tnr", "fpr",
"fnr", "fdr", "1-specificity", "1-sensitivity", "1-accuracy",
"1-npv", "1-ppv", "precision", "recall", "lr_pos", "lr_neg",
"youden", "closest.topleft")))
Loading

0 comments on commit 2f3b8e3

Please sign in to comment.