This is from page 31
In [1]:
import numpy as np
import spacepy.plot as spp
import pymc
%matplotlib inline
In [2]:
n = 251527 + 241945
p = pymc.Uniform('p', 0, 1, observed=True, value=241945/n)
g_prob = pymc.Binomial('g_prob', n=n, p=p)
In [3]:
model = pymc.MCMC((p,g_prob))
In [4]:
model.sample(100000, burn=100, burn_till_tuned=True)
In [5]:
pymc.Matplot.plot(model)
In [6]:
a = spp.plt.hist(model.trace('g_prob')[:]/n, 20)
In [7]:
print(model.summary())
In [8]:
n = 251527 + 241945
p = pymc.Normal('p', 0.5, 0.2, observed=True, value=241945/n)
g_prob = pymc.Binomial('g_prob', n=n, p=p)
In [9]:
model = pymc.MCMC((p,g_prob))
In [10]:
model.sample(100000, burn=100, burn_till_tuned=True)
In [11]:
pymc.Matplot.plot(model)
In [12]:
a = spp.plt.hist(model.trace('g_prob')[:]/n, 20)
In [13]:
print(model.summary())
In [47]:
n = 251527 + 241945
p = pymc.Normal('p', 0.5, 0.2, observed=True, value=241945/n)
g_prob = pymc.Binomial('g_prob', n=n, p=p)
@pymc.deterministic(plot=True)
def sex_ratio(g_prob=g_prob, n=n):
return ((1-g_prob/n)/(g_prob/n))
from scipy.special import logit
@pymc.deterministic(plot=True)
def sex_ratio_logit(g_prob=g_prob, n=n):
return logit(g_prob/n)
In [48]:
model = pymc.MCMC((p,g_prob, sex_ratio, sex_ratio_logit))
In [49]:
model.sample(100000, burn=100, burn_till_tuned=True)
In [50]:
pymc.Matplot.plot(model)
In [51]:
print(model.summary())
In [ ]:
In [ ]:
In [ ]: