Skip to contents

Performs correlation tests between each row (or column) and a continuous variable in the metadata.

Usage

compute_correlation(
  .data,
  var,
  method = "pearson",
  adjust = "fdr",
  add_to_data = FALSE,
  prefix = NULL,
  return_tibble = TRUE
)

Arguments

.data

A tidymatrix object with rows or columns active

var

Character. Name of continuous variable in metadata to correlate with

method

Character. Correlation method: "pearson" (default), "spearman", or "kendall"

adjust

Character. Method for p-value adjustment. Default "fdr". Use "none" for no adjustment

add_to_data

Logical. If TRUE, adds results to row_data/col_data and returns modified tidymatrix. If FALSE (default), returns data.frame

prefix

Character. Optional prefix for result column names when add_to_data = TRUE

return_tibble

Logical. If TRUE (default), returns tibble. If FALSE, returns data.frame. Only applies when add_to_data = FALSE

Value

A data.frame/tibble with columns: identifiers, correlation, p.value, and p.adj (if adjustment applied)

Examples

mat <- matrix(rnorm(100), nrow = 10, ncol = 10)
col_data <- data.frame(
  sample = paste0("S", 1:10),
  age = rnorm(10, 50, 10)
)
row_data <- data.frame(gene = paste0("Gene", 1:10))
tm <- tidymatrix(mat, row_data, col_data)

# Pearson correlation
results <- tm |>
  activate(rows) |>
  compute_correlation(var = "age", method = "pearson")

# Spearman correlation
results <- tm |>
  activate(rows) |>
  compute_correlation(var = "age", method = "spearman")