(This question is probably easier to understand if you have access to Kruschke's Doing Bayesian Data Analysis book, since I'm trying to build the model on p 493)
Basically I'm trying to build this model https://drive.google.com/open?id=0BxzmgRR6TC-2dUN3VEs4enZZQ1U in PyMC3, by using the methods from this blog post http://twiecki.github.io/blog/2014/03/17/bayesian-glms-3/
This is the code I've arrive at
with pm.Model() as multi_level_model:
# Top level
mu_0 = pm.Normal('mu_0', mu=0, sd=100**2)
sigma_0 = pm.Uniform('sigma_0', lower=0, upper=100)
mu_1 = pm.Normal('mu_1', mu=0, sd=100**2)
sigma_1 = pm.Uniform('sigma_1', lower=0, upper=100)
# Middle
beta_0 = pm.Normal('beta_0', mu=mu_0, sd=sigma_0, shape=n_subj)
beta_1 = pm.Normal('beta_1', mu=mu_1, sd=sigma_1, shape=n_subj)
nu = pm.Exponential('nu', lam=1/29.) + 1
sigma = pm.Uniform('sigma', lower=0, upper=100)
# subj_idx is a vector with what subject each observation comes from
# data_hier['X'] is the predictor
mu_ij = beta_0[subj_idx] + beta_1[subj_idx]*data_hier['X'].values
# Bottom
# data_hier['Y'] is the prdicted values
obs = pm.StudentT('obs', mu = mu_ij, sd=sigma, nu=nu, observed=data_hier['Y'].values)
#start = pm.find_MAP() This seems to never finish
step1 = pm.Metropolis([sigma, sigma_0, sigma_1])
step2 = pm.NUTS([mu_0, mu_1, nu, beta_0, beta_1])
multi_level_trace = pm.sample(draws=2000, step=[step1, step2])
However, it doesn't converge as well as the same model build in pystan. (And takes longer to run). Any tips on how the model can be improved?
The data can be found here https://drive.google.com/file/d/0BxzmgRR6TC-2Qk5WcjhaaGJSTmM/view?usp=sharing