Skip to content

Instantly share code, notes, and snippets.

@AngelBerihuete
Created March 18, 2019 21:08
Show Gist options
  • Save AngelBerihuete/ff58c4c4bcd39edda5948f4268249eed to your computer and use it in GitHub Desktop.
Save AngelBerihuete/ff58c4c4bcd39edda5948f4268249eed to your computer and use it in GitHub Desktop.
pymc3: hierarchical model with multiple obsesrved variables
# FROM https://stackoverflow.com/questions/33661064/pymc3-hierarchical-model-with-multiple-obsesrved-variables
import matplotlib.pyplot as plt
model = pm.Model()
with model:
hyper_mean = pm.Normal('hyper_mean', mu=0, sd=100)
hyper_sigma = pm.HalfNormal('hyper_sigma', sd=3)
means = pm.Normal('means', mu=hyper_mean, sd=hyper_sigma, shape=n_individuals)
sigmas = pm.HalfNormal('sigmas', sd=100)
y = pm.Normal('y', mu=means, sd=sigmas, observed=y)
trace = pm.sample(10000)
pm.traceplot(trace[100:], vars=['hyper_mean', 'hyper_sigma', 'means', 'sigmas'])
plt.show()
posteriors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment