R6. Practice model building

This recitation was prepared by Ariana Tribby

The goal of this recitation is to practice coming up with a generative likelihood, identifying which parameters to estimate, and writing down the priors for those parameters.

This recitation will present a series of proposed experiments/scenarios for which you can practice writing full generative models for (priors and likelihoods). The format of each exercise is paper/pencil sketch. Sketching your model before jumping to the code can be really helpful and is great practice! The goal of each exercise is to write your model in the format you’ve seen in lectures, for example, from “MCMC diagnostics” lecture:

\begin{align} &\log_{10} \alpha \sim \text{Norm}(0, 1), \\[1em] &\log_{10} b \sim \text{LogNorm}(2, 1), \\[1em] &\beta = 1/b,\\[1em] &n_i \sim \text{NegBinom}(\alpha, \beta) \;\forall i. \end{align}

Writing your model in this format sets you up for an easier transfer of your knowledge into Stan. Note that you should come up with concrete distributions and values for your priors for these exercises. You are free to use the distribution explorer to help come up with the likelihoods and priors.

Before we start… how do I know which “nomial” to use as a likelihood?

What is the difference between binomial and negative binomial “stories”? How do I know which one to use?

Both are based on independent Bernoulli trials with fixed probability of success, \(\theta\). The number of successes observed in n trials is binomially distributed. The number of trials until the ith success is observed is negative binomially distributed. The number of failures until the ith success (instead of the trials until ith success) is also negative binomially distributed.

# Colab setup ------------------
import os, sys, subprocess
if "google.colab" in sys.modules:
    cmd = "pip install --upgrade bebi103 watermark"
    process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()
    data_path = "https://s3.amazonaws.com/bebi103.caltech.edu/data/"
    data_path = "../data/"
# ------------------------------

import pandas as pd
import numpy as np
import scipy.stats as st

import bokeh.io

import holoviews as hv
import bebi103
Loading BokehJS ...