arviz-devs / arviz

Exploratory analysis of Bayesian models with Python
https://python.arviz.org
Apache License 2.0
1.61k stars 407 forks source link

plot_ppc for discrete data #1103

Open jeffpollock9 opened 4 years ago

jeffpollock9 commented 4 years ago

Hi, firstly thanks for a great package!

I think arviz doesn't currently support posterior predictive checks for discrete data - is that correct? Assuming that is correct - is there any interest in it? I think something along the same lines as https://mc-stan.org/bayesplot/reference/PPC-discrete.html would be great.

Cheers!

OriolAbril commented 4 years ago

I think there is limited support for ppc checks with discrete data, however, it would be great to extend its capabilities. cc @aloctavodia @agustinaarroyuelo

aloctavodia commented 4 years ago

Hi @jeffpollock9, as Oriol said the support is limited.

We have a Google Summer of code project that will address this and other issues related to support for discrete variables.

jeffpollock9 commented 4 years ago

Thanks for getting back to me. @OriolAbril and @aloctavodia. Looking forward to seeing the results of the google summer of code project!

canyon289 commented 4 years ago

@jeffpollock9 thanks for making an issue. It's possible to plot discrete data but looking at the bayesplot one ours could be nicer.

import pymc as pm
from scipy import stats

coin_flips_obs = stats.binom(12, .5).rvs(333)

with pm.Model() as coin_flips:
    p = pm.Beta("p", 10000,1)
    heads = pm.Binomial("heads", p=p, n=11, observed=coin_flips_obs)
    trace = pm.sample(chains=2, draws=1000)
    coin_flip_posterior_predictive = pm.sample_posterior_predictive(trace)
coin_data = az.from_pymc3(trace=trace, posterior_predictive=coin_flip_posterior_predictive)
az.plot_ppc(coin_data)

image