Setup and Required Packages
To run the live code in this book you need R and a small handful of packages. To reproduce the walkthrough examples - the ones shown but not executed here, because they need heavier tools - you need a few more. This page lists both, with one-line installers, so you can pull the requirements immediately.
To run the book’s live code
The executable code throughout the book uses base R plus a few graphics and publishing packages:
install.packages(c("ggplot2", "plotly", "knitr", "rmarkdown"))Everything else the running code needs - regression and ANOVA (lm, aov), factor analysis (factanal), principal components (prcomp), reliability from scratch, the bootstrap and permutation tests written by hand - lives in base R and is already installed. That is deliberate: the core ideas are demonstrated with tools everyone already has.
To reproduce the walkthrough examples
Several chapters show the production tool for a job as static code (for example, lavaan for SEM, mirt for IRT, brms for Bayesian models). These are the packages the book actually names; all are on CRAN, so a single call installs them:
install.packages(c(
"psych", # reliability (alpha, omega), EFA, describe()
"lavaan", # confirmatory factor analysis, SEM, measurement invariance
"mirt", # item response theory (2PL, graded response)
"poLCA", # latent class analysis
"mice", # multiple imputation for missing data
"dagitty", # directed acyclic graphs (adjustment sets, implied independencies)
"WRS2", # Wilcox robust methods (trimmed-means tests)
"MASS" # robust regression (rlm); ships with R, listed here for completeness
))For the Bayesian chapters, brms and bayestestR are on CRAN, but McElreath’s rethinking is not - it is distributed on GitHub. Both brms and rethinking compile models to Stan, which needs a working C++ toolchain:
install.packages(c("brms", "bayestestR")) # on CRAN
# rethinking is GitHub-only, so install it from there:
install.packages("remotes")
remotes::install_github("rmcelreath/rethinking")
# Stan toolchain setup: https://github.com/rmcelreath/rethinkingSPSS and Julia
- SPSS is commercial software. If your institution provides it, the three-languages appendix gives the syntax for the book’s core procedures.
- Julia is free and open source (julialang.org). Its statistics live in packages you add once:
using Pkg
Pkg.add(["DataFrames", "Statistics", "GLM", "HypothesisTests", "MultivariateStats"])Reproducibility
Every running example in this book sets a random seed, so re-running the same code returns the same numbers. If a result ever differs, check your package versions first; sessionInfo() in R prints exactly what you have loaded.