Created
March 18, 2019 21:08
-
-
Save AngelBerihuete/ff58c4c4bcd39edda5948f4268249eed to your computer and use it in GitHub Desktop.
pymc3: hierarchical model with multiple obsesrved variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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