1

I am modeling data that I think is gamma distributed so I write a PyMC3 model as below.

import pymc3 as pm
import arviz as az

with pm.Model() as model2:
    alpha = pm.Exponential('alpha', 5)
    beta = pm.Exponential('beta', 5)
    
    p_factor = pm.Gamma('p_factor', alpha = alpha, beta = beta, observed = d.productivity_factor)
    
    prior_checks = pm.sample_prior_predictive(samples=100, random_seed= seed)
    
    trace2 = pm.sample(2000, tune=2000)

I then plot a posterior predictive check

with model2:
    ppc2 = pm.sample_posterior_predictive(trace2, var_names=["alpha", "beta",'p_factor'], random_seed=seed)
    
idata = az.from_pymc3(trace2, posterior_predictive=ppc2)
az.plot_ppc(idata)

but the observed curve does not match what I expect. Is there something I am doing wrong?

KDE plot of observed data

PPC Plot

merv
  • 67,214
  • 13
  • 180
  • 245
kwespiipi
  • 11
  • 3
  • The apparent differences between the KDEs are probably due to extendind the data further that where there are observations. I believe the comments on this [other question](https://stackoverflow.com/questions/61283063/arviz-plot-ppc-posterior-predictive-mean#comment108414459_61283063) will help. – OriolAbril Oct 15 '20 at 03:50
  • It could also be interesting to take a look at this other question: https://stackoverflow.com/questions/63608116/plot-fit-of-gamma-distribution-with-pymc3 – OriolAbril Oct 15 '20 at 03:51

0 Answers0