16  Differential prevalence

Differential prevalence analysis (DPA) compares the presence/absence of taxa, instead of their abundances, between groups. Based on recent studies on the classification accuracy of healthy vs. non-healthy individuals, a high proportion of the information in microbiome data seems to be included in the mere presence/absence of taxa (Giliberti et al. 2022; Karwowska et al. 2025). DPA is thus a viable, and even simpler, alternative to differential abundance analysis (DAA, Chapter 15). It has also given replicable results in a benchmark study (Pelto et al. 2025).

Host phenotype classification from human microbiome data is mainly driven by the presence of microbial taxa. Giliberti et al. (2022). PLoS Comput Biol 18:e1010066. doi:10.1371/journal.pcbi.1010066.
Effects of data transformation and model selection on feature importance in microbiome classification data. Karwowska et al. (2025). Microbiome 13. doi:10.1186/s40168-024-01996-6.
Elementary methods provide more replicable results in microbial differential abundance analysis. Pelto et al. (2025). Brief Bioinform 26:130. doi:10.1093/BIB/BBAF130.

Because the detection (observed presence) of a taxon depends on the sequencing depth, DPA should control for it. In this chapter, we show how to perform DPA with logistic regression (Section 16.2), with the Bayesian method DiPPER (Section 16.3) and with Firth logistic regression (Section 16.4).

16.1 Preparing the data

We use the same Tengeler2020 dataset (C Tengeler et al. 2020) as in DAA (Section 15.3.1), and prepare it in the same way: the data is agglomerated to the genus level and filtered by a prevalence threshold of 10%, and we compare the ADHD and control groups while controlling for cohort.

Gut microbiota from persons with attention-deficit/hyperactivity disorder affects the brain in mice. C Tengeler et al. (2020). Microbiome 8:1–14. doi:10.1186/s40168-020-00816-x.
library(mia)
library(knitr)
library(dplyr)

data("Tengeler2020", package = "mia")
tse <- Tengeler2020

# Agglomerate by genus and subset by prevalence
tse <- agglomerateByRank(tse, rank = "Genus")
tse <- addPrevalence(tse)
tse <- subsetBy(tse, rows = prevalence > 0.1)

# Transform patient_status to a factor and set "Control" as the reference level
tse$patient_status <- factor(tse$patient_status, levels = c("Control", "ADHD"))

# We also transform cohort as a factor
tse$cohort <- factor(tse$cohort, levels = c("Cohort_1", "Cohort_2", "Cohort_3"))

16.2 Logistic regression

We show here how to perform differential prevalence analysis (DPA) with logistic regression. We show the case where we compare subjects with and without ADHD while controlling for cohort. Due to the convenient implementation of logistic regression for DPA, we employ here the maaslin3() function from the maaslin3 package (Nickols et al. 2026).

MaAsLin 3: Refining and extending generalized multivariable linear models for meta-omic association discovery. Nickols et al. (2026). Nat Methods 1–11. doi:10.1038/s41592-025-02923-9.

To run the maaslin3() function, we need to provide it with

  • a tse object,
  • a model formula, in this case ~ patient_status + cohort + total, and
  • a folder for output files.

Note that we also control for the sequencing depth/library size/total read count (total) in the analysis. This is because the detection (observed presence) of taxa may depend on the sequencing depth.

library(maaslin3)

# Calculate the sequencing depth (the total number of reads/counts) for each
# sample
tse <- addQC(tse)

# Run maaslin3 with patient_status, cohort and total as the predictor variables
obj_DPA_cov <- maaslin3(
    tse,
    formula = ~ patient_status + cohort + total, # Model formula
    output = "output", # The name of the folder for some output files
    plot_associations = FALSE, # To prevent some unnecessary plots
    plot_summary_plot = FALSE,
    verbosity = "ERROR" # To prevent some unnecessary output
)

Next, we extract the data.frame of results from the list object returned by maaslin3(). We remove the variable total from the output as it is merely a technical covariate that we are not interested in. We also calculate the 95% confidence intervals. Furthermore, as with Maaslin2, we calculate the q-values separately for patient_status and cohort. Lastly, we transform the results to a slightly more convenient format.

# Extract the results and calculate the 95% CIs and q-values
res_DPA_cov <- obj_DPA_cov$fit_data_prevalence$results |>
    filter(name != "total") |>
    mutate(
        ci_lwr = coef - qnorm(.975) * stderr,
        ci_upr = coef + qnorm(.975) * stderr
    ) |>
    group_by(metadata) |>
    mutate(qval = p.adjust(pval_individual, method = "fdr")) |>
    ungroup() |>
    select(feature, name, coef, pval = pval_individual, qval, ci_lwr, ci_upr)

# Print the results for taxa with the smallest p-values for patient_status
res_DPA_cov |>
    filter(name == "patient_statusADHD") |>
    arrange(pval) |>
    head() |>
    kable()
