# Issues while using sample\_posterior\_predictive \_w to compute probability or weights

**URL:** https://discourse.pymc.io/t/issues-while-using-sample-posterior-predictive-w-to-compute-probability-or-weights/5934
**Category:** Questions
**Created:** [October 8, 2020, 1:06pm UTC](https://discourse.pymc.io/t/issues-while-using-sample-posterior-predictive-w-to-compute-probability-or-weights/5934 "2020-10-08T13:06:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![VIDYA](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/vidya/32/3314_2.png) [@VIDYA](https://discourse.pymc.io/u/VIDYA)
#### Post date: [October 8, 2020, 1:06pm UTC](https://discourse.pymc.io/t/issues-while-using-sample-posterior-predictive-w-to-compute-probability-or-weights/5934/1 "2020-10-08T13:06:11Z")

</div>

Hi all,

I have one doubt regarding 'sample\_posterior\_predictive function. Actually I wish to compute the weights(probability) of predicted samples. So I used the function  
“pymc3.sampling.sample\_posterior\_predictive\_w(trace)”.  
But when I’m trying to run this , an error occured. Its like

AttributeError Traceback (most recent call last)  
in  
----\> 1 ppc\_w = pm.sample\_posterior\_predictive\_w(trace, 1000, model\_particle,progressbar=False)

~/.local/lib/python3.6/site-packages/pymc3/sampling.py in sample\_posterior\_predictive\_w(traces, samples, models, weights, random\_seed, progressbar)  
1786 traces = [dataset\_to\_point\_dict(trace) for trace in traces]  
1787 else:  
-\> 1788 n\_samples = [len(i) \* i.nchains for i in traces]  
1789  
1790 if models is None:

~/.local/lib/python3.6/site-packages/pymc3/sampling.py in (.0)  
1786 traces = [dataset\_to\_point\_dict(trace) for trace in traces]  
1787 else:  
-\> 1788 n\_samples = [len(i) \* i.nchains for i in traces]  
1789  
1790 if models is None:

AttributeError: ‘dict’ object has no attribute ‘nchains’

Can anybody help me to resolve this error. Thanks in advance

How to calculate the weights (probability) of posterior function generated using pymc3.model().Is this the correct method?

---

<div class="post-metadata">

### Author: ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)
#### Post date: [October 9, 2020, 5:12am UTC](https://discourse.pymc.io/t/issues-while-using-sample-posterior-predictive-w-to-compute-probability-or-weights/5934/2 "2020-10-09T05:12:05Z")

</div>

I suspect that you are passing a single trace object, whereas `sample_posterior_predictive_w()` takes a _list_ of traces (see [the documentation](https://docs.pymc.io/api/inference.html#pymc3.sampling.sample_posterior_predictive_w)). `sample_posterior_predictive_w()` allows you to sample from a _set_ of posteriors according to the supplied `weights`, as one might do when doing [model averaging](https://docs.pymc.io/notebooks/model_averaging.html).

---

<div class="post-metadata">

### Author: ![VIDYA](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/vidya/32/3314_2.png) [@VIDYA](https://discourse.pymc.io/u/VIDYA)
#### Post date: [October 9, 2020, 6:22am UTC](https://discourse.pymc.io/t/issues-while-using-sample-posterior-predictive-w-to-compute-probability-or-weights/5934/3 "2020-10-09T06:22:58Z")

</div>

Thanks a lot. I didn’t notice that exactly.  
Let me try in that way
