Skip to content

Commit 304a289

Browse files
committed
add and use metric_range_chr()
1 parent 30bc683 commit 304a289

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+150
-116
lines changed

R/aaa-new.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ metric_direction <- function(x) {
155155
metric_range <- function(x) {
156156
attr(x, "range", exact = TRUE)
157157
}
158+
metric_range_chr <- function(x, i) {
159+
val <- metric_range(x)[[i]]
160+
if (is.infinite(val)) paste0(if (val < 0) "-", "Inf") else as.character(val)
161+
}
158162
`metric_range<-` <- function(x, value) {
159163
attr(x, "range") <- value
160164
x

R/class-accuracy.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#' \deqn{\text{Accuracy} = \frac{A + D}{A + B + C + D}}
2626
#'
2727
#' Accuracy is a metric that should be `r attr(accuracy, "direction")`d. The
28-
#' output ranges from `r metric_range(accuracy)[1]` to
29-
#' `r metric_range(accuracy)[2]`, with `r metric_optimal(accuracy)` indicating
28+
#' output ranges from `r metric_range_chr(accuracy, 1)` to
29+
#' `r metric_range_chr(accuracy, 2)`, with `r metric_optimal(accuracy)` indicating
3030
#' perfect predictions.
3131
#'
3232
#' @author Max Kuhn

R/class-bal_accuracy.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#'
2828
#' Balanced accuracy is a metric that should be
2929
#' `r attr(bal_accuracy, "direction")`d. The output ranges from
30-
#' `r metric_range(bal_accuracy)[1]` to `r metric_range(bal_accuracy)[2]`, with
30+
#' `r metric_range_chr(bal_accuracy, 1)` to `r metric_range_chr(bal_accuracy, 2)`, with
3131
#' `r metric_optimal(bal_accuracy)` indicating perfect predictions.
3232
#'
3333
#' @author Max Kuhn

R/class-detection_prevalence.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#'
2525
#' Detection prevalence is a metric that should be
2626
#' `r attr(detection_prevalence, "direction")`d. The output ranges from
27-
#' `r metric_range(detection_prevalence)[1]` to `r metric_range(detection_prevalence)[2]`.
27+
#' `r metric_range_chr(detection_prevalence, 1)` to `r metric_range_chr(detection_prevalence, 2)`.
2828
#' The "optimal" value depends on the true prevalence of positive events in the data.
2929
#'
3030
#' @author Max Kuhn

R/class-f_meas.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
#' \deqn{F_{meas} = \frac{(1 + \beta^2) \cdot \text{Precision} \cdot \text{Recall}}{(\beta^2 \cdot \text{Precision}) + \text{Recall}}}
3737
#'
3838
#' F measure is a metric that should be `r attr(f_meas, "direction")`d. The
39-
#' output ranges from `r metric_range(f_meas)[1]` to
40-
#' `r metric_range(f_meas)[2]`, with `r metric_optimal(f_meas)` indicating
39+
#' output ranges from `r metric_range_chr(f_meas, 1)` to
40+
#' `r metric_range_chr(f_meas, 2)`, with `r metric_optimal(f_meas)` indicating
4141
#' perfect precision and recall.
4242
#'
4343
#' @references

R/class-fall_out.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#' \deqn{\text{Fall-out} = \frac{B}{B + D}}
3636
#'
3737
#' Fall-out is a metric that should be `r attr(fall_out, "direction")`d. The
38-
#' output ranges from `r metric_range(fall_out)[1]` to
39-
#' `r metric_range(fall_out)[2]`, with `r metric_optimal(fall_out)` indicating
38+
#' output ranges from `r metric_range_chr(fall_out, 1)` to
39+
#' `r metric_range_chr(fall_out, 2)`, with `r metric_optimal(fall_out)` indicating
4040
#' that all actual negatives were correctly predicted as negative (no false
4141
#' positives).
4242
#'

R/class-j_index.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#' \deqn{\text{J-index} = \text{Sensitivity} + \text{Specificity} - 1}
2323
#'
2424
#' J-index is a metric that should be `r attr(j_index, "direction")`d. The
25-
#' output ranges from `r metric_range(j_index)[1]` to
26-
#' `r metric_range(j_index)[2]`, with `r metric_optimal(j_index)` indicating no
25+
#' output ranges from `r metric_range_chr(j_index, 1)` to
26+
#' `r metric_range_chr(j_index, 2)`, with `r metric_optimal(j_index)` indicating no
2727
#' false positives and no false negatives.
2828
#'
2929
#' The binary version of J-index is equivalent to the binary concept of

R/class-kap.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#' expected agreement by chance.
4545
#'
4646
#' Kappa is a metric that should be `r attr(kap, "direction")`d. The output
47-
#' ranges from `r metric_range(kap)[1]` to `r metric_range(kap)[2]`, with
47+
#' ranges from `r metric_range_chr(kap, 1)` to `r metric_range_chr(kap, 2)`, with
4848
#' `r metric_optimal(kap)` indicating perfect agreement. Negative values
4949
#' indicate agreement worse than chance.
5050
#'

R/class-markedness.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#' \deqn{\text{Markedness} = \text{Precision} + \text{Inverse Precision} - 1}
2525
#'
2626
#' Markedness is a metric that should be `r attr(markedness, "direction")`d. The
27-
#' output ranges from `r metric_range(markedness)[1]` to
28-
#' `r metric_range(markedness)[2]`, with `r metric_optimal(markedness)` indicating
27+
#' output ranges from `r metric_range_chr(markedness, 1)` to
28+
#' `r metric_range_chr(markedness, 2)`, with `r metric_optimal(markedness)` indicating
2929
#' perfect predictions.
3030
#'
3131
#' Markedness is to the predicted condition (precision and inverse precision)

R/class-mcc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#' \deqn{\text{MCC} = \frac{(A \cdot D) - (B \cdot C)}{\sqrt{(A + B)(A + C)(D + B)(D + C)}}}
2626
#'
2727
#' MCC is a metric that should be `r attr(mcc, "direction")`d. The output
28-
#' ranges from `r metric_range(mcc)[1]` to `r metric_range(mcc)[2]`, with
28+
#' ranges from `r metric_range_chr(mcc, 1)` to `r metric_range_chr(mcc, 2)`, with
2929
#' `r metric_optimal(mcc)` indicating perfect predictions. A value of 0
3030
#' indicates no better than random prediction, and negative values indicate
3131
#' inverse prediction.

0 commit comments

Comments
 (0)