This set of notebooks works through an example of hierarchical (also known as multilevel) Bayesian modelling using the pystan
Python module. It is derived from Chris Fonnesbeck's introduction to Bayesian multilevel modelling using Stan:
These notebooks can be read through online as webpages (follow the links below in Notebooks
), or downloaded and used interactively as Jupyter notebooks, where you can explore and experiment with the models in your web browser, using Python.
# License Information
Chris Fonnesbeck's material is licensed under the following licenses:
- Text: CC-BY version 3.0
- Code: Apache version 2.0
Both licences grant permission to reproduce and prepare derivative works, and these licenses should be considered also to apply to the work in this repository.
I will have made mistakes. If you spot any, or would otherwise like to make improvements, I would be grateful if you could please take one of the following actions:
- Raise the issue at the GitHub issues page for this repository.
- Fork the repository, make the required changes, and then issue a pull request.
- Introduction
- Data Import
- Bias/Variance Tradeoff
- A Pooled Model
- An Unpooled Model
- Pooled vs Unpooled Models
- Partial Pooling - An Introduction
- Partial Pooling - Varying Intercept
- Partial Pooling - Varying Slope
- Partial Pooling - Varying Intercept and Slope
- Group-level Predictors
- Contextual Effects
- Prediction
## 1. Get the notebooks
Clone the notebooks from GitHub with:
git clone git@github.com:widdowquinn/Teaching-Stan-Hierarchical-Modelling.git
Then change into the repository directory:
cd Teaching-Stan-Hierarchical-Modelling/
Using virtualenv
we create a standalone Python virtual environment with the appropriate libraries installed. This will not interfere with system Python or any other Python instances available on your machine.
First, create the virtual environment:
virtualenv -p python3.6 venv-stan
Next, activate the virtual environment:
source venv-stan/bin/activate
Then, install the required packages:
pip install -r requirements.txt
Finally, install Jupyter:
pip install jupyter
## 3. Starting the notebooks
To start Jupyter, issue the following at the command line:
jupyter notebook
This should bring up a view on the current directory in your browser. Click on any of the .ipynb
notebook files to start them running in your browser - the index.ipynb
page is a good place to start.