Skip to content

Commit

Permalink
add sensitivity analysis to IBD example
Browse files Browse the repository at this point in the history
  • Loading branch information
krisrs1128 committed Aug 29, 2024
1 parent c6b6a0e commit 0201a90
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
20 changes: 20 additions & 0 deletions R/sensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,26 @@ covariance_matrix <- function(model, confound_ix = NULL, rho = 0.0) {
#' @param progress A logical indicating whether to show a progress bar.
#' @return A `date.frame` giving the outputs of `indirect_overall` across many
#' values of the correlation rho.
#' @examples
#' xy_data <- demo_spline()
#' exper <- mediation_data(
#' xy_data, starts_with("outcome"), "treatment", "mediator"
#' )
#' model <- multimedia(
#' exper,
#' outcome_estimator = glmnet_model(lambda = 1e-2)
#' ) |>
#' estimate(exper)
#' rho_seq <- c(-0.2, 0.2)
#' perturb <- matrix(
#' c(
#' 0, 3, 0,
#' 3, 0, 0,
#' 0, 0, 0
#' ),
#' nrow = 3, byrow = TRUE
#' )
#' sensitivity_perturb(model, exper, perturb, n_bootstrap = 2)
#' @export
sensitivity_perturb <- function(
model, exper, perturb, nu_seq = NULL, n_bootstrap = 100, progress = TRUE) {
Expand Down
21 changes: 21 additions & 0 deletions man/sensitivity_perturb.Rd

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

17 changes: 14 additions & 3 deletions vignettes/IBD.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ ggplot(coords) +
facet_wrap(~ type + reorder(outcome, -abundance))
```

```{r}
confound_ix <- data.frame(
outcome = vis_outcomes,
mediator = "gEnterocloster"
)
sensitivity_overall <- sensitivity(model, exper, confound_ix)
saveRDS(sensitivity_overall, "~/Downloads/sensitivity_overall-IBD.rds")
```

Pathwise indirect effects are those that appear when modifying the treatment
status for a single mediator. Unlike overall indirect effects, they give us
effects for individual mediator-outcome pairs. Now, instead of averaging over
Expand Down Expand Up @@ -387,11 +396,13 @@ p1 | p2
```{r}
confound_ix <- data.frame(
mediator = c("gEnterocloster", "gEnterocloster", "gCAG103"),
outcome = c("m1129_chenodeoxycholate", "m1403_cholate", "m0900_ketodeoxycholate")
outcome = c(
"m1129_chenodeoxycholate", "m1403_cholate", "m0900_ketodeoxycholate"
)
)
rho_seq <- seq(-0.7, 0.7, length.out = 2)
sensitivity_analysis <- sensitivity_pathwise(model, exper, confound_ix)#, rho_seq = rho_seq)
sensitivity_pathwise <- sensitivity_pathwise(model, exper, confound_ix)
saveRDS(sensitivity_pathwise, "~/Downloads/sensitivity_pathwise-IBD.rds")
```

# Hurdle-Lognormal Approach
Expand Down

0 comments on commit 0201a90

Please sign in to comment.