Skip to contents

Calculates sensitivity, specificity and precision for ternary data (with -1 for negative effect, 0 for no effect, 1 for positive effect).

Usage

count_vector(truth, estim)

count_matrix(truth, estim)

Arguments

truth

(i) vector of length \(p\) or (ii) \(n \times p\) matrix with entries in -1, 0, 1

estim

(i) vector of length \(p\) or (ii) \(p \times n\) matrix with entries -1, 0, 1

Value

Returns a vector of length 3 (with names "sensitivity", "specificity" and "precision") or a matrix with 3 rows (with names "sensitivity", "specificity" and "precision") and \(n\) columns.

Examples

#--- vector ---
p <- 20
truth <- sample(x=c(-1,0,1),size=p,replace=TRUE)
estim <- sample(x=c(-1,0,1),size=p,replace=TRUE)
table(truth,estim)
#>      estim
#> truth -1 0 1
#>    -1  1 1 2
#>    0   3 3 2
#>    1   4 3 1
count_vector(truth,estim)
#> sensitivity specificity   precision 
#>   0.1666667   0.3750000   0.1538462 

#--- matrix ---
p <- 20
n <- 5
truth <- matrix(sample(x=c(-1,0,1),size=n*p,replace=TRUE),nrow=p,ncol=n)
estim <- matrix(sample(x=c(-1,0,1),size=n*p,replace=TRUE),nrow=p,ncol=n)
count_matrix(truth,estim)
#>                  [,1]      [,2]      [,3]      [,4] [,5]
#> sensitivity 0.1111111 0.4000000 0.6875000 0.4285714  0.5
#> specificity 0.4545455 0.3000000 0.0000000 0.3333333  0.5
#> precision   0.1111111 0.3076923 0.6470588 0.4285714  0.5