R/run_pcor.R

Defines functions run_pcor

Documented in run_pcor

#' Wrapper for partial correlations from corpcor
#' 
#' Conducts co-expression analysis using full partial correlations; these are
#' computed using the shrinkage approach for covariance estimation from the 
#' corpcor package.
#' @param x The n by p matrix of counts.
#' @param threshold Cutoff for significant associations. If NULL, all correlations
#' are returned. Otherwise, correlations of magnitude at or below this threshold are 
#' set to zero.
#' @param verbose If true, progress messages will be printed from pcor.shrink().
#' @return A p by p matrix of association scores.
#' @export
run_pcor <- function(x, transformation = NULL, verbose = FALSE, ...) {
  if(!is.null(transformation)) {
    x <- transformation(x)
  }
  
  scores <- corpcor::pcor.shrink(x, verbose = verbose)
  scores <- matrix(as.numeric(scores), nrow = nrow(scores), ncol = ncol(scores))
  diag(scores) <- 0
  
  colnames(scores) <- colnames(x)
  
  return(scores)
}
tgrimes/dnapath2 documentation built on May 21, 2020, 5:53 p.m.