Skip to content

Commit

Permalink
update vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
krisrs1128 committed Mar 16, 2024
1 parent 404ae76 commit 116804a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
21 changes: 20 additions & 1 deletion R/mediation.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ from_summarized_experiment <- function(exper, outcomes, treatments, mediators,
#' Defaults to NULL, in which case the pretreatments slot will remain empty.
#' @return result An object of class `mediation_data`, with separate slots for
#' each of the node types in a mediation analysis diagram.
#' @importFrom phyloseq otu_table
#' @importFrom phyloseq otu_table sample_data
#' @noRd
from_phyloseq <- function(exper, outcomes, treatments, mediators, pretreatments) {
if (attr(otu_table(exper), "taxa_are_rows")) {
Expand Down Expand Up @@ -327,6 +327,25 @@ from_data_frame <- function(df, outcomes, treatments, mediators,
#' @return An object of class `multimedia` encapsulating the full mediation
#' model and data.
#' @seealso multimedia-class
#' @examples
#' exper <- demo_joy() |>
#' mediation_data("PHQ", "treatment", starts_with("ASV"))
#' multimedia(exper)
#'
#' exper <- demo_spline(tau = c(2, 1)) |>
#' mediation_data(starts_with("outcome"), "treatment", "mediator")
#' multimedia(exper)
#'
#' # real data example with a pretreatment variable
#' data(mindfulness)
#' exper <- mediation_data(
#' mindfulness,
#' phyloseq::taxa_names(mindfulness),
#' "treatment",
#' starts_with("mediator"),
#' "subject"
#' )
#' multimedia(exper)
#' @export
multimedia <- function(mediation_data,
outcome_estimator = lm_model(),
Expand Down
20 changes: 20 additions & 0 deletions man/multimedia.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vignettes/IBD.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ plot_mediators(indirect_sorted, samples, treatment = "Study.Group")
```

Finally, we can look at direct effects from this model, which can be compared to
the analogous figure for the sparse regression. Note that now, many outcomes
with exact zeros under treatment have been detected.
the analogous figure for the sparse regression. Now, many outcomes with exact
zeros under treatment have been detected, which is consistent with the the
hurdle model's effectiveness in accurately reflecting features that influence
zero-inflation.

```{r hurdle_direct, fig.width = 6, height = 5}
direct <- direct_effect(model, exper) |>
Expand Down
1 change: 0 additions & 1 deletion vignettes/illustration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ th <- theme_classic() +
legend.box.background = element_rect(fill = "transparent"),
legend.position = "bottom"
)
theme_set(th)
```

Expand Down
5 changes: 1 addition & 4 deletions vignettes/mindfulness.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ th <- theme_classic() +
legend.box.background = element_rect(fill = "transparent"),
legend.position = "bottom"
)
theme_set(th)
```

```{r helpers, include = FALSE}
normalize <- function(x) {
x <- as_tibble(x)
x / rowSums(x)
clr(x / rowSums(x))
}
```

Expand All @@ -69,7 +68,6 @@ other of these possibilities.
library(compositions)
library(ggdist)
library(ggrepel)
library(patchwork)
library(phyloseq)
library(tidyverse)
library(multimedia)
Expand Down Expand Up @@ -262,7 +260,6 @@ ggplot(combined_samples) +
labs(x = "log(Relative Abundance)", y = "Genus", fill = "", col = "") +
facet_grid(~source, scales = "free") +
theme(panel.border = element_rect(fill = NA))
ggsave("~/Downloads/lnm_samples.png", dpi = 400)
```


Expand Down
8 changes: 3 additions & 5 deletions vignettes/random.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ th <- theme_classic() +
legend.box.background = element_rect(fill = "transparent"),
legend.position = "bottom"
)
theme_set(th)
```

Expand Down Expand Up @@ -168,12 +167,11 @@ indirect_pathwise(model, exper)

Effect estimates are rarely enough on their own. We need some uncertainty
assessments to set appropriate expectations. The most straightforward approach
is to use the bootstrap. Each element in `funs` will get its own data.frame
with the bootstrap distribution for that estimator.
is to use the bootstrap. Each function in the third argument, `fs`, will get its
own data.frame with the bootstrap distribution for that estimator.

```{r bootstrap}
funs <- list(direct_effect = direct_effect)
bootstrap(model, exper, funs, B = 100)
bootstrap(model, exper, c(direct_effect = direct_effect))
```

We can also generate synthetic nulls to calibrate selection sets. The third
Expand Down

0 comments on commit 116804a

Please sign in to comment.