Let the set of predictions be described by a logical vector `pred`, and let the corresponding trues by described in a logical vector `true` of the same length. Then, the true positive rate is given by the expression: sum(pred & true)/sum(true). The false positive rate is given by the expression: sum(pred & !true)/sum(!true). If these expressions do not give a finite number, NA_real_ is returned.

TruePositiveRate(pred, true)

FalsePositiveRate(pred, true)

Arguments

pred, true

vectors of the same positive length that can be converted to logical.

Value

a double between 0 and 1 or NA_real_ if the result is not a finite number.

Examples

TruePositiveRate(c(1,0,1,1), c(1,1,0,1))
#> [1] 0.6666667
TruePositiveRate(c(0,0,0,0), c(1,1,0,1))
#> [1] 0
TruePositiveRate(c(1,1,1,1), c(1,1,0,1))
#> [1] 1
FalsePositiveRate(c(1,0,1,1), c(1,1,0,1))
#> [1] 1
FalsePositiveRate(c(0,0,0,0), c(1,1,0,1))
#> [1] 0
FalsePositiveRate(c(1,1,1,1), c(1,1,0,1))
#> [1] 1
TruePositiveRate(c(1,0,1,1), c(0,0,0,0))
#> [1] NA
FalsePositiveRate(c(1,0,1,1), c(1,1,1,1))
#> [1] NA