# Sample\_prior\_predictive doesn't work with Negative Binomial likelihood

**URL:** <https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767>\
**Category:** Questions\
**Created:** [March 30, 2020, 10:38am UTC](https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767 "2020-03-30T10:38:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [March 30, 2020, 10:38am UTC](https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767/1 "2020-03-30T10:38:05Z")

</div>

Hi all,  
The following model samples smoothly when using `pm.sample` and `pm.sample_posterior_predictive`. But it raises `ValueError: operands could not be broadcast together with shapes (500,10886) (500,)` when trying `pm.sample_prior_predictive` (10886 is the number of data points):

```python
with pm.Model() as m_bike_poisson:
    a = pm.Normal("a", 0.0, 0.5)
    bT = pm.Normal("bT", 0.0, 0.2)

    lam = pm.math.exp(a + bT * bike_data["temp_std"])
    scale = pm.Exponential("scale", 2.0)

    bike_count = pm.NegativeBinomial(
        "bike_count", mu=lam, alpha=scale, observed=bike_data["count"]
    )

    prior_checks = pm.sample_prior_predictive(random_seed=RANDOM_SEED)
    trace_bike_poisson = pm.sample(1000, tune=2000, random_seed=RANDOM_SEED)
    post_samples = pm.sample_posterior_predictive(
        trace_bike_poisson, random_seed=RANDOM_SEED
    )

```

The data simply come from Kaggle’s [bike-sharing demand](https://www.kaggle.com/c/bike-sharing-demand) contest.  
It looks like a shape issue when drawing random values from the Gamma distribution, but I wanted to be sure before raising a GitHub issue – I think @lucianopaz is the go-to person here?  
Thanks in advance 🖖

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [March 30, 2020, 9:58pm UTC](https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767/2 "2020-03-30T21:58:18Z")

</div>

Does it also fail if you explicitly pass the shape to the negative binomial? Something like `shape=bike_data["temp_std"].to_numpy().shape`?

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [March 31, 2020, 8:09am UTC](https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767/3 "2020-03-31T08:09:57Z")

</div>

Yes, same error I’m afraid 😕  
Do you want me to file a GH issue?

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [March 31, 2020, 8:24am UTC](https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767/4 "2020-03-31T08:24:00Z")

</div>

I think that would be the best thing to do. Although, with the covid quarantine and trying to deal with working from home, and all the family related stuff at the same time, I won’t be able to look into pymc development for some time. Hopefully someone else will be able to pitch in.

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [March 31, 2020, 8:56am UTC](https://discourse.pymc.io/t/sample-prior-predictive-doesnt-work-with-negative-binomial-likelihood/4767/5 "2020-03-31T08:56:03Z")

</div>

[Just did it](https://github.com/pymc-devs/pymc3/issues/3864), thanks Luciano.  
Will try and take a look, but same covid situation and working on other PRs.  
Hope you and your family are safe, and good luck for the quarantine!
