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,
assay.type1 = NULL,
assay.type2 = NULL,
...
)
Arguments
- object
a
SummarizedExperiment
orMetaboSet
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 against x
- id
character, column name for subject IDs. If provided, the correlation will be computed using the rmcorr package
- object2
optional second 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 duplicated. 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 ofplot_effect_heatmap
- assay.type1
character, assay of object(1) to be used in case of multiple assays
- assay.type2
character, assay of object2 to be used in case of multiple assays
- ...
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.
Examples
data(example_set)
# Correlations between all features
correlations <- perform_correlation_tests(example_set,
x = rownames(example_set), id = "Subject_ID")
#> INFO [2025-06-23 22:37:12] Starting correlation tests.
#> INFO [2025-06-23 22:37:12] Performing correlation tests for single object
#> INFO [2025-06-23 22:37:20] Correlation tests performed.
# 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 = rownames(example_set),
y = c("Time", "Injection_order"), method = "spearman"
)
#> INFO [2025-06-23 22:37:20] Starting correlation tests.
#> INFO [2025-06-23 22:37:20] Performing correlation tests for single object
#> INFO [2025-06-23 22:37:20] Correlation tests performed.
# Correlations between variables from two distinct objects
cross_object_cor <- perform_correlation_tests(hilic_neg_sample,
x = rownames(hilic_neg_sample),
object2 = hilic_pos_sample,
y = rownames(hilic_pos_sample),
all_pairs = FALSE
)
#> INFO [2025-06-23 22:37:20] Starting correlation tests.
#> INFO [2025-06-23 22:37:20] Performing correlation tests for two objects
#> INFO [2025-06-23 22:37:20] Correlation tests performed.