Skip to contents

Performs Kruskal-Wallis tests for each row (or column) of a tidymatrix. This is a non-parametric alternative to one-way ANOVA.

Usage

compute_kruskal(
  .data,
  group_col,
  adjust = "fdr",
  add_to_data = FALSE,
  prefix = NULL,
  return_tibble = TRUE
)

Arguments

.data

A tidymatrix object with rows or columns active

group_col

Character. Name of column in metadata containing group labels

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, statistic, p.value, df, and p.adj (if adjustment applied)

Examples

mat <- matrix(rnorm(150), nrow = 10, ncol = 15)
col_data <- data.frame(
  sample = paste0("S", 1:15),
  condition = rep(c("A", "B", "C"), each = 5)
)
row_data <- data.frame(gene = paste0("Gene", 1:10))
tm <- tidymatrix(mat, row_data, col_data)

# Kruskal-Wallis test
results <- tm |>
  activate(rows) |>
  compute_kruskal(group_col = "condition")