library(mia)
library(knitr)
library(dplyr)
library(tinytable)
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 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).
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.
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. As it provides a convenient implementation of logistic regression for DPA, we use here the maaslin3() function from the maaslin3 package (Nickols et al. 2026).
To run the maaslin3() function, we need to provide it with
- a
tseobject, - 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. Furthermore, as with Maaslin2, we calculate the q-values (Benjamini and Hochberg 1995) separately for patient_status and cohort. Lastly, we keep the most relevant columns.
# Extract the results and calculate the q-values for each variable
res_DPA_cov <- obj_DPA_cov$fit_data_prevalence$results |>
filter(name != "total") |>
group_by(metadata) |>
mutate(qval = p.adjust(pval_individual, method = "fdr")) |>
ungroup() |>
select(feature, name, coef, stderr, pval = pval_individual, qval)
# Print the results for taxa with the smallest p-values for patient_status
res_DPA_cov |>
filter(name == "patient_statusADHD") |>
arrange(pval) |>
head() |>
tt() |>
format_tt(digits = 3, num_fmt = "significant_cell")| feature | name | coef | stderr | pval | qval |
|---|---|---|---|---|---|
| Eubacterium | patient_statusADHD | -5.35 | 1.49 | 0.000347 | 0.0156 |
| Dielma | patient_statusADHD | -4.66 | 1.45 | 0.00132 | 0.0172 |
| [Eubacterium]_rectale_group | patient_statusADHD | -4.59 | 1.44 | 0.00146 | 0.0172 |
| Ruminococcaceae_UCG-004 | patient_statusADHD | 4.64 | 1.47 | 0.00153 | 0.0172 |
| Ruminococcus_1 | patient_statusADHD | -3.05 | 0.998 | 0.00226 | 0.0186 |
| Anaerotruncus | patient_statusADHD | -4.71 | 1.58 | 0.00293 | 0.0186 |
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 Eubacterium. 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 Eubacterium 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.
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 |
|---|---|---|---|---|---|
| Eubacterium | -12.2 | -25.7 | -5.87 | TRUE | 0.000125 |
| Dielma | -7.93 | -16 | -3.87 | TRUE | 0.000125 |
| [Eubacterium]_rectale_group | -7.39 | -15.7 | -3.72 | TRUE | 0.000125 |
| Anaerotruncus | -5.86 | -13.6 | -2.42 | TRUE | 0.000125 |
| Holdemania | -5.83 | -13.6 | -2.29 | TRUE | 0.000125 |
| [Eubacterium]_coprostanoligenes_group | -5.33 | -13.3 | -1.88 | TRUE | 0.000125 |
As with maaslin3 above, Eubacterium is less prevalent in the ADHD group, and it has the largest estimated difference in prevalence (Figure 16.1). Note that DiPPER flags more genera than maaslin3 here. 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.
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.