Compare genotypes/phenotypes based on signature groups (samples are assigned to several groups). For categorical type, calculate fisher p value (using stats::fisher.test) and count table. In larger than 2 by 2 tables, compute p-values by Monte Carlo simulation. For continuous type, calculate anova p value (using stats::aov), summary table and Tukey Honest significant difference (using stats::TukeyHSD). The result of this function can be plotted by show_group_comparison().

get_group_comparison(
  data,
  col_group,
  cols_to_compare,
  type = "ca",
  NAs = NA,
  verbose = FALSE
)

Arguments

data

a data.frame containing signature groups and genotypes/phenotypes (including categorical and continuous type data) want to analyze. User need to construct this data.frame by him/herself.

col_group

column name of signature groups.

cols_to_compare

column names of genotypes/phenotypes want to summarize based on groups.

type

a characater vector with length same as cols_to_compare, 'ca' for categorical type and 'co' for continuous type.

NAs

default is NA, filter NAs for categorical columns. Otherwise a value (either length 1 or length same as cols_to_compare) fill NAs.

verbose

if TRUE, print extra information.

Value

a list contains data, summary, p value etc..

Author

Shixiang Wang w_shixiang@163.com

Examples

# \donttest{
load(system.file("extdata", "toy_copynumber_signature_by_W.RData",
  package = "sigminer", mustWork = TRUE
))

# Assign samples to clusters
groups <- get_groups(sig, method = "k-means")
#>  [2024-03-13 10:46:29.835536]: Started.
#>  [2024-03-13 10:46:29.837225]: 'Signature' object detected.
#>  [2024-03-13 10:46:29.842497]: Running k-means with 2 clusters...
#>  [2024-03-13 10:46:29.85173]: Generating a table of group and signature contribution (stored in 'map_table' attr):
#>        Sig1      Sig2
#> 1 0.2097559 0.7901116
#> 2 0.8964984 0.1035016
#>  [2024-03-13 10:46:29.854921]: Assigning a group to a signature with the maximum fraction...
#>  [2024-03-13 10:46:29.858319]: Summarizing...
#> 	group #1: 2 samples with Sig2 enriched.
#> 	group #2: 8 samples with Sig1 enriched.
#> ! [2024-03-13 10:46:29.860314]: The 'enrich_sig' column is set to dominant signature in one group, please check and make it consistent with biological meaning (correct it by hand if necessary).
#>  [2024-03-13 10:46:29.861816]: 0.026 secs elapsed.

set.seed(1234)

groups$prob <- rnorm(10)
groups$new_group <- sample(c("1", "2", "3", "4", NA), size = nrow(groups), replace = TRUE)

# Compare groups (filter NAs for categorical coloumns)
groups.cmp <- get_group_comparison(groups[, -1],
  col_group = "group",
  cols_to_compare = c("prob", "new_group"),
  type = c("co", "ca"), verbose = TRUE
)
#> Treat prob as continuous variable.
#> Treat new_group as categorical variable.

# Compare groups (Set NAs of categorical columns to 'Rest')
groups.cmp2 <- get_group_comparison(groups[, -1],
  col_group = "group",
  cols_to_compare = c("prob", "new_group"),
  type = c("co", "ca"), NAs = "Rest", verbose = TRUE
)
#> Treat prob as continuous variable.
#> Treat new_group as categorical variable.
# }