# Bug in sample\_prior\_predictive

**URL:** https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210
**Category:** Questions
**Created:** [November 14, 2018, 8:10pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210 "2018-11-14T20:10:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [November 14, 2018, 8:10pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/1 "2018-11-14T20:10:15Z")

</div>

I’ve been seeing some odd behavior with a hierarchical model that I’m trying with `sample_prior_predictive`: some of the variance parameters, which I was modeling with Inverse Gamma(1,2) distributions, give what look like very odd samples. Here’s an arviz plot of the results of sample\_prior\_predictive for 4 such variables:

 ![InverseGammas](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/5/57e68aac210a60a9780483862dcd37d2571958fb.png)

Here’s the code I used to make this:

```auto
import pymc3 as pm
import arviz as az
import matplotlib.pyplot as plt

m = pm.Model()
with m:
   pm.InverseGamma('Inverse Gamma(1,2)',alpha=1, beta=2, shape=4)
samples = pm.sampling.sample_prior_predictive(model=m)
data=az.from_pymc3(prior=samples)
az.plot_density(data,var_names=pm.sampling.get_default_varnames(m.named_vars, False), group='prior')
plt.show()

```

---

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [November 14, 2018, 9:23pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/2 "2018-11-14T21:23:45Z")

</div>

Actually, TBQH, I am not sure that this is a bug in `sample_prior_predictive` or if it’s a bug in `arviz`. These plots look kooky.

---

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [November 14, 2018, 9:46pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/3 "2018-11-14T21:46:09Z")

</div>

Yes, sorry, my bad – `arviz` made a _very_ distorted plot that hid the exponential drop-off.

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [November 14, 2018, 10:04pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/4 "2018-11-14T22:04:53Z")

</div>

cc @RavinKumar, @aloctavodia, @colcarroll

---

<div class="post-metadata">

### Author: ![aloctavodia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aloctavodia/32/8642_2.png) [@aloctavodia](https://discourse.pymc.io/u/aloctavodia)
#### Post date: [November 14, 2018, 11:02pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/5 "2018-11-14T23:02:52Z")

</div>

Density plot, by default shows the values in the 94% hpd interval, your distributions have a very long tail with very low density, if you change from the 0.94 default to something like `credible_interval=0.999`, you should see something closer to what you are expecting

---

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [November 14, 2018, 11:28pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/6 "2018-11-14T23:28:34Z")

</div>

Yes, that’s true. But in my case, the behavior at the left end – in the range 0 ≤ x ≤ 10 – is what’s really important, and there _is_ a drop-off there. But arviz plotting this as a line plot obscures what’s really going on. A histogram plot captures the behavior in this case much better, because having only the default number of samples (500) is not nearly enough to approximate the curve well enough to plot it as a line… If I had 10 times the samples, it would be a better visualization…

---

<div class="post-metadata">

### Author: ![aloctavodia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aloctavodia/32/8642_2.png) [@aloctavodia](https://discourse.pymc.io/u/aloctavodia)
#### Post date: [November 14, 2018, 11:48pm UTC](https://discourse.pymc.io/t/bug-in-sample-prior-predictive/2210/7 "2018-11-14T23:48:12Z")

</div>

I see, I may have a solution, but I have to play with the code a little bit.

EDIT: [This](https://github.com/arviz-devs/arviz/pull/408) should fix the problem.
