Learn R Programming

countTransformers (version 0.0.6)

getJaccard: Calculate Jaccard Index for Two Binary Vectors

Description

Calculate Jaccard index for two binary vectors.

Usage

getJaccard(cl1, cl2)

Arguments

cl1

n by 1 binary vector of classification 1 for the n subjects

cl2

n by 1 binary vector of classification 2 for the n subjects

Value

The Jaccard Index

Details

Jaccard Index is defined as the ratio $$d/(b+c+d$$, where \(d\) is the number of subjects who were classified to group 1 by both classification rules, \(b\) is the number of subjects who were classified to group 1 by classification rule 1 and were classified to group 0 by classification rule 2, \(c\) is the number of subjects who were classified to group 0 by classification rule 1 and were classified to group 1 by classification rule 2.

References

Zhang Z, Yu D, Seo M, Hersh CP, Weiss ST, Qiu W. Novel Data Transformations for RNA-seq Differential Expression Analysis. (2019) 9:4820 https://rdcu.be/brDe5

Examples

Run this code
# NOT RUN {
  n = 10
  set.seed(1234567)

  # generate two random binary vector of size n
  cl1 = sample(c(1,0), size = n, prob = c(0.5, 0.5), replace = TRUE)
  cl2 = sample(c(1,0), size = n, prob = c(0.5, 0.5), replace = TRUE)
  cat("\n2x2 contingency table >>\n")
  print(table(cl1, cl2))

  JI = getJaccard(cl1, cl2)
  cat("Jaccard index = ", JI, "\n")


# }

Run the code above in your browser using DataLab