| group_enrichment {sigminer} | R Documentation |
General Group Enrichment Analysis
Description
This function takes a data.frame as input, compares proportion of positive
cases or mean measure in one subgroup and the remaining samples.
Usage
group_enrichment(
df,
grp_vars = NULL,
enrich_vars = NULL,
cross = TRUE,
co_method = c("t.test", "wilcox.test"),
ref_group = NA
)
Arguments
df |
a |
grp_vars |
character vector specifying group variables to split samples into subgroups (at least 2 subgroups, otherwise this variable will be skipped). |
enrich_vars |
character vector specifying measure variables to be compared.
If variable is not numeric, only binary cases are accepted in the form of
|
cross |
logical, default is |
co_method |
test method for continuous variable, default is 't.test'. |
ref_group |
reference group set in |
Value
a data.table with following columns:
-
grp_var: group variable name. -
enrich_var: enrich variable (variable to be compared) name. -
grp1: the first group name, should be a member ingrp_varcolumn. -
grp2: the remaining samples, marked as 'Rest'. -
grp1_size: sample size forgrp1. -
grp1_pos_measure: for binary variable, it stores the proportion of positive cases ingrp1; for continuous variable, it stores mean value. -
grp2_size: sample size forgrp2. -
grp2_pos_measure: same asgrp1_pos_measurebut forgrp2. -
measure_observed: for binary variable, it stores odds ratio; for continuous variable, it stores scaled mean ratio. -
measure_tested: only for binary variable, it stores estimated odds ratio and its 95% CI fromfisher.test(). -
p_value: for binary variable, it stores p value fromfisher.test(); for continuous variable, it stores value fromwilcox.test()ort.test(). -
type: one of "binary" and "continuous". -
method: one of "fish.test", "wilcox.test" and "t.test".
See Also
Examples
set.seed(1234)
df <- dplyr::tibble(
g1 = factor(abs(round(rnorm(99, 0, 1)))),
g2 = rep(LETTERS[1:4], c(50, 40, 8, 1)),
e1 = sample(c("P", "N"), 99, replace = TRUE),
e2 = rnorm(99)
)
print(str(df))
print(head(df))
# Compare g1:e1, g1:e2, g2:e1 and g2:e2
x1 <- group_enrichment(df, grp_vars = c("g1", "g2"), enrich_vars = c("e1", "e2"))
x1
# Only compare g1:e1, g2:e2
x2 <- group_enrichment(df,
grp_vars = c("g1", "g2"),
enrich_vars = c("e1", "e2"),
co_method = "wilcox.test",
cross = FALSE
)
x2
# Visualization
p1 <- show_group_enrichment(x1, fill_by_p_value = TRUE)
p1
p2 <- show_group_enrichment(x1, fill_by_p_value = FALSE)
p2
p3 <- show_group_enrichment(x1, return_list = TRUE)
p3