The function allows to compare richness, evenness, alpha diversity and beta diversity across groups, where beta diversity can be assessed with both a Bray Curtis distribution or overdispersion from a Dirichlet-Multinomial distribution fit. By default, groups are subsampled to the same sample number, for this reason the output of the same run can differ. To switch off this behaviour, subsample can be set to false. Chao1 and Shannon diversity are computed with vegan.

compareGroups(
abundances,
property = "beta",
method = "dissim",
groups = c(),
colors = c(),
colorMap = NULL,
plot.type = "pergroup",
avg = "none",
all = FALSE,
noSameGroup = TRUE,
rowNorm = FALSE,
subsample = TRUE,
xlab = "",
pvalViz = FALSE,
returnValues = FALSE
)

## Arguments

abundances a matrix with taxa as rows and samples as columns richness (Chao1), evenness (Sheldon), alpha (alpha-diversity with Shannon index) or beta (beta-diversity) for beta-diversity, dissim (Bray Curtis dissimilarities) and DM (estimation of theta with package dirmult) are supported group membership vector with as many entries as samples in abundances optional color vector with as many entries as (unique) groups (only for plot.type pergroup) optional color map with a color for a metadata value, required for color legend (only for plot.type pergroup) pergroup (plot property per group; this is the only plot type available for richness, evenness, alpha and beta with DM) and intravsinter (plot property for all within-group samples versus all samples) none, mean or median (average group property with the selected averaging method, does not work for method DM) include the beta diversity for all samples for beta diversity with method dissim: only between-group pairs are used to calculate the beta diversity for all samples for beta diversity with method dissim: normalize the abundances row-wise subsample groups randomly to have the same sample number in each group; for plot type intravsinter, it equalises in additon the number of pairs within and between groups the x axis label if true and avg is set to none and plot.type is pergroup, significant Wilcoxon p-values are displayed on the violin plot using function stat_compare_means in R package ggpubr if true, return properties

## Value

if returnValues is true, properties are returned

## Examples

data("ibd_taxa")
groups=as.vector(ibd_metadata$Diagnosis) compareGroups(ibd_taxa,groups=groups,property="alpha",pvalViz = TRUE)#> [1] "Constraining sample number randomly to the same minimal group sample number of 34" #> [1] "Number of significant differences in property alpha across groups: 2"#> No id variables; using all as measure variablesdata("floresgut_taxa") data("floresgut_metadata") groups=floresgut_metadata$host_subject_id
diet.col=makeColorsGivenMetadata(metadataItem=floresgut_metadata$diet,groups=groups)#> [1] "Each sample is assigned into its own bin."compareGroups(floresgut_taxa,groups=groups,colors=diet.col$colors,colorMap=diet.col$colormap)#> [1] "Constraining sample number randomly to the same minimal group sample number of 7"#> No id variables; using all as measure variablesage=floresgut_metadata$age
#> [1] "21 missing values found."col=age.col$colors compareGroups(floresgut_taxa,groups=groups,property="alpha",colors=col,colorMap=age.col$colormap)#> [1] "Constraining sample number randomly to the same minimal group sample number of 7"#> No id variables; using all as measure variables