Course overview
Who this course is for and how to get the most out of it
Aims and philosophy
This course was initially developed for master’s students at the University of Vienna, but is intended for anyone interested in learning about Bayesian statistics, and using Bayesian methods to both build and apply cognitive models. As a result, students at all levels, postdocs, as well as senior faculty have completed this course!
The term ‘Bayesian’ is not limited to modeling, and reflects a more general approach to probability observed in many research areas. Therefore, to avoid confusion beforehand, this course is not about ‘Bayes in the brain’ (Bayesian brain hypothesis), or why Bayesian statistics is a better alternative to frequentist statistics (even though it is).
Instead, this course aims to develop understanding and experience in using Bayesian statistics to analyse cognitive processes by constructing models.
The course’s approach to understanding cognition through modeling is guided by David Marr’s influential framework of three levels of analysis1:
The Computational Level (Why): This addresses what problem the cognitive system is trying to solve and why. It focuses on the goals and logic of the computation.
The Algorithmic Level (What): This specifies the representation and algorithm used to solve the computational problem. It describes the rules and strategies that implement the solution.
The Implementation Level (How): This details how the algorithm is physically realized in neural circuits and brain structures.
Throughout this course, we’ll use cognitive modeling as a bridge between these levels, particularly focusing on how algorithmic-level models can help us understand behaviour:
Marr’s framework as applied to cognitive modeling
The goals of this course are to:
- Build a foundational knowledge in cognitive behaviour and model-building
- Learn practical
R
programming - Build cognitive models using RStan
- Engage in open-source methods using
git
and GitHub (optional)
Subsequently, after completing the course, you …
- feel comfortable with reading mathematical equations
- consider the implementation of the “computational modeling” section when reading scientific articles
- gain insightful understanding of Bayesian statistics and modeling
- can apply computational modeling in your own experiments
This course particularly places a strong emphasis on hands-on experience modeling in Stan, gaining experience with the modeling workflow depicted below2:
You will learn to implement parameter and model recovery, perform posterior predictive checks, and assess competing models using model selection. Don’t worry if none of this is currently familiar; hopefully it will be after completing this course!
Pre-requisites
To fully benefit from the materials, you are expected to have:
- Some basic understanding of frequentist statistics
- Some basic knowledge of programming
Any advanced knowledge of programming or statistics, whilst useful, is not required!
The course develops in complexity across the workshops, with the later material on hierarchical models and model optimization being more challenging. However, do not feel as if you need to complete all workshops within a specific time-frame! These materials should consist part of your education in cognitive modeling.
As a course in statistics and mathematical modeling, math equations feature throughout, albeit sparingly. Understanding the mathematical equations underlying computational models is necessary for understanding the relationship between data and parameters. However, some sections of the course feature additional math (e.g., derivations, statistical distributions) which are not strictly necessary to understand. As a general rule of thumb, most important is that you try to understand the equations describing your data and parameters, and how they are represented mathematically!
In any case, do not worry if you struggle during the course!
List of folders and contents
The materials for the workshops are split across sub-folders within /workshops
:
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 |
*Workshops 5, 10 and 11 have yet to be added, so watch this space!
In addition to following along with the taught material, there are a number of exercises that you can work through. The code and solutions to the exercises will be worked through on the website in some cases, but not in others. In all cases however, the materials to work through the exercises yourself are provided.
Specifically, each workshop folder above will typically have two sub-folders: _data
and _scripts
. Each _scripts
folder will also contain separate files with and without the master
suffix.
├── R_basics.Rproj
├── _data
├── _scripts
│ ├── R_basics.R
│ └── R_basics_master.R
The base scripts will often contain the necessary code; details on which scripts and data to use during the workshops is always given.
You do not have to work through the exercises to benefit from and complete this course, but is recommended if you are wanting to gain practical experience with programming in Stan!
The course materials and Stan models were primarily written in 2020-21. Both Stan and R
are ever-evolving programming languages where certain features and practices are likely to change over time. Therefore whilst the Stan models and R
scripts in the course materials will run correctly without issue, proper syntax may not always be followed.
You should always consult the most recent documentation for best practices when programming!
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.
Using RStudio and renv
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/sohaamir/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_test:latest
docker run -p 8787:8787 \
--mount type=bind,source=$(pwd),target=/home/rstudio/project \
-e PASSWORD=your_chosen_password \
--name bayescog_test \
sohamir/bayescog_test
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 be there.
To start/stop the container, type (from the command line):
docker start bayescog_test
docker stop bayescog_test
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_test