Skip to main content

ANCOM-BC2

Differential abundance analysis for multiple groups, with covariate adjustment and repeated measures.

Microbiome differential abundance released R Python QIIME 2

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.

Platforms

Platform Package Install Documentation
R ANCOMBC (Bioconductor) BiocManager::install("ANCOMBC") Vignette · GitHub
Python scikit-bio (version 0.7.4 or later) pip install scikit-bio skbio.stats.composition.ancombc2
QIIME 2 q2-composition Included in the QIIME 2 amplicon distribution qiime composition ancombc2 · GitHub

Extended tutorial

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.

Select a platform.

Model and hypotheses

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

\[ \log o_{ij} = d_j + \mathbf{x}_j^\top \boldsymbol{\beta}_i + \varepsilon_{ij}, \]

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.

Test Null hypothesis Alternative
Primary \(\beta_{ik} = 0\) for one coefficient \(k\) \(\beta_{ik} \neq 0\)
Global \(\beta_{i,\mathrm{ow}} = \beta_{i,\mathrm{ob}} = 0\) at least one is nonzero
Pairwise directional equal abundance in a pair of groups, for every pair a difference with its direction
Dunnett type equal abundance in a group and the reference, for every non-reference group a difference with its direction
Trend \(\beta_{i,\mathrm{ow}} = \beta_{i,\mathrm{ob}} = 0\) a monotone pattern across the ordered groups

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) <- meta
tse <- mia::convertFromPhyloseq(pseq)
tse
#> class: TreeSummarizedExperiment 
#> dim: 130 1006 
#> metadata(0):
#> assays(1): counts
#> rownames(130): Actinomycetaceae Aerococcus ... Xanthomonadaceae
#>   Yersinia et rel.
#> rowData names(3): Phylum Family Genus
#> colnames(1006): Sample-1 Sample-2 ... Sample-1005 Sample-1006
#> colData names(12): age sex ... bmi region
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: NULL
#> rowTree: NULL
#> colLinks: NULL
#> colTree: NULL

Analysis

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.

increasing <- matrix(c( 1, 0,
                       -1, 1), nrow = 2, byrow = TRUE)
decreasing <- matrix(c(-1,  0,
                        1, -1), nrow = 2, byrow = TRUE)
set.seed(123)
out <- ancombc2(data = tse, assay_name = "counts", tax_level = "Family",
                fix_formula = "age + region + bmi", rand_formula = NULL,
                p_adj_method = "holm", pseudo_sens = TRUE,
                prv_cut = 0.10, lib_cut = 1000, s0_perc = 0.05,
                group = "bmi", struc_zero = TRUE, neg_lb = TRUE,
                alpha = 0.05, n_cl = 2, verbose = FALSE,
                global = TRUE, pairwise = TRUE, dunnet = TRUE, trend = TRUE,
                iter_control = list(tol = 1e-2, max_iter = 20, verbose = FALSE),
                em_control = list(tol = 1e-5, max_iter = 100),
                lme_control = lme4::lmerControl(),
                mdfdr_control = list(fwer_ctrl_method = "holm", B = 100),
                trend_control = list(contrast = list(increasing, decreasing),
                                     node = list(2, 2),
                                     solver = "ECOS", B = 100))
Argument Role
fix_formula, rand_formula Fixed and random effects of the log-linear model.
group 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$res

tab_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.

round(out$bias_correct_log_table[1:5, 1:4], 2)
#>                         Sample-1 Sample-2 Sample-3 Sample-4
#> Actinobacteria              0.84     0.11     0.73     0.08
#> Bacilli                    -0.13    -0.01    -0.43    -0.22
#> Bacteroidetes              -0.28     0.54    -0.43     0.62
#> Clostridium cluster I      -0.20     0.61     1.38    -0.53
#> Clostridium cluster III     0.98     0.09    -0.17     0.21

Session information

