Prework

Thank you participating in our workshop, Diagnostic Classification Modeling With R and Stan. To prepare for the workshop, please install the following:

install.packages(c("measr", "dplyr", "fs", "usethis"),
                 repos = "https://cran.rstudio.com/",
                 dependencies = TRUE)

Optional

By default, measr uses rstan as a backend for estimating models. However, the version of rstan on CRAN is outdated. Therefore, I recommend using an updated version of rstan from the stan-dev/r-packages repository, or using the cmdstanr interface to CmdStan.

Updated rstan

You can download an updated version of rstan by running the following code:

install.packages(
  c("StanHeaders", "rstan"),
  repos = c("https://mc-stan.org/r-packages/", getOption("repos"))
)

To verify that rstan is installed correctly, run the following code. If it works, then things are set up properly! For additional help installing rstan, see the RStan Getting Started help page.

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

cmdstanr

For cmdstanr, I recommend installing the development version directly from Github:

install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")

After installing cmdstanr, you will also need to install CmdStan, which can be by running:

cmdstanr::install_cmdstan()

To ensure that cmdstanr and CmdStan are installed properly, try running the following code. If it works, then you are good to go! For help with install cmdstanr, see the Getting Started with CmdStanR vignette.

file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)