Here are materials for a workshop on Bayesian analysis at Case Western Reserve University. An earlier version of this workshop was given that the Rotman Research Institute.
For this workshop you will need:
- R
- R Studio
- The materials in this repository (click green "Clone or download" button above)
- Some
R
packages, by entering the code below in RStudio
install.packages(c("brms", "rstan", "bridgesampling", "loo", "bayesplot", "coda", "HDInterval", "lme4")) # this might take a while...
This workshop will introduce attendees to Bayesian data analysis and the R
package brms
. brms
stands for 'Bayesian Regression Models using Stan
' and, as the name suggests, it provides a flexible interface to Stan
, which is a powerful program for fitting Bayesian models. brms
can handle a wide range of models and data types and this workshop will cover several example analyses, with a particular focus on (generalized) linear mixed effects models. These example analyses will cover the setting of prior distributions on model parameters, assessing model convergence and fit, and model comparison. Given responses to the pre-workshop questionnaire, we will also review linear and generalized mixed models. There are also slides and examples introducing the Stan
model language so attendees can start to implement their own bespoke models, as well as better understand what brms
is doing 'under the hood'.
- Review linear and generalized mixed models
- To give a conceptual understanding of Bayesian data analysis
- Introduce the
brms
package forR
- Work on several example analyses
- specifying the model
- choosing priors
- evaluating convergence
- posterior predictive checks
- model comparison (including Bayes' factors)
- Introduce the
Stan
model language and work through some examples (if there's time)
Main workshop slides:
intro.html
- how to get the materials and overview of the workshopmixed.html
- primer on mixed modelsbayes.html
- conceptual introduction to Bayesian analysisbrms.html
- introduction tobrms
with examples
Optional extras:
stan.html
- introduction toStan
with examplesmcmc.html
- introduction to MCMC sampling in Bayesian analysis
The .Rmd
files used to create slides are also available (you may need extra packages to knit)
Example analyses with brms
:
brms-example1.R
- analysis of thesleepstudy
dataset from thelme4
package. Reaction times after different amounts of sleep deprivationbrms-example2.R
- analysis of a hypothetical memory study where two groups recall items under two different conditions. Outcome is recall accuracy (seesim-brms-ex2.R
for code to simulate dataset)brms-example3.R
- analysis of thewine
dataset from theordinal
package. Ordinal ratings of wine betterness
Example analyses with Stan
:
stan-example1.R
- analysis of thesleepstudy
dataset withStan
(seestan-models
folder)stan-example2.R
- analysis of two-dimensional recall data that (I think) cannot be handled bybrms
(seesim-recall-2D.R
for code to simulate dataset)
Please send questions/ comments/ suggestions to: [email protected]