Skip to contents

Introduction

The BayesPharma package contains a collection of R tools for analyzing pharmacology data using Bayesian statistics and modeling. In comparison to likelihood-based inference, BayesPharma builds on the stan ecosystem and brms package. BayesPharma facilitates applying a principled Bayesian workflow to to fit and analyze several foundational pharmacology models, such as dose-response modeling, modeling Pnear and folding funnels from molecular modeling, and modeling potential docking ‘hit-rate’ curves as a function of dock score from ultra-large library docking (Lyu et al. (2019), Alon et al. (2021)).

Installation

Pre-requisites

Follow the instructions to install rstan

Install BayesPharma

In R do

install.packages("remotes")
remotes::install_github("maomlab/BayesPharma")

Usage

library(tidyverse)
library(BayesPharma)

data <- data.frame(
  response = ...,
  treatment = ...,
  <predictor columns>)

The predictor columns are typically treatment variables like drug or batch variable like well_id.

To use the model to, for example fit a sigmoid agonist model:

model <- BayesPharma::sigmoid_model(
   data = data,
   formula = BayesPharma::sigmoid_agoinst_formula(),
   prior = BayesPharma::sigmoid_agonsit_prior(),
   init = BayesPharma::sigmoid_agonist_init())

Evaluate model fit

Once the model has been fit, to evaluate it

Traceplot

model |> BayesPharma::traceplot()

Basic statistics

model |> posterior::summarize_draws()

Regression plot

model |> BayesPharma::plot_posterior_draws()

Prior densities

model |> BayesPharma::density_distributions()
model |> BayesPharma::posterior_densities()
model |> BayesPharma::prior_posterior_densities()

posterior predictive check

model |> brms::pp_check(type = "dens_overlay", ndraws = 50)

compare model fits

model <- model |> brms::add_loo_criterion()
model_fit_comparison <- brms::compare_models(model, model_alt)