In [1]:
# Import relevant modules
import pymc
import numpy as np
import matplotlib.pyplot as plt
In [2]:
# Some data
n = 5 * np.ones(4, dtype=int)
x = np.array([-.86, -.3, -.05, .73])
In [3]:
# Priors on unknown parameters
alpha = pymc.Normal('alpha', mu=0, tau=.01)
beta = pymc.Normal('beta', mu=0, tau=.01)
# Arbitrary deterministic function of parameters
@pymc.deterministic
def theta(a=alpha, b=beta):
"""theta = logit^{-1}(a+b)"""
return pymc.invlogit(a + b * x)
# Binomial likelihood for data
d = pymc.Binomial('d', n=n, p=theta, value=np.array([0., 1., 3., 5.]),
observed=True)
In [9]:
mymodel = pymc.Model([theta, d])
S = pymc.MCMC(mymodel, db='pickle')
In [10]:
S.sample(iter=10000, burn=5000, thin=2)
In [11]:
pymc.Matplot.plot(S)
In [12]:
plt.show()
In [ ]: