perform_correlation_tests: Perform correlation tests

View source: R/stats.R

perform_correlation_testsR Documentation

Perform correlation tests

Description

Performs a correlation test between two sets of variables. All the variables must be either feature names or column names of pheno data (sample information). There are two ways to use this function: either provide a set of variables as x, and all correlations between those variables are computed. Or provide two distinct sets of variables x, y and correlations between each x variable and each y variable are computed.

Usage

perform_correlation_tests(
  object,
  x,
  y = x,
  id = NULL,
  object2 = NULL,
  fdr = TRUE,
  all_pairs = TRUE,
  duplicates = FALSE,
  ...
)

Arguments

object

a MetaboSet object

x

character vector, names of variables to be correlated

y

character vector, either identical to x (the default) or a distinct set of variables to be correlated agains x

id

character, column name for subject IDs. If provided, the correlation will be computed using the rmcorr package

object2

optional second MeatboSet object. If provided, x variables will be taken from object and y variables will be taken from object2. Both objects should have the same number of samples.

fdr

logical, whether p-values from the correlation test should be adjusted with FDR correction

all_pairs

logical, whether all pairs between x and y should be tested. If FALSE, x and y give the exact pairs of variables to test, and should have the same length.

duplicates

logical, whether correlations should be dublicated. If TRUE, each correlation will be included in the results twice, where the order of the variables (which is x and which is y) is changed. Can be useful for e.g. plotting a heatmap of the results, see examples of plot_effect_heatmap

...

other parameters passed to cor.test, such as method

Value

a data frame with the results of correlation tests: the pair of variables, correlation coefficient and p-value

See Also

cor.test, rmcorr

Examples

# Correlations between all features
correlations <- perform_correlation_tests(example_set, x = featureNames(example_set))

# Spearman Correlations between features and sample information variables
# Drop QCs and convert time to numeric
no_qc <- drop_qcs(example_set)
no_qc$Time <- as.numeric(no_qc$Time)
correlations <- perform_correlation_tests(no_qc,
  x = featureNames(example_set),
  y = c("Time", "Injection_order"), method = "spearman"
)

# Correlations between variables from two distinct MetaboSets
cross_object_cor <- perform_correlation_tests(hilic_neg_sample,
  x = featureNames(hilic_neg_sample),
  object2 = hilic_pos_sample,
  y = featureNames(hilic_pos_sample),
  all_pairs = FALSE
)

antonvsdata/notame documentation built on Sept. 14, 2024, 11:09 p.m.