Code
example(stan_model, package = "rstan", run.dontrun = TRUE)
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:
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.
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.
Please stop here until we discuss installing Stan as a group.
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/:
example(stan_model, package = "rstan", run.dontrun = TRUE)
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:
install.packages("rstanarm")
and then
install.packages("brms")
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
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:
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.
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,
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.