feature name coef pval qval ci_lwr ci_upr
Erysipelatoclostridium patient_statusADHD -2.893 0.0047 0.2107 -4.8980 -0.8881
[Ruminococcus]_gauvreauii_group patient_statusADHD -2.999 0.0168 0.3058 -5.4574 -0.5404
Barnesiella patient_statusADHD 2.026 0.0251 0.3058 0.2529 3.7998
Ruminococcaceae_UCG-014 patient_statusADHD 2.635 0.0345 0.3058 0.1927 5.0778
Catabacter patient_statusADHD 1.915 0.0455 0.3058 0.0384 3.7923
uncultured_1 patient_statusADHD -2.261 0.0538 0.3058 -4.5586 0.0373

The results are in the same format as the DAA results in Section 15.3.3.3. The only difference is that coef now indicates the log-odds ratio for the difference in prevalences. The odds ratios (OR) would thus be calculated as or = exp(coef). Note also that the results are not provided for taxa that were present in all samples (as it is not sensible to analyze presence/absence differences for such taxa).

By examining the results we see that the smallest p-value was observed for genus Erysipelatoclostridium. As the sign of the estimate is negative, it means that the genus is more prevalent in the control group. (This can be seen from the prevalence bars of Erysipelatoclostridium in the strip plots in Figure 15.2.)

16.2.1 With an interaction

Contrary to Maaslin2(), the maaslin3() function also supports the analysis with interaction terms. Therefore, in the analysis with interaction(s), one can just add the interaction term(s) into the model formula by using the standard R syntax, e.g., formula = ~ patient_status + cohort + patient_status:cohort + total or alternatively formula = ~ patient_status * cohort + total.

16.3 DiPPER

DiPPER (Pelto et al. 2026) is a Bayesian method for DPA that connects the logistic regression models of the taxa with a common hierarchical prior. Unlike standard logistic regression, it gives finite estimates even when a taxon is absent from one group, and its results are adjusted for multiple testing without a separate q-value correction. It also supports longitudinal data and works directly with TreeSE.

DiPPER: A Bayesian approach to differential prevalence analysis with applications in microbiome studies. Pelto et al. (2026). arXiv. doi:10.48550/arXiv.2602.05938.

The code below repeats the logistic regression analysis above (Section 16.2). It is not run when the book is built, as DiPPER needs the separately installed CmdStan backend. Instead, the results shown below were computed beforehand with DiPPER 0.99.1 (see inst/scripts/dipper_precompute.R in the book repository). The first term of the formula is the variable of interest.

library(DiPPER)

fit_dipper <- dipper(
    tse = tse,
    assay.type = "counts",
    data.type = "counts", # Presence is defined as a count above zero
    formula = ~ patient_status + cohort,
    read.depth = TRUE # Control for the sequencing depth
)

# Results for patient_status: log-odds ratio estimates, 95% credible
# intervals and pseudo q-values
res_dipper <- summary(fit_dipper)

# Forest plot of the taxa whose credible interval excludes zero
plot(fit_dipper)

The summary() gives log-odds ratio estimates (log_or) with 95% credible intervals (lwr, upr) and a pseudo_q value that resembles a q-value. A taxon is flagged as significant when its credible interval excludes zero.

taxon log_or lwr upr significant pseudo_q
Erysipelatoclostridium -2.425 -4.5574 -0.5926 TRUE 0.0050
[Ruminococcus]_gauvreauii_group -2.337 -5.9601 -0.0465 TRUE 0.0400
Barnesiella 1.619 0.0381 3.5853 TRUE 0.0440
Ruminococcaceae_UCG-014 2.102 0.0041 5.7541 TRUE 0.0500
uncultured_1 -1.964 -5.5956 0.0303 FALSE 0.0580
Clostridium_sensu_stricto_1 -1.918 -5.4017 0.0463 FALSE 0.0615
Forest plot of differential prevalence odds ratios on a log scale with a dashed vertical line at one. Erysipelatoclostridium and the [Ruminococcus] gauvreauii group have odds ratios below one, that is, they are less prevalent in the ADHD group, while Barnesiella and Ruminococcaceae UCG-014 have odds ratios above one.
Figure 16.1: Differential prevalence between the ADHD and control groups estimated with DiPPER, controlling for cohort and sequencing depth. The points are the odds ratio estimates and the lines their 95% credible intervals, shown for the genera whose interval excludes one. Computed beforehand with DiPPER 0.99.1.

As with maaslin3 above, Erysipelatoclostridium has the strongest evidence for a difference in prevalence, and it is less prevalent in the ADHD group (Figure 16.1). See the DiPPER vignette for more information.

16.4 Firth logistic regression

While the maaslin3 package provides a convenient implementation of logistic regression for microbial DPA, we note that it may provide somewhat conservative results, that is, it rarely provides false positive results but it may fail to detect some true effects. To obtain higher statistical power, we recommend using a version of logistic regression introduced by Firth (1993). As there currently exists no convenient implementation of Firth logistic regression for DPA, one needs to use a custom function. Such a custom function with application examples is given in the extra materials.

Bias reduction of maximum likelihood estimates. Firth (1993). Biometrika 80:27. doi:10.2307/2336755.

16.5 Exercises

