I recently found the need to apply a hierarchical Bayesian model in a project. That experience has motivated me to refine my Bayesian statistics skills. Years ago I used Gibbs sampling and a Dirichlet Process to sample distributions over phoneme/word alignments in finite state transducers to improve speech recognition using written translations in another language. I learnt a lot doing this, however I mostly learnt all the relevant concepts on a need-to-know basis. This time I want to learn a more general understanding and set of skills from the ground up. It’s very interesting, and having practical abilities with statistics is a timeless skill set.

I’ve been reading Richard McElreath’s Statistical Rethinking (2nd edition) and have now started to work through the practice problems found at the end of each chapter. I’m using Python and pymc3 because life is short and want to leverage my existing Python skills and also practice the statistical skills using the language and libraries I would be using in real world projects. I thought it might be useful to publish my answers online, and so here they are. Note that I’m only including my answers, not the questions that were in the book itself. This will make these answers difficult to interpret without the book.

In my solutions I build upon the very Python/pymc3 ports of the code examples in the book. Since the problems are designed to practice concepts learnt in their respective chapters, I have ended up making heavy use of the code from that repository, since their code frequently forms the scaffold to solutions to the problems.

I will update this post as I produce more solutions. Note that since producing these solutions was a learning exercise and not subject to thorough review, I can’t be sure of the correctness of all the answers.

Chapter 2 solutions

Chapter 3 solutions

Chapter 4 solutions (added 25/8/2021)

Chapter 5 solutions (completed 27/8/2021; but only added 24/10/2022)