This website1 is an adapted version of teaching materials originally made for the award winning* BayesCog seminar at the Faculty of Psychology, University of Vienna, as part of the Advanced Seminar for master's students (Mind and Brain track; recorded during Summer Term 2020/2021). Further content from the BayesCog workshop at UKE Hamburg (2023) have also been added.
Recording: Recordings from the original version of the course are available on YouTube. The most recent recording from the 2021 summer semester is also available on YouTube.
Outreach: Twitter thread (being liked 700+ times on Twitter) summarizing the contents of the course.
Award/Recognition: The original course received a commendation award from the Society for the Improvement of Psychological Science (SIPS) (also see a tweet), as well as an ECR Teaching Award from the Faculty of Psychology, University of Vienna.
Computational modeling and mathematical modeling provide an insightful quantitative framework that allows researchers to inspect latent processes and to understand hidden mechanisms. Hence, computational modeling has gained increasing attention in many areas of cognitive science through cognitive modeling. One illustration of this trend is the growing popularity of Bayesian approaches to cognitive modeling. To this end, this course teaches the theoretical and practical knowledge necessary to perform, evaluate and interpret Bayesian modeling analyses, with a specific emphasis towards modeling latent cognitive processes.
In the course, students will be formally grounded in key principles of cognitive modeling including Bayesian statistics, statistical distributions and reinforcement learning. We will use R/RStudio and a newly developed statistical computing language - Stan - to perform Bayesian analyses, ranging from simple binomial models and linear regression models to more complex hierarchical reinforcement learning (RL) models.
| Folder | Task | Model |
|---|---|---|
| 01.R_basics | NA | NA |
| 02.binomial_globe | Globe toss | Binomial Model |
| 03.bernoulli_coin | Coin flip | Bernoulli Model |
| 04.regression_height | Observed weight and height | Linear regression model |
| 05.regression_height_poly | Observed weight and height | Polynomial regression model |
| 06.reinforcement_learning | 2-armed bandit task | Simple reinforcement learning (RL) |
| 07.optm_rl | 2-armed bandit task | Simple reinforcement learning (RL) |
| 08.compare_models | Probabilistic reversal learning task | Simple and Fictitious RL models |
| 09.debugging | Memory Retention | Exponential decay model |
There is no additional set-up needed if you aim to work solely from the website. However, to work on the exercises yourself, several software and packages are required.
You can work with the course material by installing the software and packages locally. To do this:
-
Install and set-up the latest version of RStan here
To create the environment, first clone the repository and change to the project directory:
git clone https://github.com/alpn-lab/BayesCog.git
cd BayesCogThe various analyses across the workshops require specific packages to be installed. This project uses renv to manage package dependencies.
To set up the environment, firstly open RStudio in the project root and run in the console:
source("setup.R")After executing this command once, the project environment will load automatically whenever you open the project, for both project root and individual workshops.
All you need to do is to load the packages required for the relevant scripts when necessary e.g., library(rstan).
You can always check if you are missing a certain package by clicking on the 'Packages' tab (next to 'Files/Plots' tab) or by running
library().
We also provide a Docker image which can be used to create an R/RStudio container with the required packages. This assumes you have Docker Desktop installed.
To do so, after cloning the git repository as above, open Docker Desktop and then from the project root run:
docker pull sohamir/bayescog:latest
docker run -d -p 8787:8787 \
--mount type=bind,source=$(pwd),target=/home/rstudio/project \
-e PASSWORD=your_chosen_password \
--name bayescog \
sohamir/bayescogMake sure to replace the PASSWORD argument with your own password!
This will mount the Docker image onto the BayesCog repository.
Then, navigate to http://localhost:8787 in a browser, and type your username (which is always 'rstudio') and the password chosen in the command prior.
Then once RStudio has loaded, click on the project folder and the BayesCog material will appear. You will not need to install any packages, only to load them when running various operations.
Subsequently, to start/stop the container, type (from the command line):
docker start bayescog
docker stop bayescogTo see/remove the container type:
docker ps -a
docker rm your_docker_imageAnd to see/remove the image, type:
docker images
docker rmi your_docker_image # e.g. docker rmi sohamir/bayescogIf you run into problems while working through the course, there are a few places to look:
- Setup and installation issues (e.g. installing RStan, restoring the
renvenvironment, or building the Docker image): re-check the Set-up instructions above. If a local installation proves difficult, the Docker image provides a pre-configured RStudio environment with all required packages and is the most reliable fallback. - Questions about the course content or models: each workshop page on the website is self-contained and includes worked examples and solutions.
- Bugs, errors, or suggestions: please open an issue on the GitHub repository, or get in touch using the Contact details below.
If you would like to contribute a fix or improvement yourself, see the CONTRIBUTING guidelines.
Dr. Lei Zhang π» π§ |
Aamir Sohail π» π§ |
Zhi-Lin Su π» |
This project follows the all-contributors specification.
This project β including both the course content (the website text, figures, slides, and teaching materials) and the code (the R scripts, Stan models, and other software in this repository) β is released under the MIT License (see LICENSE).
You are free to use, copy, modify, and redistribute the material for any purpose, including commercial use, provided that the copyright notice and permission notice are retained.
If you use materials from this course in your work or research, please cite it as:
Zhang, L., & Sohail, A. (2025, November 16). BayesCog: A freely available course in Bayesian statistics and hierarchical Bayesian modeling for psychological science. https://doi.org/10.31234/osf.io/ua5ng_v1
For BibTeX users:
@online{ZhangSohail2025,
title = {BayesCog: A freely available course in Bayesian statistics and hierarchical Bayesian modeling for psychological science},
author = {Zhang, Lei and Sohail, Aamir},
year = {2025},
publisher = {OSF},
doi = {10.31234/osf.io/ua5ng_v1}
}For bug reports, issues or comments, please contact Lei Zhang or Aamir Sohail, or open a thread on the GitHub repository.
Footnotes
-
Bayes' photo credit: Burrsettles (2016). The three faces of Bayes. Slackprop. β©
