-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
142 lines (111 loc) · 5.11 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
title: "multimedia"
output: md_document
---
```{r, echo = FALSE}
knitr::knit_hooks$set(output = multimedia::ansi_aware_handler)
knitr::opts_chunk$set(fig.path = "man/figures/README-")
options(crayon.enabled = TRUE)
set.seed(20240313)
```
# multimedia <img src="man/figures/logo.png" align="right" width="200" alt=""/>
<!-- badges: start -->
[![R-CMD-check](https://github.com/krisrs1128/multimedia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/krisrs1128/multimedia/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/krisrs1128/multimedia/graph/badge.svg?token=XB865GLQ8B)](https://app.codecov.io/github/krisrs1128/multimedia/)
[![Launch binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/krisrs1128/multimedia/main/)
<!-- badges: end -->
`multimedia` is an R package for **multi**modal **media**tion 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:
[Jiang H, Miao X, Thairu MW, Beebe M, Grupe DW, Davidson RJ, Handelsman J, Sankaran K. Multimedia: multimodal mediation analysis of microbiome data. Microbiol Spectr 0:e01131-24.](https://doi.org/10.1128/spectrum.01131-24)
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.
<center>
<img src="man/figures/overview_figure-extended.png" width=400/>
</center>
## Installation
You can install the stable [CRAN version](https://cran.r-project.org/package=multimedia) with:
``` r
install.packages("multimedia")
```
You can install the development version from
[GitHub](https://github.com/krisrs1128/multimedia) with:
``` r
# 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.
```{r, message = FALSE}
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.
```{r}
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.
```{r}
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.
```{r}
direct_effect(model, exper)
indirect_overall(model, exper)
```
The package also includes helpers to visualize and perform inference on these
effects. For example,
```{r, fig.height = 3, fig.width = 6, dpi = 300, out.width=500, fig.align="center", message = FALSE}
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.
```{r}
multimedia(exper, glmnet_model(lambda = .1)) |>
estimate(exper) |>
direct_effect()
```
## Help
We welcome questions and comments about the package either through
[github](https://github.com/krisrs1128/multimedia/issues) or [email](mailto:[email protected]).
```{r, eval = FALSE, include = FALSE}
library(hexSticker)
library(showtext)
img <- "~/Downloads/source.jpeg"
font_add_google("Dosis", "dosis")
sticker(img, package = "multimedia", h_color = "#a92645", h_fill = "#f7f7f7", p_size = 35, p_y = 1.4, s_x = 1, s_y = .75, s_width = .47, p_color = "#0c0c0c", dpi = 500, p_family = "dosis")
usethis::use_logo("multimedia.png")
```
```{r}
sessionInfo()
```