This question concerns Gelman’s Rat Tumor example in BDA 3 (bottom of page 109).
I’m trying to replicate the inference made in this example. Here is some code to get started:
import numpy as np
import pandas as pd
import pymc3 as pm
import theano.tensor as T
import matplotlib.pyplot as plt
# rat data (BDA3, p. 102)
n_tumour = np.array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 5, 2,
5, 3, 2, 7, 7, 3, 3, 2, 9, 10, 4, 4, 4, 4, 4, 4, 4,
10, 4, 4, 4, 5, 11, 12, 5, 5, 6, 5, 6, 6, 6, 6, 16, 15,
15, 9, 4
])
n_rat = np.array([
20, 20, 20, 20, 20, 20, 20, 19, 19, 19, 19, 18, 18, 17, 20, 20, 20,
20, 19, 19, 18, 18, 25, 24, 23, 20, 20, 20, 20, 20, 20, 10, 49, 19,
46, 27, 17, 49, 47, 20, 20, 13, 48, 50, 20, 20, 20, 20, 20, 20, 20,
48, 19, 19, 19, 22, 46, 49, 20, 20, 23, 19, 22, 20, 20, 20, 52, 46,
47, 24, 14
])
with pm.Model() as model:
#Uninformative prior for alpha and beta
u = pm.Uniform('u', 0, 1)
v = pm.Uniform('v', 0,1)
alpha = pm.Deterministic('a',u/T.pow(v,2))
beta = pm.Deterministic('b',(1-u)/T.pow(v,2))
theta = pm.Beta('theta', alpha=alpha, beta = beta)
p = pm.Binomial('y',p=theta,observed = n_tumour, n=n_rat)
trace = pm.sample(50_000, cores = 2, step = pm.NUTS())
Gelman choses a uniform hyperprior on (\dfrac{a}{a+b}, (a+b)^{-1/2}), so let u = \dfrac{a}{a+b} and v = (a+b)^{-1/2} and solve appropriately.
I keep getting the error
There were 4377 divergences after tuning. Increase `target_accept` or reparameterize.
There were 2637 divergences after tuning. Increase `target_accept` or reparameterize.
The number of effective samples is smaller than 10% for some parameters.
so I was wondering how best to reparameterize the problem so that the chains converge. Am I reparameterizing incorrectly by using pm.Deterministic
?