# Sample\_prior\_predictive bug, gives wrong shape for dependent variable?

**URL:** <https://discourse.pymc.io/t/sample-prior-predictive-bug-gives-wrong-shape-for-dependent-variable/3648>\
**Category:** Questions\
**Created:** [July 29, 2019, 8:32pm UTC](https://discourse.pymc.io/t/sample-prior-predictive-bug-gives-wrong-shape-for-dependent-variable/3648 "2019-07-29T20:32:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenjioman](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kenjioman](https://discourse.pymc.io/u/kenjioman)\
**Post date:** [July 29, 2019, 8:32pm UTC](https://discourse.pymc.io/t/sample-prior-predictive-bug-gives-wrong-shape-for-dependent-variable/3648/1 "2019-07-29T20:32:51Z")

</div>

Minimum working Example:

```
import pandas as pd
import pymc3 as pm

foxes = pd.read_csv('https://github.com/rmcelreath/rethinking/raw/master/data/foxes.csv', sep=';')

with pm.Model() as mdl:
    a = pm.Normal('a', mu=0, sd=0.25)
    b = pm.Normal('b', mu=0, sd=0.4)
    mu = pm.Deterministic('mu', a + b * foxes.area.values.reshape(-1, 1))
    sigma = pm.Exponential('sigma', lam=1)
    weight = pm.Normal('weight', mu=mu, sd=sigma, observed=foxes.weight)
    
    prior = pm.sample_prior_predictive()

{k: prior[k].shape for k in prior.keys()}

```

As output I get:

```
{'a': (500,),
 'weight': (500, 116, 116),
 'mu': (500, 116, 1),
 'sigma': (500,),
 'b': (500,),
 'sigma_log__': (500,)}

```

For “weight”, I would have expected a shape of (500, 116), but instead get (500, 116, 116). Am I misunderstanding something with what sample\_prior\_predictive should be doing?

---

<div class="post-metadata">

**Author:** ![aseyboldt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aseyboldt/32/5795_2.png) [@aseyboldt](https://discourse.pymc.io/u/aseyboldt)\
**Post date:** [July 29, 2019, 8:38pm UTC](https://discourse.pymc.io/t/sample-prior-predictive-bug-gives-wrong-shape-for-dependent-variable/3648/2 "2019-07-29T20:38:59Z")

</div>

Not a bug 🙂  
The problem is that you reshaped `foxes.area`. Your dataset has shape `(N,)`, `mu` has shape `(N, 1)`. Those are broadcast using numpy rules to `(N, N)`. Basically, you are saying that you have `N` copies of each observation. To fix it just remove the reshape:

```auto
mu = pm.Deterministic('mu', a + b * foxes.area.values) 

```

---

<div class="post-metadata">

**Author:** ![kenjioman](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kenjioman](https://discourse.pymc.io/u/kenjioman)\
**Post date:** [July 29, 2019, 8:40pm UTC](https://discourse.pymc.io/t/sample-prior-predictive-bug-gives-wrong-shape-for-dependent-variable/3648/3 "2019-07-29T20:40:58Z")

</div>

Yeah, that did it – I didn’t realize that would make such a difference! Thanks for your help!!
