Skip to content

Commit

Permalink
Merge pull request #101 from shirmath/main
Browse files Browse the repository at this point in the history
add plotting demo to radEmu vignettes
  • Loading branch information
svteichman authored Dec 3, 2024
2 parents 49b50dc + 94c4731 commit 9c536e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 40 deletions.
39 changes: 19 additions & 20 deletions vignettes/intro_radEmu.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,29 @@ ch_fit
```


The way to access estimated coefficients and confidence intervals from the model is with `ch_fit$coef`. Let's plot our results:

```{r, fig.width= 7, fig.height = 4}
ch_df <- ch_fit$coef %>%
mutate(Genus = (mOTU_name_df %>%
filter(genus_name %in% chosen_genera) %>%
pull(genus_name))[-category_to_rm]) %>%
# add genus name to output from emuFit

Now, we can easily visualize our results using the `plot` function!
So that we only produce the plot, and not the dataframe used to produce the plots,
we will explicitly extract the plots using the `$` operator to get the `plots` component.

```{r, fig.height = 6, fig.width = 6}
plot(ch_fit)$plots
```

In the plot above, it is a bit difficult to read the taxa names on the y-axis. We can create a data frame that maps the full taxa names in our data to simplified labels and plot using those instead, as shown below.
```{r, fig.height = 6, fig.width = 6}
#create data frame that has simplified names for taxa
taxa_names <- data.frame("category" = ch_fit$coef$category) %>%
mutate(cat_small = stringr::str_remove(paste0("mOTU_",
stringr::str_split(category, 'mOTU_v2_', simplify = TRUE)[, 2]),
"\\]")) %>%
mutate(cat_small = factor(cat_small, levels = cat_small[order(Genus)]))
# reorder mOTU categories by genus
ggplot(ch_df) +
geom_point(aes(x = cat_small, y = estimate,color = Genus), size = .5) +
geom_errorbar(aes(x = cat_small, ymin = lower, ymax = upper, color = Genus), width = .25) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "Category",
y = "Estimate") +
coord_cartesian(ylim = c(-5,10))
"\\]"))
#produce plot with cleaner taxa labels
plot(ch_fit, taxon_names = taxa_names)$plots
```


Interestingly, we estimate a meta-mOTU "unknown Eubacterium [meta_mOTU_v2_7116]" assigned to Eubacteria to have a much higher ratio of abundance (comparing CRC group to control) than is typical across the mOTUs we included in this analysis.

The confidence interval for this effect does not include zero -- but (!!!) the kind of confidence interval that is returned by default by emuFit is not extremely reliable when counts are very skewed or sample size is small-to-moderate.
Expand Down
26 changes: 6 additions & 20 deletions vignettes/intro_radEmu_with_phyloseq.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,12 @@ ch_fit <- emuFit(formula = ~ Group,
run_score_tests = FALSE)
```

The way to access estimated coefficients and confidence intervals from the model is with `ch_fit$coef`. Let's plot our results:

```{r, fig.width= 7, fig.height = 4, eval = phy}
ch_df <- ch_fit$coef %>%
mutate(Genus = as.vector(phyloseq::tax_table(wirbel_china)[, 6])) %>%
# add genus name to output from emuFit
mutate(cat_small = stringr::str_remove(paste0("mOTU_",
stringr::str_split(category, 'mOTU_v2_', simplify = TRUE)[, 2]),
"\\]")) %>%
mutate(cat_small = factor(cat_small, levels = cat_small[order(Genus)]))
# reorder mOTU categories by genus
ggplot(ch_df) +
geom_point(aes(x = cat_small, y = estimate, color = Genus), size = .5) +
geom_errorbar(aes(x = cat_small, ymin = lower, ymax = upper, color = Genus), width = .25) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "Category",
y = "Estimate") +
coord_cartesian(ylim = c(-5,10))
The way to access estimated coefficients and confidence intervals from the model is with `ch_fit$coef`.

Now, we can easily visualize our results using the `plot.emuFit` function!

```{r, fig.height = 6, fig.width = 6}
plot(ch_fit)$plots
```

If you'd like to see more explanations of the `radEmu` software and additional analyses of this data, check out the vignette "intro_radEmu.Rmd".

0 comments on commit 9c536e8

Please sign in to comment.