These reseources are intended primarily for the use of my students, but others may find them useful as well.

R packages

There are several R packages that make doing bayesian data analysis in R easier. For an overview see the CRAN Bayesian task view. A few are highlighted below.

Packages maintained by rpruim

CalvinBayes – https://rpruim.github.io/CalvinBayes/

The CalvinBayes package includes data sets (including all the data sets from Kruschke text below) and a collection of utilties to make our Bayesian lives easier. Some of these are modeled after or similar to functions that Kruschke provides in his many R files. Others help smooth over differences that arise when fitting Bayesian models in different ways.

ggformula – https://rpruim.github.io/ggformula/

The ggformula package introduces a family of graphics functions, gf_point(), gf_density(), and so on, bringing the formula interface to ggplot(). This captures and extends the excellent simplicity of the lattice-graphics formula interface, while providing the intuitive “add this component” capabilities of ggplot2 using maggrittr pipes.

Tutorials:

JAGS

According to its development team, JAGS (Just Another Gibbs Sampler) is a program for analysis of Bayesian hierarchical models using Markov Chain Monte Carlo (MCMC) simulation not wholly unlike BUGS. JAGS was written with three aims in mind:

  • To have a cross-platform engine for the BUGS language
  • To be extensible, allowing users to write their own functions, distributions and samplers.
  • To be a platform for experimentation with ideas in Bayesian modelling

There are several packages that facilitate using JAGS in R. For an overview of these packages see Using JAGS via R by Karreth (see also his github page). Here is how the packages are described in this tutorial:

One advantage of R2jags is that JAGS models can be described in R without manually writing them to a file first.

Stan – https://mc-stan.org

According to its development team, Stan® is a state-of-the-art platform for statistical modeling and high-performance statistical computation. Users specify log density functions in Stan’s probabilistic programming language and get:

  • full Bayesian statistical inference with MCMC sampling (NUTS, HMC)
  • approximate Bayesian inference with variational inference (ADVI)
  • penalized maximum likelihood estimation with optimization (L-BFGS)

Stan’s math library provides differentiable probability functions & linear algebra (C++ autodiff). Additional R packages provide expression-based linear modeling, posterior visualization, and leave-one-out cross-validation.

rstan – https://mc-stan.org/rstan

rstan is the R interface to Stan. Several other packages are built on top of it.

bayesplot – http://mc-stan.org/bayesplot/

bayesplot is an R package providing an extensive library of plotting functions for use after fitting Bayesian models (typically with MCMC). Currently bayesplot offers a variety of plots of posterior draws, visual MCMC diagnostics, as well as graphical posterior predictive checking. Additional functionality (e.g. for forecasting/out-of-sample prediction and other inference-related tasks) will be added in future releases.

The plots created by bayesplot are ggplot objects, which means that after a plot is created it can be further customized using the various functions for modifying ggplot objects provided by the ggplot2 or ggformula packages.

shinystan – https://mc-stan.org/shinystan/

shinystan provides immediate, informative, customizable visual and numerical summaries of model parameters and convergence diagnostics for MCMC simulations. The ShinyStan interface is coded primarily in R using the Shiny web application framework and is available via the shinystan R package.

ShinyStan can be used to explore the output of any MCMC program (including but not limited to Stan, JAGS, BUGS, MCMCPack, NIMBLE, emcee, and SAS).

brms

brms is a package built on top of Stan for fitting a wide range of multilevel models using syntax borrowed from lme4.

General

ggmcmc

  • ggs() converts various types of objects produced by Bayesian MCMC algorithms into a tidy data frame suitable for plotting.
  • ggs_*(): a number of functions take the output from ggmcmc() and produce a ggplot2 plot. Examples: ggs_density(), ggs_histogram(), ggs_traceplot(), ….

rethinking

The rethinking package is a companion to Statistical Rethinking by McElreath (see below). It provides a nice interface between Stan and R and many other utilities as well. The package is not on CRAN (only on github), and development seems to have stalled, but you may find it interesting, especially if you use his book.

When I taught in 2017, I created a fork of the package to add a few improvements. My fork is not under active development, but you can still find it at https://github.com/rpruim/rethinking.


Textbooks

Doing Bayesian Data Analysis by John Kruschke

(Re)Doing Bayesian Data Analysis by R Pruim

An online book to accompany the Kruschke text. It will include

  • (I hope nicer) R code for doing things in the book.
  • Additional comments/examples etc.

Statistical Rethinking by McElreath

  • YouTube channel with videos of his lectures. (You see his slides and hear his voice – and sometimes the voices of his students.)

Bayesian Data Analysis by Andrew Gelman et al

  • website
  • This is in some sense the Bible of Bayesian inference. The third edition includes Stan

Implementations of Bayesian algorithms

Stan

Named after Stanislaw Ulam

JAGS

Just Another Gibbs Sampler


RStudio


Articles

Webinars

Other

Distributions and their relationships (Distributionpalooza)