Lab 0: Installing software

Applied Bayesian Modeling (ICPSR Summer Program 2025)
Author
Affiliation

Ursinus College

Published

July 20, 2025

Overview

The purpose of this document is to list all software required throughout this workshop and guide participants through installation. We will generally proceed in the following order:

  1. Install R (or update your current installation)
  2. Install RStudio (or update your current installation)
  3. Install Stan (via RStan, will also look at CmdStanR later)
  4. Install rstanarm and brms
  5. Install other R packages

Installing R and RStudio

The most recent version of R for all operating systems is always located at http://www.r-project.org/index.html. Go directly to https://cloud.r-project.org, and download the latest version of R for your operating system. Then, install R.

Installing RStudio

To operate R, you will rely on writing R scripts. We will write these scripts in RStudio. Download the latest version of RStudio from https://posit.co/download/rstudio-desktop/. Then, install it on your computer.

Caution

Please stop here until we discuss installing Stan as a group.

Installing Stan

Stan is a powerful and fast-growing tool for Bayesian estimation, and currently the most popular platform for this purpose. The Stan developers have created interfaces for different statistical software packages (such as R, Python, and others). We will first be installing the RStan interface for R. To do this, follow the instructions at https://mc-stan.org/install/:

  • Under “Download and Install Stan”, choose your OS and then the appropriate configuration for “RStan”
  • Scroll to the section “Prerequisite: C++17 Toolchain”
  • Follow the guidance for your operating system
  • Check your installation by copying & pasting the following code into your R console:
Code
example(stan_model, package = "rstan", run.dontrun = TRUE)
  • You will see several hundred lines of code pop up in your console, but that’s fine. If you see something similar to the following output at the end, your installation of RStan is working.

Installing rstanarm and brms

You can now install two higher-level R packages that allow you to use RStan without writing Stan code. For much of our workshop, this approach will allow us to take advantage of the power of Bayesian estimation, though we will also practice writing Stan code later this week. To install these packages, simply copy & paste the following into your console:

Code
install.packages("rstanarm")

and then

Code
install.packages("brms")

Installing R packages

Many useful and important functions in R are provided via packages that need to be installed separately. You can do this by using the Package Installer in the menu (Packages & Data – Package Installer in R or Tools – Install Packages… in RStudio), or by typing a command like

Code
install.packages("packagename")

in the R console, like we did above. Packages need to be installed only once.

For this workshop, I recommend installing the following packages:

Code
install.packages(c("bayesplot", "BayesPostEst", "BMA", "brms", "data.table", 
                   "devtools", "ggdist", "ggmcmc", "ggridges", "lme4", "loo", 
                   "marginaleffects", "MCMCpack", "mcmcplots", "modelsummary", 
                   "mvtnorm", "rio", "shinystan", "superdiag", "tidybayes", 
                   "tidyverse", "tinytex"), dependencies = TRUE)

If you run into any errors, warnings, or questions during installation, let me know in the chat and we’ll troubleshoot individually.

Installing CmdStanR

Note

This step is not necessary, but we will look at CmdStanR later in this workshop. If you have time now, you may follow the directions below.

For faster estimation, we can use CmdStanR as a backend for the brms interface. To install CmdStanR,

Additional tools

You may want to install LaTeX in order to generate notebooks and reports in PDF format directly from within RStudio. To do this, you need to install at least a minimal version of LaTeX using the TinyTeX distribution, following the instructions at https://bookdown.org/yihui/rmarkdown-cookbook/install-latex.html.