Bayesian Workflow book: Case studies

Published

2026-02-26

Modified

2026-04-07

Introduction

The code and data are provided to fully reproduce the examples and figures in the book. They can be a good way to see what the code does. Different people have different styles of code and we don’t claim our style is the best.

When running the notebooks, to avoid the need to switch the working directory, the rprojroot package is used to set the project root directory. The downloaded git repository can be placed anywhere you like and you can rename the Bayesian-Workflow directory if you wish. When running the code, it is sufficient that the working directory is any directory in the Bayesian-Workflow (or renamed). Running

library("rprojroot")
root<-has_file(".Bayesian-Workflow-root")$make_fix_file()

will find the file .Bayesian-Workflow-root which is in the Bayesian-Workflow directory, and will set the full path according to that. Then, for example,

bioassay_stan_file <- root("bioassay","bioassay0.stan")

finds the bioassay0.stan file, no matter where you have placed or renamed the Bayesian-Workflow directory. When you switch to another example, there is no need to switch the working directory.

Case studies

Software versions

We list here all the software packages used in the case studies and the versions used when rendering the case study web pages 2026-01-08.

Package Version Description
arm 1.14-4 Functions to accompany A. Gelman and J. Hill, Data Analysis Using Regression and Multilevel/Hierarchical Models, Cambridge University Press, 2007.
assertthat 0.2.1 An extension to stopifnot() that makes it easy to declare the pre and post conditions that you code should satisfy, while also producing friendly error messages so that your users know what's gone wrong.
bayesplot 1.15.0.9000 Plotting functions for posterior analysis, MCMC diagnostics, prior and posterior predictive checks, and other visualizations to support the applied Bayesian workflow advocated in Gabry, Simpson, Vehtari, Betancourt, and Gelman (2019)
boot 1.3-31 Functions and datasets for bootstrapping from the book "Bootstrap Methods and Their Application" by A. C. Davison and D. V. Hinkley (1997, CUP), originally written by Angelo Canty for S.
bridgesampling 1.2-1 Provides functions for estimating marginal likelihoods, Bayes factors, posterior model probabilities, and normalizing constants in general, via different versions of bridge sampling (Meng & Wong, 1996,
brms 2.23.1 Fit Bayesian generalized (non-)linear multivariate multilevel models using 'Stan' for full Bayesian inference.
CircStats 0.2-7 Circular Statistics, from "Topics in Circular Statistics" (2001) S. Rao Jammalamadaka and A. SenGupta, World Scientific.
CmdStan 2.39.0 The command-line interface to Stan.
cmdstanr 0.9.0.9000 A lightweight interface to 'Stan'
doFuture 1.1.2 The 'future' package provides a unifying parallelization framework for R that supports many parallel and distributed backends . The 'foreach' package provides a powerful API for iterating over an R expression in parallel.
doRNG 1.8.6.2 Provides functions to perform reproducible parallel foreach loops, using independent random streams as generated by L'Ecuyer's combined multiple-recursive generator [L'Ecuyer (1999),
dplyr 1.2.0 A fast, consistent tool for working with data frame like objects, both in memory and out of memory.
future 1.68.0 The purpose of this package is to provide a lightweight and unified Future API for sequential and parallel processing of R expression via futures.
ggdist 3.3.3 Provides primitives for visualizing distributions using 'ggplot2' that are particularly tuned for visualizing uncertainty in either a frequentist or Bayesian mode.
ggh4x 0.3.1 A 'ggplot2' extension that does a variety of little helpful things.
ggplot2 4.0.1 A system for 'declaratively' creating graphics, based on "The Grammar of Graphics". You provide the data, tell 'ggplot2' how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.
ggrepel 0.9.6 Provides text and label geoms for 'ggplot2' that help to avoid overlapping text labels.
ggsurvfit 1.2.0 Ease the creation of time-to-event (i.e. survival) endpoint figures.
Iso 0.0-21 Linear order and unimodal order (univariate) isotonic regression; bivariate isotonic regression with linear order on both variables.
khroma 1.16.0 Color schemes ready for each type of data (qualitative, diverging or sequential), with colors that are distinct for all people, including color-blind readers.
latex2exp 0.9.6 Parses and converts LaTeX math formulas to R's plotmath expressions, used to enter mathematical formulas and symbols to be rendered as text, axis labels, etc.
lme4 1.1-38 Fit linear and generalized linear mixed-effects models.
loo 2.9.0 Efficient approximate leave-one-out cross-validation (LOO) for Bayesian models fit using Markov chain Monte Carlo, as described in Vehtari, Gelman, and Gabry (2017) . The approximation uses Pareto smoothed importance sampling (PSIS), a new procedure for regularizing importance weights.
lubridate 1.9.4 Functions to work with date-times and time-spans: fast and user friendly parsing of date-time data, extraction and updating of components of a date-time (years, months, days, hours, minutes, and seconds), algebraic manipulation on date-time and time-span objects.
marginaleffects 0.30.0.4 Compute and plot predictions, slopes, marginal means, and comparisons (contrasts, risk ratios, odds, etc.
MASS 7.3-65 Functions and datasets to support Venables and Ripley, "Modern Applied Statistics with S" (4th edition, 2002).
matrixStats 1.5.0 High-performing functions operating on rows and columns of matrices, e.g. col / rowMedians(), col / rowRanks(), and col / rowSds().
modelr 0.1.11 Functions for modelling that help you seamlessly integrate modelling into a pipeline of data manipulation and visualisation.
moveHMM 1.12 Provides tools for animal movement modelling using hidden Markov models.
mvtnorm 1.3-3 Computes multivariate normal and t probabilities, quantiles, random deviates, and densities.
patchwork 1.3.1 The 'ggplot2' package provides a strong API for sequentially building up a plot, but does not concern itself with composition of multiple plots.
pillar 1.11.1 Provides 'pillar' and 'colonnade' generics designed for formatting columns of data using the full range of colours provided by modern terminals.
plyr 1.8.9 A set of tools that solves a common set of problems: you need to break a big problem down into manageable pieces, operate on each piece and then put all the pieces back together.
posterior 1.6.1.9000 Provides useful tools for both users and developers of packages for fitting Bayesian models or working with output from Bayesian models.
priorsense 1.1.1.9000 Provides functions for prior and likelihood sensitivity analysis in Bayesian models.
progressr 0.15.1 A minimal, unifying API for scripts and packages to report progress updates from anywhere including when using parallel processing.
projpred 2.9.0 Performs projection predictive feature selection for generalized linear models (Piironen, Paasiniemi, and Vehtari, 2020, ) with or without multilevel or additive terms (Catalina, Bürkner, and Vehtari, 2022,
RColorBrewer 1.1-3 Provides color schemes for maps (and other graphics) designed by Cynthia Brewer as described at http://colorbrewer2.org.
readr 2.1.5 The goal of 'readr' is to provide a fast and friendly way to read rectangular data (like 'csv', 'tsv', and 'fwf').
reliabilitydiag 0.2.1 Checking the reliability of predictions via the CORP approach, which generates provably statistically 'C'onsistent, 'O'ptimally binned, and 'R'eproducible reliability diagrams using the 'P'ool-adjacent-violators algorithm.
rethinking 2.21 Utilities for fitting and comparing models
rjson 0.2.23 Converts R object into JSON objects and vice-versa.
rprojroot 2.1.1 Robust, reliable and flexible paths to files below a project root.
rstan 2.36.0.9000 User-facing R functions are provided to parse, compile, test, estimate, and analyze Stan models by accessing the header-only Stan library provided by the 'StanHeaders' package.
rstanarm 2.32.2 Estimates previously compiled regression models using the 'rstan' package, which provides the R interface to the Stan C++ library for Bayesian estimation.
rstantools 2.6.0.9000 Provides various tools for developers of R packages interfacing with 'Stan'
SBC 0.5.0.9000 SBC helps perform Simulation Based Calibration on Bayesian models.
scales 1.4.0 Graphical scales map data to aesthetics, and provide methods for automatically determining breaks and labels for axes and legends.
stringr 1.6.0 A consistent, simple and easy to use set of wrappers around the fantastic 'stringi' package.
survival 3.8-3 Contains the core survival analysis routines, including definition of Surv objects, Kaplan-Meier and Aalen-Johansen (multi-state) curves, Cox models, and parametric accelerated failure time models.
tibble 3.3.1 Provides a 'tbl_df' class (the 'tibble') with stricter checking and better formatting than the traditional data frame.
tictoc 1.2.1 Code execution timing functions 'tic' and 'toc' that can be nested.
tidybayes 3.0.7 Compose data for and extract, manipulate, and visualize posterior draws from Bayesian models ('JAGS', 'Stan', 'rstanarm', 'brms', 'MCMCglmm', 'coda', ...) in a tidy data format.
tidyr 1.3.2 Tools to help to create tidy data, where each column is a variable, each row is an observation, and each cell contains a single value.
tidyverse 2.0.0 The 'tidyverse' is a set of packages that work in harmony because they share common data representations and 'API' design.
tinytable 0.15.2 Create highly customized tables with this simple and dependency-free package.