We use the peerj13075 dataset, as in the exercises of Chapter 15.

Solve the exercises in order, as each exercise continues from the previous one. Try to solve each exercise yourself before opening the solution.

Exercise 1: Prepare the data

Goal: Prepare the data for DPA.

  1. Load the peerj13075 dataset from the mia package and store it in a variable called tse.

  2. Agglomerate the data to genus level with rank = "genus". (Note that the rank names of this dataset are written in lowercase.) Then add the prevalence and keep only the genera that are present in more than 50% of the samples.

  3. Convert the Diet column to a factor and set Mixed as the reference level.

  4. Convert the Geographical_location column to a factor with the levels Pune, Ahmednagar and Nashik, in this order. Pune is then the reference level.

Useful functions: data(), mia::agglomerateByRank(), mia::addPrevalence(), mia::subsetBy(), factor()

library(mia)

# 1. Load the data
data("peerj13075", package = "mia")
tse <- peerj13075

# 2. Agglomerate to genus level and keep prevalent genera
tse <- agglomerateByRank(tse, rank = "genus")
tse <- addPrevalence(tse)
tse <- subsetBy(tse, rows = prevalence > 0.5)

# 3. Set Mixed as the reference level
tse$Diet <- factor(tse$Diet, levels = c("Mixed", "Veg"))

# 4. Set Pune as the reference level
tse$Geographical_location <- factor(
    tse$Geographical_location,
    levels = c("Pune", "Ahmednagar", "Nashik")
)
Exercise 2: Logistic regression

Goal: Compare the presence and absence of taxa between groups with maaslin3().

  1. Calculate the total number of reads in each sample with addQC(). The results are stored in the total column of colData.

  2. Run maaslin3() with tse and the formula ~ Diet + Geographical_location + total. Set output = "output", plot_associations = FALSE, plot_summary_plot = FALSE and verbosity = "ERROR". Store the result in a variable called obj_dpa.

  3. Extract the results of the prevalence model (fit_data_prevalence). Remove the rows for total, add the 95% confidence intervals, calculate the q-values separately for each variable, and keep the columns feature, name, coef, pval (renamed from pval_individual), qval, ci_lwr and ci_upr, as shown in Section 16.2. Store the table in a variable called res_dpa.

  4. Show the six genera with the smallest p-values for DietVeg.

  5. What does coef describe in these results? Why is the total number of reads included in the model? Why are coef and the p-values missing (NA) for some genera?

Useful functions: mia::addQC(), maaslin3::maaslin3(), dplyr::filter(), dplyr::mutate(), stats::qnorm(), dplyr::group_by(), stats::p.adjust(), dplyr::ungroup(), dplyr::select(), dplyr::arrange(), head()

library(maaslin3)
library(dplyr)

# 1. Calculate the total number of reads in each sample
tse <- addQC(tse)

# 2. Run maaslin3 with diet, city and total number of reads
obj_dpa <- maaslin3(
    tse,
    formula = ~ Diet + Geographical_location + total,
    output = "output",
    plot_associations = FALSE,
    plot_summary_plot = FALSE,
    verbosity = "ERROR"
)

# 3. Extract the results of the prevalence model
res_dpa <- obj_dpa$fit_data_prevalence$results |>
    filter(name != "total") |>
    mutate(
        ci_lwr = coef - qnorm(.975) * stderr,
        ci_upr = coef + qnorm(.975) * stderr
    ) |>
    group_by(metadata) |>
    mutate(qval = p.adjust(pval_individual, method = "fdr")) |>
    ungroup() |>
    select(feature, name, coef, pval = pval_individual, qval, ci_lwr, ci_upr)

# 4. Genera with the smallest p-values for diet
res_dpa |>
    filter(name == "DietVeg") |>
    arrange(pval) |>
    head()
##  # A tibble: 6 × 7
##    feature          name      coef    pval  qval ci_lwr ci_upr
##    <chr>            <chr>    <dbl>   <dbl> <dbl>  <dbl>  <dbl>
##  1 Vulgatibacter    DietVeg -2.04  0.00342 0.116  -3.41 -0.674
##  2 Anaeromyxobacter DietVeg -1.70  0.00846 0.144  -2.97 -0.436
##  3 Oceanobacillus   DietVeg -1.66  0.0353  0.400  -3.20 -0.114
##  4 Desulfotomaculum DietVeg -1.33  0.0823  0.700  -2.82  0.170
##  5 Orientia         DietVeg -0.989 0.115   0.717  -2.22  0.239
##  6 Ilumatobacter    DietVeg -0.739 0.197   0.717  -1.86  0.384
  1. In DPA, coef is the log-odds ratio of the presence of the genus between the Veg and Mixed groups. A positive value means that the genus is estimated to be more prevalent in the Veg group, and a negative value that it is less prevalent. The odds ratio is exp(coef).

The more reads a sample has, the more likely it is that a taxon is detected. The total number of reads is therefore included as a technical covariate, so that differences in sequencing depth do not appear as differences in prevalence.

For genera that are present in all samples, coef and the p-values are NA, because their presence and absence does not vary.

Back to top