View source: R/compare_groups.R
| compare_groups | R Documentation |
Test whether one or more numeric metadata columns (e.g. Tm, GC)
differ between levels of a categorical grouping column in a GRanges
object.
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")
)
gr |
A |
target |
Character vector of metadata column names to test (e.g.
|
method |
Statistical test family. One of:
|
group |
Character. Name of a metadata column in |
min_n_per_group |
Minimum number of non-missing observations required
per group. Default: |
paired |
Logical. Only for exactly two groups. Default: |
alternative |
Character. Alternative hypothesis for two-group tests.
One of |
posthoc |
Logical. For |
p.adjust.method |
Multiple-testing correction for post-hoc pairwise
comparisons. Passed to |
The test used depends on method and the number of group levels:
| Groups | method = "wilcoxon" | method = "t.test" |
| 2 | Wilcoxon rank-sum (or signed-rank if paired = TRUE) |
Welch two-sample t-test (or paired t-test) |
\ge 3 | Kruskal-Wallis | One-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.
A list with:
resultsData frame with one row per target: omnibus
test name, statistic, p.value, and group information.
summaryPer-group descriptive statistics
(n, mean, sd, median).
pairwisePairwise comparisons when posthoc = TRUE and
there are \ge 3 groups; otherwise NULL.
Junhui Li
## Not run:
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")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.