labeled inverse cell frequency: relative frequency

idf_rf(expr, features = NULL, label, multi = TRUE, thres = 0)

Arguments

expr

a matrix, features in row and cells in column

features

vector, feature names or indexes to compute

label

vector, group label of each cell

multi

logical, if to compute based on binary (FALSE) or multi-class (TRUE)

thres

numeric, cell only counts when expr > threshold, default 0

Value

a matrix of inverse cell frequency score

Details

$$\mathbf{IDF_{i,j}} = log(1+\frac{\frac{n_{i,j\in D}}{n_{j\in D}}}{max(\frac{n_{i,j\in \hat D}}{n_{j\in \hat D}})+ e^{-8}})$$ where \(n_{i,j\in D}\) is the number of cells containing feature \(i\) in class \(D\), \(n_{j\in D}\) is the total number of cells in class \(D\), \(\hat D\) is the class except \(D\).

Examples

data <- matrix(rpois(100, 2), 10, dimnames = list(1:10))
smartid:::idf_rf(data, label = sample(c("A", "B"), 10, replace = TRUE))
#>            B         B         A         B         A         B         A
#> 1  0.5596158 0.5596158 0.8472979 0.5596158 0.8472979 0.5596158 0.8472979
#> 2  0.9162907 0.9162907 0.5108256 0.9162907 0.5108256 0.9162907 0.5108256
#> 3  0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472
#> 4  0.6418539 0.6418539 0.7472144 0.6418539 0.7472144 0.6418539 0.7472144
#> 5  0.7884574 0.7884574 0.6061358 0.7884574 0.6061358 0.7884574 0.6061358
#> 6  0.7884574 0.7884574 0.6061358 0.7884574 0.6061358 0.7884574 0.6061358
#> 7  0.6418539 0.6418539 0.7472144 0.6418539 0.7472144 0.6418539 0.7472144
#> 8  0.6418539 0.6418539 0.7472144 0.6418539 0.7472144 0.6418539 0.7472144
#> 9  0.6418539 0.6418539 0.7472144 0.6418539 0.7472144 0.6418539 0.7472144
#> 10 0.5596158 0.5596158 0.8472979 0.5596158 0.8472979 0.5596158 0.8472979
#>            A         A         A
#> 1  0.8472979 0.8472979 0.8472979
#> 2  0.5108256 0.5108256 0.5108256
#> 3  0.6931472 0.6931472 0.6931472
#> 4  0.7472144 0.7472144 0.7472144
#> 5  0.6061358 0.6061358 0.6061358
#> 6  0.6061358 0.6061358 0.6061358
#> 7  0.7472144 0.7472144 0.7472144
#> 8  0.7472144 0.7472144 0.7472144
#> 9  0.7472144 0.7472144 0.7472144
#> 10 0.8472979 0.8472979 0.8472979