Good morning,
It’s been a long time since I last used PyMC and I realize that I have mostly forgotten how programs should be properly written!
To address a Gamma-Poisson
problem that interests me, I was inspired by the question asked and addressed here: HERE
So, I adjusted the instructions given by jlindbloom a bit, based on what I remember, and figured I could write the program below:
import pymc as pm
import arviz as az
with pm.Model() as model:
gamma = pm.Gamma('gamma', alpha=1, beta=1) # Prior
p_obs = pm.Poisson('p_obs', mu=gamma, observed=[1]) # Likelihood
with model:
idata = pm.sample(tune=1000,draws=5000,target_accept=0.9)
idata_prior = pm.sample_prior_predictive(var_names=["gamma"],
return_inferencedata=True)
idata_posterior = pm.sample_posterior_predictive(idata, var_names=["p_obs"],
return_inferencedata=True,
extend_inferencedata=True,
predictions=False)
idata.extend(idata_prior)
idata.extend(idata_posterior)
az.plot_ppc(idata_prior, var_names=["p_obs"])
az.plot_ppc(idata_posterior, var_names=["gamma"])
Unfortunately, what I feared happened, in the form of the error:
TypeError Traceback (most recent call last)
Cell In[22], line 20
16 idata.extend(idata_prior)
17 idata.extend(idata_posterior)
---> 20 az.plot_ppc(idata_prior, var_names=["p_obs"])
22 az.plot_ppc(idata_posterior, var_names=["gamma"])
...
TypeError: `data` argument must have the group "posterior_predictive" for ppcplot.
and, obviously, I completely forgot what the meaning of: must have the group "posterior_predictive" for ppcplot
is and how to fix that…
I come to you for some advice and ask you to bear with me on this not-so-smart question; I’ll try to find some notes I must have taken on the subject.