R/binomial.R

Defines functions binomial

Documented in binomial

#' Calculate the co-dependency index
#' 
#' Calculate P-values from the binomial distribution and take their negative
#' logarithms as an indicator of coexpression, as proposed by Mohammadi et al.
#' in doi: 10.1101/241646. 
#' 
#' @param mat a matrix of data, with samples in rows and features in columns
#' 
#' @return the binomial P-values between non-zero/missing values in each pair of 
#'   columns
#' 
#' @importFrom stats pbinom
#' @export
binomial = function(mat) {
  present = !is.na(mat) & mat > 0
  size = nrow(mat)
  q = crossprod(present)
  prob = crossprod(t(colMeans(present)))
  cor = pbinom(q, size, prob, lower.tail = F)
  dimnames(cor) = list(colnames(mat), colnames(mat))
  -log10(cor)
}
fosterlab/CFTK documentation built on Jan. 19, 2021, 10:31 p.m.