| Title: | Creating Volcano Plots from Bayesian Model Posteriors |
|---|---|
| Description: | Bayesian models are used to estimate effect sizes (e.g., gene expression changes, protein abundance differences, drug response effects) while accounting for uncertainty, small sample sizes, and complex experimental designs. However, Bayesian posteriors of models with many parameters are often difficult to interpret at a glance. One way to quickly identify important biological changes based on frequentist analysis are volcano plots (using fold-changes and p-values). Bayesian volcano plots bring together the explicit treatment of uncertainty in Bayesian models and the familiar visualization of volcano plots. |
| Authors: | Katja Danielzik [aut, cre, cph] (ORCID: <https://orcid.org/0009-0007-5021-6212>), Simo Kitanovski [aut, ctb] (ORCID: <https://orcid.org/0000-0003-2909-5376>), Daniel Hoffmann [aut] (ORCID: <https://orcid.org/0000-0003-2973-7869>) |
| Maintainer: | Katja Danielzik <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.1 |
| Built: | 2026-05-28 06:37:56 UTC |
| Source: | https://github.com/katjadanielzik/bayesvolcano |
A data with two columns "parameter" and "label" corresponding to data("posterior")
data("posterior")data("posterior")
"Parameter" refers to column names of posterior "Lable" are the biological entities corresponding to the parameters
Script used to create simulated data #BiocManager::install("MetaboDynamics") library(MetaboDynamics) data("longitudinalMetabolomics_df") library(BayesVolcano) data("posterior")
annotation_df <- as.data.frame(cbind(parameter=colnames(posterior), label=levels(as.factor(longitudinalMetabolomics_df$metabolite)), group=rep(c("A","B")),value=rnorm(98,10,3))) annotation_df$value <- as.numeric(annotation_df$value)
Wrapper function to extract parameter draws from two common Stan interfaces. This function requires the respective stan interface (rstan, brms) package to be installed.
extract_fit(fit, parameter_name)extract_fit(fit, parameter_name)
fit |
|
parameter_name |
A character string of parameter name |
A data frame with one row per MCMC draw and one column per parameter. If multiple parameters, columns are named after the parameter.
# Not run: # fit <- brms::brm(count ~ zAge + zBase * Trt + (1|patient), # data = brms::epilepsy[1:30,], family = poisson()) # posterior <- extract_stan_fit(fit, "b_Intercept") # End(Not run)# Not run: # fit <- brms::brm(count ~ zAge + zBase * Trt + (1|patient), # data = brms::epilepsy[1:30,], family = poisson()) # posterior <- extract_stan_fit(fit, "b_Intercept") # End(Not run)
Plot Bayesian Volcano plot
plot_volcano(result, CrI = FALSE, CrI_width = FALSE, color = NULL)plot_volcano(result, CrI = FALSE, CrI_width = FALSE, color = NULL)
result |
from |
CrI |
Logical. Whether to display the CrI Interval of the parameter |
CrI_width |
Logical. Whether to display the CrI width as point size. |
color |
Column in 'result$result. Can be numerical or character. |
a ggplot2 object
data("posterior") head(posterior) data("annotation_df") head(annotation_df) result <- prepare_volcano_input( posterior = posterior, annotation = annotation_df, ) plot_volcano(result, color = "group", CrI = TRUE, CrI_width = TRUE )data("posterior") head(posterior) data("annotation_df") head(annotation_df) result <- prepare_volcano_input( posterior = posterior, annotation = annotation_df, ) plot_volcano(result, color = "group", CrI = TRUE, CrI_width = TRUE )
A data frame with 98 columns (each indicating posterior samples of the paramter "delta_mu" of one biological entity like e.g. a metabolite) and 1000 rows (the number of total samples (chains*iterations)) of the Bayesian model.
data("posterior")data("posterior")
A data frame with 98 columns (each indicating posterior samples of the paramter "delta_mu" of one biological entity like e.g. a metabolite) and 1000 rows (the number of total samples (chains*iterations)) of the Bayesian model.
Script used to create simulated data #BiocManager::install("MetaboDynamics") library(MetaboDynamics) data("longitudinalMetabolomics_df") fit_dynamics_model(data=longitudinalMetabolomics_df) posterior <- as.data.frame(rstan::extract(fit,pars="euclidean_distance"))
library(stringr) cols <- colnames(posterior)[str_detect(pattern = ".1.2",string=colnames(posterior))] posterior <- posterior[,cols] posterior <- posterior[,-c(1:10,109:118)]
This function has as input posterior draws, calculates pi-values and credible intervals (CrI), and annotates them with biological information (e.g., cell line, time point) based on parameter names and a user-provided annotation data frame. Returns a data frame that is ready for plotting.
prepare_volcano_input(posterior, annotation, null.effect = 0, CrI_level = 0.95)prepare_volcano_input(posterior, annotation, null.effect = 0, CrI_level = 0.95)
posterior |
A data frame of posterior draws (one row per draw) |
annotation |
A data frame with at least one column:
|
null.effect |
Central parameter value corresponding to no effect (default t=0). |
CrI_level |
a scalar between 0 and 1 specifying the mass within the credible interval (default=0.95, i.e. 95% credible interval (CrI)). |
Only returns pi-values and credible intervals for parameters that are in posterior and annotation. For formula see README or Vignette
A list with:
result: A data frame with columns:
parameter: original parameter name
pi.value: calculated pi.value
null.effect: set null effect by user
parameter.median: median posterior parameter value
parameter.low: lower boundary of CrI of parameter value
paramter.high: upper boundary of CrI of parameter value
CrI.width: the absolute distance between parameter.low and parameter.high
CrI.level: CrI_level set by user
label: biological label (e.g., cell.line)
Other columns from annotation (e.g., group, condition)
# Example: Simulate posterior and annotation posterior <- data.frame( doubling.1 = rnorm(1000), doubling.2 = rnorm(1000) ) annotation <- data.frame( parameter = c("doubling.1", "doubling.2"), label = c("cell.line.A", "cell.line.B"), group = c("group1", "group1") ) result <- prepare_volcano_input( posterior = posterior, annotation = annotation, ) head(result$result)# Example: Simulate posterior and annotation posterior <- data.frame( doubling.1 = rnorm(1000), doubling.2 = rnorm(1000) ) annotation <- data.frame( parameter = c("doubling.1", "doubling.2"), label = c("cell.line.A", "cell.line.B"), group = c("group1", "group1") ) result <- prepare_volcano_input( posterior = posterior, annotation = annotation, ) head(result$result)