ANCOM-BC2 extends ANCOM-BC to multigroup comparisons. It supports fixed and random effects, and therefore covariate adjustment and repeated measures. It provides a global test, pairwise comparisons, comparisons against a reference group (Dunnett-type), and trend tests across ordered groups, with control of the mixed directional false discovery rate.
The R tutorial applies ANCOM-BC2 to the HITChip Atlas data set of intestinal microbiota profiles from Western adults, distributed with the microbiome package as atlas1006. The analysis compares the abundance of each taxon, aggregated at the Family rank of the data set, across three body mass index (BMI) groups (lean, overweight, obese), adjusted for age and geographic region.
Let \(o_{ij}\) denote the observed abundance of taxon \(i\) in sample \(j\), and let \(\mathbf{x}_j\) denote the covariate vector of sample \(j\), including an intercept. ANCOM-BC2 assumes
where \(d_j\) is the log sampling fraction of sample \(j\) and \(\varepsilon_{ij}\) is a mean-zero error. For repeated measures, random effects are added to the linear predictor through rand_formula.
Let \(\beta_{i,\mathrm{ow}}\) and \(\beta_{i,\mathrm{ob}}\) denote the coefficients of taxon \(i\) for the overweight and obese groups, with lean as the reference. The analysis tests four families of hypotheses.
The pairwise and Dunnett-type tests control the mixed directional false discovery rate, which accounts for both the multiple comparisons within a taxon and the multiplicity across taxa.
Data
library(ANCOMBC)library(tidyverse)data(atlas1006, package ="microbiome")# Baseline samples only, so that each subject contributes one sample.pseq <- phyloseq::subset_samples(atlas1006, time ==0)meta <-data.frame(phyloseq::sample_data(pseq))# BMI in three ordered groups, with lean as the reference level.meta$bmi <-fct_collapse(meta$bmi_group,obese =c("obese", "severeobese", "morbidobese"))meta$bmi <-factor(meta$bmi, levels =c("lean", "overweight", "obese"))# Geographic region, with Central Europe as the reference level.meta$region <-fct_collapse(meta$nationality,CE ="CentralEurope", NE =c("Scandinavia", "UKIE"),SE ="SouthEurope", EE ="EasternEurope", US ="US")phyloseq::sample_data(pseq) <- metatse <- mia::convertFromPhyloseq(pseq)tse
The trend test requires the monotone patterns as inequality constraints \(A\boldsymbol{\theta} \ge 0\) on \(\boldsymbol{\theta} = (\beta_{i,\mathrm{ow}}, \beta_{i,\mathrm{ob}})^\top\). The pattern \(0 \le \beta_{i,\mathrm{ow}} \le \beta_{i,\mathrm{ob}}\) (increasing) and the pattern \(0 \ge \beta_{i,\mathrm{ow}} \ge \beta_{i,\mathrm{ob}}\) (decreasing) are specified as two contrast matrices.
Grouping variable for structural zero detection and for the global, pairwise, Dunnett-type, and trend tests.
pseudo_sens
Sensitivity analysis of each result to the addition of pseudo-counts to zeros.
s0_perc
Percentile of the standard errors added to the denominator of the test statistic, which limits significance caused by very small standard errors.
global, pairwise, dunnet, trend
Multigroup tests to perform.
mdfdr_control
Procedure and number of bootstrap samples B for the mixed directional false discovery rate.
trend_control
Contrast matrices, position of the nodal parameter, and number of bootstrap samples B for the trend test.
Primary results
The element res is a data frame with one row per taxon. For each model coefficient it contains the following columns.
Column prefix
Content
lfc_
Log fold change (natural log)
se_
Standard error
W_
Test statistic, lfc / se
p_, q_
p-value and adjusted p-value
diff_
TRUE if the adjusted p-value is below alpha
passed_ss_
TRUE if the result does not change with the pseudo-count added to zeros
diff_robust_
TRUE if both diff_ and passed_ss_ are TRUE
res <- out$restab_obese <- res |>transmute(taxon,lfc = lfc_bmiobese, se = se_bmiobese, W = W_bmiobese,p = p_bmiobese, q = q_bmiobese,diff = diff_bmiobese, passed_ss = passed_ss_bmiobese,diff_robust = diff_robust_bmiobese) |>arrange(q)knitr::kable(tab_obese, digits =3,caption ="Obese versus lean, adjusted for age and region.")
Obese versus lean, adjusted for age and region.
taxon
lfc
se
W
p
q
diff
passed_ss
diff_robust
Uncultured Clostridiales
-0.415
0.131
-3.160
0.002
0.034
TRUE
TRUE
TRUE
Bacteroidetes
0.423
0.140
3.012
0.003
0.053
FALSE
FALSE
FALSE
Clostridium cluster XI
-0.309
0.112
-2.769
0.006
0.109
FALSE
TRUE
FALSE
Clostridium cluster IX
0.333
0.125
2.675
0.008
0.137
FALSE
TRUE
FALSE
Verrucomicrobia
-0.278
0.118
-2.347
0.019
0.326
FALSE
TRUE
FALSE
Actinobacteria
-0.238
0.129
-1.851
0.065
1.000
FALSE
TRUE
FALSE
Bacilli
-0.128
0.113
-1.126
0.261
1.000
FALSE
TRUE
FALSE
Clostridium cluster I
-0.143
0.099
-1.448
0.148
1.000
FALSE
TRUE
FALSE
Clostridium cluster III
-0.078
0.112
-0.693
0.488
1.000
FALSE
TRUE
FALSE
Clostridium cluster IV
-0.097
0.101
-0.958
0.338
1.000
FALSE
TRUE
FALSE
Clostridium cluster XIII
0.000
0.093
0.000
1.000
1.000
FALSE
TRUE
FALSE
Clostridium cluster XIVa
-0.066
0.101
-0.659
0.510
1.000
FALSE
TRUE
FALSE
Clostridium cluster XV
-0.062
0.100
-0.617
0.538
1.000
FALSE
TRUE
FALSE
Clostridium cluster XVI
-0.104
0.105
-0.995
0.320
1.000
FALSE
TRUE
FALSE
Clostridium cluster XVII
0.253
0.149
1.699
0.090
1.000
FALSE
TRUE
FALSE
Clostridium cluster XVIII
-0.021
0.100
-0.206
0.836
1.000
FALSE
TRUE
FALSE
Cyanobacteria
-0.083
0.170
-0.490
0.625
1.000
FALSE
TRUE
FALSE
Fusobacteria
0.018
0.093
0.190
0.849
1.000
FALSE
TRUE
FALSE
Proteobacteria
0.133
0.101
1.310
0.191
1.000
FALSE
TRUE
FALSE
Spirochaetes
0.196
0.166
1.184
0.239
1.000
FALSE
TRUE
FALSE
Uncultured Mollicutes
-0.108
0.117
-0.924
0.356
1.000
FALSE
TRUE
FALSE
tab_obese |>mutate(taxon =fct_reorder(taxon, lfc)) |>ggplot(aes(x = lfc, y = taxon)) +geom_vline(xintercept =0, linetype ="dashed", color ="grey50") +geom_errorbarh(aes(xmin = lfc -1.96* se, xmax = lfc +1.96* se),height =0, color ="grey40") +geom_point(aes(fill = diff_robust), shape =21, size =3, color ="grey20") +scale_fill_manual(values =c(`TRUE`="#f2775f", `FALSE`="white"),guide ="none") +labs(x ="Log fold change (obese versus lean)", y =NULL) +theme_minimal(base_size =12)
Figure 1: Log fold change (natural log) in absolute abundance, obese versus lean, with 95% confidence intervals. Filled points have an adjusted p-value below 0.05 and passed the sensitivity analysis.
Global test
out$res_global |>arrange(q_val) |> knitr::kable(digits =3, caption ="Global test across the three BMI groups.")
Global test across the three BMI groups.
taxon
W
p_val
q_val
diff_abn
passed_ss
diff_robust_abn
Uncultured Clostridiales
17.291
0.000
0.000
TRUE
TRUE
TRUE
Bacteroidetes
13.142
0.000
0.000
TRUE
TRUE
TRUE
Clostridium cluster XI
7.945
0.001
0.014
TRUE
TRUE
TRUE
Clostridium cluster IX
7.167
0.002
0.029
TRUE
TRUE
TRUE
Verrucomicrobia
5.573
0.008
0.134
FALSE
TRUE
FALSE
Actinobacteria
4.872
0.016
0.252
FALSE
TRUE
FALSE
Bacilli
1.870
0.309
1.000
FALSE
TRUE
FALSE
Clostridium cluster I
2.818
0.121
1.000
FALSE
TRUE
FALSE
Clostridium cluster III
1.418
0.486
1.000
FALSE
TRUE
FALSE
Clostridium cluster IV
2.266
0.209
1.000
FALSE
TRUE
FALSE
Clostridium cluster XIII
0.063
0.123
1.000
FALSE
TRUE
FALSE
Clostridium cluster XIVa
0.449
0.723
1.000
FALSE
TRUE
FALSE
Clostridium cluster XV
0.500
0.787
1.000
FALSE
TRUE
FALSE
Clostridium cluster XVI
1.065
0.691
1.000
FALSE
TRUE
FALSE
Clostridium cluster XVII
3.056
0.096
1.000
FALSE
TRUE
FALSE
Clostridium cluster XVIII
0.052
0.102
1.000
FALSE
TRUE
FALSE
Cyanobacteria
0.263
0.461
1.000
FALSE
TRUE
FALSE
Fusobacteria
0.040
0.078
1.000
FALSE
TRUE
FALSE
Proteobacteria
2.102
0.246
1.000
FALSE
TRUE
FALSE
Spirochaetes
1.429
0.487
1.000
FALSE
TRUE
FALSE
Uncultured Mollicutes
1.939
0.289
1.000
FALSE
TRUE
FALSE
Pairwise directional test
The element res_pair contains the three pairwise comparisons. Columns with the suffix bmioverweight and bmiobese compare each group with lean. Columns with the suffix bmiobese_bmioverweight compare obese with overweight.
pair_long <- out$res_pair |>pivot_longer(-taxon,names_to =c(".value", "comparison"),names_pattern ="^(lfc|se|W|p|q|diff_robust|diff|passed_ss)_(.*)$") |>mutate(comparison =recode(comparison,bmioverweight ="overweight vs lean",bmiobese ="obese vs lean",bmiobese_bmioverweight ="obese vs overweight"))pair_long |>filter(diff) |>select(taxon, comparison, lfc, se, q, passed_ss) |>arrange(q) |> knitr::kable(digits =3,caption ="Pairwise comparisons with an adjusted p-value below 0.05.")
Pairwise comparisons with an adjusted p-value below 0.05.
taxon
comparison
lfc
se
q
passed_ss
Uncultured Clostridiales
overweight vs lean
-0.438
0.124
0.006
TRUE
Bacteroidetes
obese vs overweight
0.587
0.177
0.012
TRUE
Uncultured Clostridiales
obese vs lean
-0.415
0.131
0.019
TRUE
Bacteroidetes
obese vs lean
0.423
0.140
0.031
TRUE
pair_long |>mutate(taxon =fct_rev(factor(taxon))) |>ggplot(aes(x = lfc, y = taxon)) +geom_vline(xintercept =0, linetype ="dashed", color ="grey50") +geom_errorbarh(aes(xmin = lfc -1.96* se, xmax = lfc +1.96* se),height =0, color ="grey40") +geom_point(aes(fill = diff_robust), shape =21, size =2.6, color ="grey20") +scale_fill_manual(values =c(`TRUE`="#f2775f", `FALSE`="white"),guide ="none") +facet_wrap(~ comparison) +labs(x ="Log fold change", y =NULL) +theme_minimal(base_size =12)
Figure 2: Log fold changes (natural log) for the three pairwise comparisons, with 95% confidence intervals. Filled points have an adjusted p-value below 0.05 and passed the sensitivity analysis.
Dunnett-type test
The element res_dunn compares each non-reference group with the reference group (lean). It tests fewer comparisons than the pairwise test.
out$res_dunn |>select(taxon, lfc_bmioverweight, q_bmioverweight, diff_bmioverweight, lfc_bmiobese, q_bmiobese, diff_bmiobese) |>arrange(q_bmiobese) |> knitr::kable(digits =3, caption ="Dunnett-type test against the lean group.")
Dunnett-type test against the lean group.
taxon
lfc_bmioverweight
q_bmioverweight
diff_bmioverweight
lfc_bmiobese
q_bmiobese
diff_bmiobese
Bacteroidetes
-0.164
1
FALSE
0.423
0.056
FALSE
Clostridium cluster IX
0.098
1
FALSE
0.333
0.160
FALSE
Actinobacteria
0.075
1
FALSE
-0.238
1.000
FALSE
Bacilli
0.051
1
FALSE
-0.128
1.000
FALSE
Clostridium cluster I
-0.122
1
FALSE
-0.143
1.000
FALSE
Clostridium cluster III
-0.127
1
FALSE
-0.078
1.000
FALSE
Clostridium cluster IV
-0.134
1
FALSE
-0.097
1.000
FALSE
Clostridium cluster XI
-0.164
1
FALSE
-0.309
1.000
FALSE
Clostridium cluster XIII
-0.020
1
FALSE
0.000
1.000
FALSE
Clostridium cluster XIVa
-0.009
1
FALSE
-0.066
1.000
FALSE
Clostridium cluster XV
-0.049
1
FALSE
-0.062
1.000
FALSE
Clostridium cluster XVI
-0.058
1
FALSE
-0.104
1.000
FALSE
Clostridium cluster XVII
0.164
1
FALSE
0.253
1.000
FALSE
Clostridium cluster XVIII
0.002
1
FALSE
-0.021
1.000
FALSE
Cyanobacteria
-0.061
1
FALSE
-0.083
1.000
FALSE
Fusobacteria
0.000
1
FALSE
0.018
1.000
FALSE
Proteobacteria
0.096
1
FALSE
0.133
1.000
FALSE
Spirochaetes
0.097
1
FALSE
0.196
1.000
FALSE
Uncultured Clostridiales
-0.438
1
FALSE
-0.415
1.000
FALSE
Uncultured Mollicutes
-0.148
1
FALSE
-0.108
1.000
FALSE
Verrucomicrobia
-0.120
1
FALSE
-0.278
1.000
FALSE
Trend test
The log fold changes in res_trend are the estimates under the monotone constraint, so they differ from the unconstrained estimates in res.
out$res_trend |>select(taxon, lfc_bmioverweight, lfc_bmiobese, W, p_val, q_val, diff_abn, passed_ss) |>arrange(q_val) |> knitr::kable(digits =3,caption ="Test of a monotone pattern across lean, overweight, and obese.")
Test of a monotone pattern across lean, overweight, and obese.
taxon
lfc_bmioverweight
lfc_bmiobese
W
p_val
q_val
diff_abn
passed_ss
Bacteroidetes
0.000
0.466
0.466
0.00
0.00
TRUE
TRUE
Clostridium cluster IX
0.098
0.333
0.333
0.00
0.00
TRUE
TRUE
Clostridium cluster XI
-0.164
-0.309
0.309
0.00
0.00
TRUE
TRUE
Uncultured Clostridiales
-0.427
-0.427
0.427
0.00
0.00
TRUE
TRUE
Verrucomicrobia
-0.120
-0.278
0.278
0.01
0.17
FALSE
TRUE
Actinobacteria
0.000
-0.261
0.261
0.06
0.96
FALSE
TRUE
Bacilli
0.000
-0.141
0.141
0.22
1.00
FALSE
TRUE
Clostridium cluster I
-0.122
-0.143
0.143
0.15
1.00
FALSE
TRUE
Clostridium cluster III
-0.103
-0.103
0.103
0.48
1.00
FALSE
TRUE
Clostridium cluster IV
-0.117
-0.117
0.117
0.32
1.00
FALSE
TRUE
Clostridium cluster XIII
-0.011
-0.011
0.011
0.99
1.00
FALSE
TRUE
Clostridium cluster XIVa
-0.009
-0.066
0.066
0.66
1.00
FALSE
TRUE
Clostridium cluster XV
-0.049
-0.062
0.062
0.65
1.00
FALSE
TRUE
Clostridium cluster XVI
-0.058
-0.104
0.104
0.35
1.00
FALSE
TRUE
Clostridium cluster XVII
0.164
0.253
0.253
0.12
1.00
FALSE
TRUE
Clostridium cluster XVIII
0.000
-0.021
0.021
0.98
1.00
FALSE
TRUE
Cyanobacteria
-0.061
-0.083
0.083
0.83
1.00
FALSE
TRUE
Fusobacteria
0.000
0.018
0.018
0.94
1.00
FALSE
TRUE
Proteobacteria
0.096
0.133
0.133
0.18
1.00
FALSE
TRUE
Spirochaetes
0.097
0.196
0.196
0.21
1.00
FALSE
TRUE
Uncultured Mollicutes
-0.129
-0.129
0.129
0.22
1.00
FALSE
TRUE
In this analysis, 4 of the 21 taxa have an adjusted p-value below 0.05 in the trend test.
Bias-corrected abundances
The element bias_correct_log_table contains the log abundances after subtraction of the estimated sample-specific bias. These values are comparable between samples.
The code in this tab is shown for reference and is not executed on this page.
ANCOM-BC2 is available in scikit-bio from version 0.7.4.
pip install scikit-bio
from skbio.stats.composition import ancombc2
The arguments and the structure of the result are listed in the function reference.
The command in this tab is shown for reference and is not executed on this page.
ANCOM-BC2 is an action of the q2-composition plugin, which is included in the QIIME 2 amplicon distribution.
qiime composition ancombc2 --help
The inputs, parameters, and outputs are listed in the plugin reference.
A web tool for this method is in development. This tab will hold its link and a walk-through at release.
Citation
Lin H, Peddada SD. Multigroup analysis of compositions of microbiomes with covariate adjustments and repeated measures. Nature Methods 21:83–91 (2024). doi:10.1038/s41592-023-02092-7
For the Python implementation, also cite: Wu Z, Lin H, Morton JT, Zhu Q. Efficient and scalable Python implementation of ANCOM-BC and ANCOM-BC2 for omics differential abundance testing. Bioinformatics 42(10):btag767 (2026). doi:10.1093/bioinformatics/btag767
Related methods
ANCOM-BC: the two-group method that ANCOM-BC2 extends.