Learn R Programming

TmCalculator (version 1.0.9)

compare_groups: Compare numeric GRanges metadata across groups

Description

Test whether one or more numeric metadata columns (e.g. Tm, GC) differ between levels of a categorical grouping column in a GRanges object.

Usage

compare_groups(
  gr,
  target = "Tm",
  method = c("wilcoxon", "t.test"),
  group,
  min_n_per_group = 2L,
  paired = FALSE,
  alternative = c("two.sided", "less", "greater"),
  posthoc = TRUE,
  p.adjust.method = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr",
    "none")
)

Value

A list with:

results

Data frame with one row per target: omnibus test name, statistic, p.value, and group information.

summary

Per-group descriptive statistics (n, mean, sd, median).

pairwise

Pairwise comparisons when posthoc = TRUE and there are \(\ge\) 3 groups; otherwise NULL.

Arguments

gr

A GRanges object.

target

Character vector of metadata column names to test (e.g. c("Tm", "GC")). All must be numeric.

method

Statistical test family. One of:

  • "wilcoxon": rank-based tests (Wilcoxon / Kruskal-Wallis).

  • "t.test": Gaussian-based tests (\(t\)-test / ANOVA).

group

Character. Name of a metadata column in gr defining groups.

min_n_per_group

Minimum number of non-missing observations required per group. Default: 2.

paired

Logical. Only for exactly two groups. Default: FALSE.

alternative

Character. Alternative hypothesis for two-group tests. One of "two.sided" (default), "less", or "greater".

posthoc

Logical. For \(\ge\) 3 groups, run pairwise follow-up tests with multiple-testing correction. Default: TRUE.

p.adjust.method

Multiple-testing correction for post-hoc pairwise comparisons. Passed to pairwise.wilcox.test / pairwise.t.test. One of: "holm" (default), "hochberg", "hommel", "bonferroni", "BH" (Benjamini-Hochberg FDR), "BY" (Benjamini-Yekutieli), "fdr" (alias of "BH"), or "none".

Author

Junhui Li

Details

The test used depends on method and the number of group levels:

Groupsmethod = "wilcoxon"method = "t.test"
2Wilcoxon rank-sum (or signed-rank if paired = TRUE)Welch two-sample \(t\)-test (or paired \(t\)-test)
\(\ge\) 3Kruskal-WallisOne-way ANOVA (Welch)

When there are three or more groups and posthoc = TRUE, pairwise follow-up tests are run (Wilcoxon or Welch \(t\)-test) with p.adjust multiple-testing correction.

Examples

Run this code
if (FALSE) {
library(GenomicRanges)
set.seed(1)
gr <- GRanges(
  seqnames = rep("chr1", 90),
  ranges = IRanges(start = sort(sample(1e6, 90)), width = 50),
  Tm = c(rnorm(30, 74, 2), rnorm(30, 70, 2), rnorm(30, 66, 2)),
  GC = runif(90, 40, 60)
)
gr$group <- rep(c("high", "mid", "low"), each = 30)

# Two groups
gr2 <- gr[gr$group %in% c("high", "low")]
compare_groups(gr2, target = "Tm", group = "group", posthoc = FALSE)

# Three or more groups (Kruskal-Wallis + pairwise Wilcoxon)
compare_groups(gr, target = c("Tm", "GC"), group = "group",
                     method = "wilcoxon")

# Three or more groups (one-way ANOVA + pairwise t-tests)
compare_groups(gr, target = "Tm", group = "group", method = "t.test")

# Post-hoc with Benjamini-Hochberg FDR control
compare_groups(gr, target = "Tm", group = "group",
                     p.adjust.method = "BH")
}

Run the code above in your browser using DataLab