I came accross the canonical Bayesian cancer question and thought it would be fun to solve it using PYMC.
Here is the question:
And here is the solution in PYMC:
prevalence_cancer = 0.008
sensitivity = 0.98
specificity = 0.97
with pm.Model() as model:
cancer = pm.Bernoulli("cancer", prevalence_cancer)
test_positive = pm.Bernoulli("test_positive",
p=pm.math.switch(cancer, sensitivity, 1 - specificity),
observed=1
)
trace = pm.sample(draws=5000, tune=1000, chains=4, random_seed=1)
let’s look at the posterior:
or the summary:
This is what the solution would be if you did this by hand. I think this was a nice simple example for newbies to PYMC