multimedia
multimedia
is an R package for multimodal mediation analysis
of microbiome data. It streamlines data curation, mediation and outcome
model specification, and statistical inference for direct and indirect
effects. By defining causal relationships across data modalities, it can
support principled data integration. You can read more about the package
in our preprint:
The preprint describes the scientific context and interpretation for two of the vignettes in this package. One gives a multi-omics analysis of IBD, and the other describes how to simultaneously model 16S profiles and survey responses in a mindfulness intervention study.
Installation
You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("krisrs1128/multimedia")
Example
Here is a simple example of estimating direct and indirect effects. The
data are randomly generated (no real effects), but we imagine that the
ASV columns mediate the relationship between treatment
and PHQ
. This
is mimics the possibility that the microbiome (ASV = Amplicon Sequence
Variant) mediates the relationship between a treatment and depression
(PHQ = Patient Health Questionnaire). You can find more details in the
random.Rmd
vignette.
The original data here are a SummarizedExperiment
. The package can
also take phyloseq objects and data.frames.
library(multimedia)
demo_joy()
Next, we specify which columns are the treatment, mediators, and
outcomes. Notice that we can use tidyselect
syntax to match multiple
columns.
exper <- mediation_data(demo_joy(), "PHQ", "treatment", starts_with("ASV"))
exper
Next, we fit all mediation analysis components and estimate effects. By default, the package uses linear models – see the vignettes for examples using sparse regression, random forests, and bayesian hierarchical models instead.
model <- multimedia(exper) |>
estimate(exper)
model
In any mediation analysis, there are several types of effects that could
be interesting, each corresponding to different ways of traveling from
the treatment to the outcome in the mediation analysis causal graph. In
the block below, direct_effect
captures treatment effects that bypass
the microbiome; indirect_effect
are effects that are mediated by ASV
relative abundances. Since this example uses a linear model, the effects
are identical for the two indirect settings.
direct_effect(model, exper)
indirect_overall(model, exper)
The package also includes helpers to visualize and perform inference on these effects. For example,
boot <- bootstrap(model, exper, c(direct = direct_effect))
library(ggplot2)
ggplot(boot$direct) +
geom_histogram(aes(direct_effect), bins = 20) +
scale_y_continuous(expand = c(0, 0)) +
theme_classic() +
labs(x = "Direct Effect", y = "Frequency", title = "Bootstrap Distribution")
If we want to use a different type of model, we can just modify the
original multimedia
specification. Below we use a sparse regression
model, which correctly recovers that the direct effects are 0.
multimedia(exper, glmnet_model(lambda = .1)) |>
estimate(exper) |>
direct_effect()
Help
We welcome questions and comments about the package either through github or email.
sessionInfo()