Skip to content

BayesCog: A freely available course in Bayesian statistics and Hierarchical Bayesian Modeling for Psychological Science

License

Notifications You must be signed in to change notification settings

Alpn-Lab/BayesCog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BayesCog - Bayesian Statistics and Hierarchical Bayesian Modeling for Psychological Science

Visitors GitHub contributors GitHub last commit GitHub repo size

Bayes Banner

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.

Table of contents

Course summary

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 distibrutions 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.

List of folders and contents

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
10.model_based WIP WIP
11.delay_discounting WIP WIP

Set-up

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.

Locally using RStudio and renv

You can work with the course material by installing the software and packages locally. To do this:

  • Install the latest version of R here and RStudio here

  • 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 BayesCog

The 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().

Building the Docker image

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, from the project root run:

docker pull sohamir/bayescog:latest

docker run -p 8787:8787 \
  --mount type=bind,source=$(pwd),target=/home/rstudio/project \
  -e PASSWORD=your_chosen_password \
  --name bayescog \
  sohamir/bayescog

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.

To start/stop the container, type (from the command line):

docker start bayescog
docker stop bayescog

To see/remove the container type:

docker ps -a
docker rm your_docker_image

And to see/remove the image, type:

docker images
docker rmi your_docker_image # e.g. docker rmi sohamir/bayescog

Contributing

We welcome contributions regarding content or with fixing errors on the current website. Making and committing these changes is simple.

Assuming you have cloned the repository and have Quarto installed, you can preview any changes that you have in the browser by running:

quarto preview

If you are fortunate enough to have admin access (i.e., are a member of the ALPN Lab), you can just commit the changes:

git add .
git commit -m "your commit message"
git push origin main

And once the changes have been pushed, re-build the website by running:

quarto publish gh-pages

If you do not have admin privileges, you can commit the changes to the main branch by following the steps below:

# First, make sure you fork https://github.com/Alpn-Lab/BayesCog to your GitHub account

# Add the original as upstream
git remote add upstream https://github.com/Alpn-Lab/BayesCog.git

# Create and switch to a new branch for your changes
git checkout -b your-feature-name

# Add and commit your changes
git add .
git commit -m "Describe your changes here"

# Push to your fork
git push origin your-feature-name

You will then need to go to your fork on GitHub, where you'll see a prompt to "Compare & pull request" for your new branch. Click that to create a pull request to suggest your changes to the main repository.

If approved, we will both add the changes and you to the 'Contributors' list below!

Contributors

Dr. Lei Zhang
Dr. Lei Zhang

πŸ’» 🚧
Aamir Sohail
Aamir Sohail

πŸ’» 🚧

This project follows the all-contributors specification.

License

This course is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

You are free to share, copy, and redistribute the material in any medium or format. Additionally, you can adapt, remix, transform, and build upon the material for any purpose, including commercial use. However, you must provide appropriate attribution, including credit to the original source, a link to the license, and an indication if changes were made. Furthermore, if you remix, transform, or build upon the material, you are required to distribute your contributions under the same license as the original.

Citing

If you use materials from this course in your work or research, please cite it as:

Zhang, L., & Sohail, A. (2025). BayesCog: Bayesian Statistics and Hierarchical Bayesian Modeling for Psychological Science [Online course]. Zenodo. https://doi.org/[DOI_HERE]

For BibTeX users:

@online{zhang_sohail_2025,
    title = {BayesCog: Bayesian Statistics and Hierarchical Bayesian Modeling for Psychological Science},
    author = {Zhang, Lei and Sohail, Aamir},
    year = {2025},
    publisher = {Zenodo},
    doi = {DOI_HERE},
    url = {ZENODO_URL},
    note = {Online course},
    repository = {https://github.com/REPOSITORY_URL}
}

Note: Once this course is published on Zenodo, this citation information will be updated with the corresponding DOI and URL.

Contact

For bug reports, issues or comments, please contact Lei Zhang, or Aamir Sohail, or open a thread on the GitHub repository.

Footnotes

  1. Bayes' photo credit: Burrsettles (2016). The three faces of Bayes. Slackprop. ↩

About

BayesCog: A freely available course in Bayesian statistics and Hierarchical Bayesian Modeling for Psychological Science

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published