Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/riborings/mediation
https://github.com/riborings/mediation
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/riborings/mediation
- Owner: RiboRings
- Created: 2024-02-22T19:00:54.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-03-10T17:31:29.000Z (8 months ago)
- Last Synced: 2024-03-11T16:55:29.026Z (8 months ago)
- Language: HTML
- Size: 1.24 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mediation Analysis in the miaverse
There are two functions available in the funs.R script:
- `mediate_assay` perfoms mediation analysis for every taxon in an assay of choice or for every component of a reducedDim of choice
- `mediate_coldata` performs mediation analysis for a variable in the colDataIn either case, the treatment and the outcome variables are taken from the colData.
## Prepare for examples
The following code can also be found in the tutorial.R script. Some example output (both statistical tables and plots) are stored in
the results folder.```
library(mia)
library(dplyr)
library(tidyr)
library(mediation)
library(scater)
library(ggplot2)
library(ggrepel)source("./funs.R")
data("enterotype", package = "mia")
tse <- enterotypetse <- tse[ , tse$ClinicalStatus %in% c("healthy", "obese")]
tse <- subsetByPrevalentFeatures(tse,
prevalence = 0.1)tse <- transformAssay(tse, method = "relabundance")
```## Example: alpha diversity as mediator
Here the question is: does shannon diversity mediate the effect of age on clinical status?
```
tse <- estimateDiversity(tse, index = "shannon")med_out <- mediate_coldata(tse,
outcome = "ClinicalStatus",
treatment = "Age",
mediator = "shannon",
family = binomial("logit"),
boot = TRUE, sims = 1000)summary(med_out)
plot(med_out)
```## Example: reduced dimension as mediator
Here the question is: does any of the reduced components mediate the effect of gender on clinical status?
```
tse <- runMDS(tse,
assay.type = "relabundance",
ncomponents = 5)med_df <- mediate_assay(tse,
outcome = "ClinicalStatus",
treatment = "Gender",
dim.type = "MDS",
family = binomial("logit"),
boot = TRUE, sims = 300)p <- ggplot(med_df, aes(x = ACME_estimate,
y = -log10(ACME_pval))) +
geom_point() +
scale_x_continuous(limits = c(-0.11, 0.11)) +
geom_hline(yintercept = -log10(0.05),
linetype = "dashed",
colour = "red") +
geom_text_repel(data = subset(med_df, ACME_pval < 0.05),
aes(label = Mediator),
colour = "black") +
labs(x = "Mediated Effect",
y = "Negative Decadic Logarithm of P-value") +
theme_classic()p
```## Example: taxa in assay as mediator
Here the question is: does any of taxa mediate the effect of age on clinical status?
```
med_df <- mediate_assay(tse,
outcome = "ClinicalStatus",
treatment = "Age",
assay.type = "relabundance",
family = binomial("logit"),
boot = TRUE, sims = 100)p <- ggplot(med_df, aes(x = ACME_estimate,
y = -log10(ACME_pval))) +
geom_point() +
scale_x_continuous(limits = c(-0.05, 0.05)) +
geom_hline(yintercept = -log10(0.05),
linetype = "dashed",
colour = "red") +
geom_text_repel(data = subset(med_df, ACME_pval < 0.05),
aes(label = Mediator),
colour = "black") +
labs(x = "Mediated Effect",
y = "Negative Decadic Logarithm of P-value") +
theme_classic()p
```