Code
sessionInfo()
#> R version 4.5.3 (2026-03-11)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS Sequoia 15.7.2
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1
#> 
#> locale:
#> [1] en_US/C.UTF-8/en_US/C/en_US/en_US
#> 
#> time zone: America/New_York
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] lubridate_1.9.5 forcats_1.0.1   stringr_1.6.0   dplyr_1.2.0    
#>  [5] purrr_1.2.1     readr_2.2.0     tidyr_1.3.2     tibble_3.3.1   
#>  [9] ggplot2_4.0.2   tidyverse_2.0.0 ANCOMBC_2.15.1 
#> 
#> loaded via a namespace (and not attached):
#>   [1] splines_4.5.3                   cellranger_1.1.0               
#>   [3] DirichletMultinomial_1.52.0     rpart_4.1.24                   
#>   [5] lifecycle_1.0.5                 Rdpack_2.6.6                   
#>   [7] doParallel_1.0.17               lattice_0.22-9                 
#>   [9] MASS_7.3-65                     MultiAssayExperiment_1.36.1    
#>  [11] backports_1.5.0                 magrittr_2.0.4                 
#>  [13] Hmisc_5.2-5                     rmarkdown_2.30                 
#>  [15] yaml_2.3.12                     otel_0.2.0                     
#>  [17] doRNG_1.8.6.3                   gld_2.6.8                      
#>  [19] DBI_1.3.0                       minqa_1.2.8                    
#>  [21] RColorBrewer_1.1-3              ade4_1.7-23                    
#>  [23] multcomp_1.4-30                 abind_1.4-8                    
#>  [25] Rtsne_0.17                      expm_1.0-0                     
#>  [27] quadprog_1.5-8                  GenomicRanges_1.62.1           
#>  [29] fillpattern_1.0.3               BiocGenerics_0.56.0            
#>  [31] phyloseq_1.54.2                 yulab.utils_0.2.4              
#>  [33] nnet_7.3-20                     TH.data_1.1-5                  
#>  [35] rappdirs_0.3.4                  sandwich_3.1-1                 
#>  [37] IRanges_2.44.0                  S4Vectors_0.48.0               
#>  [39] ggrepel_0.9.7                   irlba_2.3.7                    
#>  [41] tidytree_0.4.7                  vegan_2.7-3                    
#>  [43] microbiome_1.32.0               rbiom_2.2.1                    
#>  [45] parallelly_1.46.1               DelayedMatrixStats_1.32.0      
#>  [47] permute_0.9-10                  codetools_0.2-20               
#>  [49] DelayedArray_0.36.0             xml2_1.5.2                     
#>  [51] ggtext_0.1.2                    scuttle_1.20.0                 
#>  [53] energy_1.7-12                   tidyselect_1.2.1               
#>  [55] farver_2.1.2                    lme4_2.0-1                     
#>  [57] ScaledMatrix_1.18.0             viridis_0.6.5                  
#>  [59] matrixStats_1.5.0               stats4_4.5.3                   
#>  [61] base64enc_0.1-6                 Seqinfo_1.0.0                  
#>  [63] jsonlite_2.0.0                  BiocNeighbors_2.4.0            
#>  [65] multtest_2.66.0                 e1071_1.7-17                   
#>  [67] decontam_1.30.0                 mia_1.18.0                     
#>  [69] Formula_1.2-5                   emmeans_2.0.2                  
#>  [71] survival_3.8-6                  scater_1.38.0                  
#>  [73] iterators_1.0.14                systemfonts_1.3.2              
#>  [75] foreach_1.5.2                   ggnewscale_0.5.2               
#>  [77] tools_4.5.3                     ragg_1.5.1                     
#>  [79] treeio_1.34.0                   DescTools_0.99.60              
#>  [81] Rcpp_1.1.1                      glue_1.8.0                     
#>  [83] BiocBaseUtils_1.12.0            gridExtra_2.3                  
#>  [85] SparseArray_1.10.9              xfun_0.56                      
#>  [87] mgcv_1.9-4                      MatrixGenerics_1.22.0          
#>  [89] TreeSummarizedExperiment_2.18.0 withr_3.0.2                    
#>  [91] numDeriv_2016.8-1.1             fastmap_1.2.0                  
#>  [93] bluster_1.20.0                  boot_1.3-32                    
#>  [95] rhdf5filters_1.22.0             digest_0.6.39                  
#>  [97] rsvd_1.0.5                      estimability_1.5.1             
#>  [99] timechange_0.4.0                R6_2.6.1                       
#> [101] textshaping_1.0.5               colorspace_2.1-2               
#> [103] gtools_3.9.5                    generics_0.1.4                 
#> [105] DECIPHER_3.6.0                  data.table_1.18.2.1            
#> [107] class_7.3-23                    httr_1.4.8                     
#> [109] htmlwidgets_1.6.4               S4Arrays_1.10.1                
#> [111] pkgconfig_2.0.3                 gtable_0.3.6                   
#> [113] Exact_3.3                       S7_0.2.1                       
#> [115] SingleCellExperiment_1.32.0     XVector_0.50.0                 
#> [117] htmltools_0.5.9                 biomformat_1.38.0              
#> [119] scales_1.4.0                    Biobase_2.70.0                 
#> [121] lmom_3.2                        reformulas_0.4.4               
#> [123] knitr_1.51                      rstudioapi_0.18.0              
#> [125] tzdb_0.5.0                      reshape2_1.4.5                 
#> [127] coda_0.19-4.1                   checkmate_2.3.4                
#> [129] nlme_3.1-168                    nloptr_2.2.1                   
#> [131] proxy_0.4-29                    zoo_1.8-15                     
#> [133] rhdf5_2.54.1                    rootSolve_1.8.2.4              
#> [135] parallel_4.5.3                  vipor_0.4.7                    
#> [137] foreign_0.8-91                  pillar_1.11.1                  
#> [139] grid_4.5.3                      vctrs_0.7.1                    
#> [141] slam_0.1-55                     BiocSingular_1.26.0            
#> [143] beachmat_2.26.0                 xtable_1.8-8                   
#> [145] cluster_2.1.8.2                 beeswarm_0.4.0                 
#> [147] htmlTable_2.4.3                 evaluate_1.0.5                 
#> [149] mvtnorm_1.3-5                   cli_3.6.5                      
#> [151] compiler_4.5.3                  rlang_1.1.7                    
#> [153] crayon_1.5.3                    rngtools_1.5.2                 
#> [155] labeling_0.4.3                  plyr_1.8.9                     
#> [157] fs_1.6.7                        ggbeeswarm_0.7.3               
#> [159] stringi_1.8.7                   viridisLite_0.4.3              
#> [161] BiocParallel_1.44.0             lmerTest_3.2-1                 
#> [163] Biostrings_2.78.0               gsl_2.1-9                      
#> [165] lazyeval_0.2.2                  Matrix_1.7-4                   
#> [167] patchwork_1.3.2                 hms_1.1.4                      
#> [169] sparseMatrixStats_1.22.0        Rhdf5lib_1.32.0                
#> [171] SummarizedExperiment_1.40.0     haven_2.5.5                    
#> [173] rbibutils_2.4.1                 gridtext_0.1.6                 
#> [175] igraph_2.2.2                    readxl_1.4.5                   
#> [177] ape_5.8-1

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