Software for SOCI 620

Required software

The main required software for the course is R. It is the core computational environment we will be using.

In addition to R, you will need several R add-on packages:

Finally, you likely want to install an integrated development environment (IDE). An IDE is a program that will run R, help you edit scripts, and provides interfaces for visualizations, installing packages, and other common needs. While not technically required, an IDE can make life a lot easier, especially if you don’t consider yourself a computer nerd. The most popular IDE for R is RStudio, but VSCode (and VSCodium, it’s open-source version with Microsoft’s tracking features removed) is also becoming more widely used. I’ll teach the class using RStudio because that is the most common among students.

Install R

Mac and Windows:

  1. Go to https://cran.r-project.org/ and follow the link for your OS.
  2. Download and run the appropriate installer (Mac users, be sure to use the installer that matches your computer: Intel for older Macs and Apple Silicon for newer Macs).

Linux:

  1. Search for r-base using your package manager.

Install RStudio

Installing RStudio is optional, but recommended for most students.

  1. Go to https://posit.co/download/rstudio-desktop/
  2. Identify and download the appropriate installer for your computer

Install C++ toolchain and RStan

This is the most complex component to install, and the process depends entirely on what OS you run.

Mac

Complete the following steps (consolidated from Rstan) in an R console (in RStudio, another IDE, or in a terminal window):

  1. Install the remotes package:

    install.packages("remotes")
  2. Install macrtools package:

    remotes::install_github("coatless-mac/macrtools")
  3. Run the macrtools toolchain installer:

    macrtools::macos_rtools_install()
  4. Running the following is not required, but will help your Stan code run faster:

    dotR <- file.path(Sys.getenv("HOME"), ".R")
    if (!file.exists(dotR)) dir.create(dotR)
    M <- file.path(dotR, "Makevars")
    if (!file.exists(M)) file.create(M)
    arch <- ifelse(R.version$arch == "aarch64", "arm64", "x86_64")
    cat(paste("\nCXX17FLAGS += -O3 -mtune=native -arch", arch, "-ftemplate-depth-256"),
        file = M, sep = "\n", append = FALSE)
  5. Install the RStan package:

    install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
  6. Make sure RStan works by running an example (this will take a few seconds to compile and run):

    example(stan_model, package = "rstan", run.dontrun = TRUE)

Windows

Instructions consolidated from RStan:

  1. Ensure you have the latest version of R installed (upgrade if necessary).

  2. Visit the Rtools website (https://cran.r-project.org/bin/windows/Rtools/rtools43/rtools.html).

  3. Download and run the RTools43 installer linked from that page.

  4. Running the following in an R console is not required, but will help your Stan code run faster:

    dotR <- file.path(Sys.getenv("HOME"), ".R")
    if (!file.exists(dotR)) dir.create(dotR)
    M <- file.path(dotR, "Makevars.win")
    if (!file.exists(M)) file.create(M)
    cat("\n CXX17FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2",
        file = M, sep = "\n", append = FALSE)
  5. Install the RStan package:

    install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
  6. Make sure RStan works by running an example (this will take a few seconds to compile and run):

    example(stan_model, package = "rstan", run.dontrun = TRUE)

Linux

  1. If you use Linux, you almost certainly already have a C++ toolchain installed.

  2. Running the following in an R console is not required, but will help your Stan code run faster:

    dotR <- file.path(Sys.getenv("HOME"), ".R")
    if (!file.exists(dotR)) dir.create(dotR)
    M <- file.path(dotR, "Makevars")
    if (!file.exists(M)) file.create(M)
    cat("\nCXX17FLAGS=-O3 -march=native -mtune=native -fPIC",
        "CXX17=g++", # or clang++ but you may need a version postfix
        file = M, sep = "\n", append = TRUE)
  3. Install the RStan package:

    Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1)
    install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
  4. Make sure RStan works by running an example (this will take a few seconds to compile and run):

    example(stan_model, package = "rstan", run.dontrun = TRUE)

Install remaining R packages

The remaining required packages should be easy to install from within an R console:

  1. Install cmdstanR and rethinking:

    install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))
    # possibly:
    install_cmdstan()
    
    install.packages(c("coda","mvtnorm","loo","dagitty","shape"))
    devtools::install_github("rmcelreath/rethinking")
  2. Install brms and lme4:

    install.packages(c("brms","lme4"))