This function calculates Pearson/Spearman correlations between all pairs of features in a matrix/dataframe much faster than the base R cor function. It is also possible to simultaneously calculate mutual rank (MR) of correlations as well as their p-values and adjusted p-values. Additionally, this function can automatically combine and flatten the result matrices. Selecting correlated features using an MR-based threshold rather than based on their correlation coefficients or an arbitrary p-value is more efficient and accurate in inferring functional associations in systems, for example in gene regulatory networks.

fcor(
  data,
  use = "everything",
  method = "spearman",
  mutualRank = TRUE,
  mutualRank_mode = "unsigned",
  pvalue = FALSE,
  adjust = "BH",
  flat = TRUE
)

Arguments

data

a numeric dataframe/matrix (features on columns and samples on rows).

use

The NA handler, as in R's cov() and cor() functions. Options are "everything", "all.obs", and "complete.obs".

method

a character string indicating which correlation coefficient is to be computed. One of "pearson" or "spearman" (default).

mutualRank

logical, whether to calculate mutual ranks of correlations or not.

mutualRank_mode

a character string indicating whether to rank based on "signed" or "unsigned" (default) correlation values. In the "unsigned" mode, only the level of a correlation value is important and not its sign (the function ranks the absolutes of correlations). Options are "unsigned", and "signed".

pvalue

logical, whether to calculate p-values of correlations or not.

adjust

p-value correction method (when pvalue = TRUE), a character string including any of "BH" (default), "bonferroni", "holm", "hochberg", "hommel", or "none".

flat

logical, whether to combine and flatten the result matrices or not.

Value

Depending on the input data, a dataframe or list including cor (correlation coefficients), mr (mutual ranks of correlation coefficients), p (p-values of correlation coefficients), and p.adj (adjusted p-values).

Examples

if (FALSE) {
set.seed(1234)
data <- datasets::attitude
cor <- fcor(data = data)
}