# Sample\_posterior\_predictive\_w

**URL:** <https://discourse.pymc.io/t/sample-posterior-predictive-w/10982>\
**Category:** v5\
**Tags:** development\
**Created:** [December 10, 2022, 8:59am UTC](https://discourse.pymc.io/t/sample-posterior-predictive-w/10982 "2022-12-10T08:59:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![opherdonchin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/opherdonchin/32/5948_2.png) [@opherdonchin](https://discourse.pymc.io/u/opherdonchin)\
**Post date:** [December 10, 2022, 8:59am UTC](https://discourse.pymc.io/t/sample-posterior-predictive-w/10982/1 "2022-12-10T08:59:54Z")

</div>

I’m using Google Colab for teaching Bayesian statistics and it is curently on PyMC 4.1.4 and Arviz 12.1. I’m teaching out of [Bayesian Analysis with Python](https://github.com/aloctavodia/BAP) by @aloctavodia (as well as other texts).

In Chapter 5 of the text, they use the function `sample_posterior_predictive_w`. In PyMC 4.1.4 it says that this function is “not yet implemented” in PyMC 4. In the latest version of PyMC, it says that it is deprectated in favor of `weights_prediction` in `Arviz`. However, I didn’t find any mention of `weights_prediction` in the current versoin of Arviz. There is an [Arviz issue](https://github.com/arviz-devs/arviz/pull/2147) which I guess means it is merged into an upcoming release?

In any case, I’d like to be able to show this functionality in the Colab-current versions of Arviz and PyMC. Is there a simple way to do this?

Opher

---

<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:** [December 10, 2022, 11:40am UTC](https://discourse.pymc.io/t/sample-posterior-predictive-w/10982/2 "2022-12-10T11:40:34Z")

</div>

That function is available in the latest release or arviz (0.14.0). Not sure if that version is already available from colab. @RavinKumar, @colcarroll

---

<div class="post-metadata">

**Author:** ![opherdonchin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/opherdonchin/32/5948_2.png) [@opherdonchin](https://discourse.pymc.io/u/opherdonchin)\
**Post date:** [December 10, 2022, 12:36pm UTC](https://discourse.pymc.io/t/sample-posterior-predictive-w/10982/3 "2022-12-10T12:36:18Z")

</div>

So, colab is still on 12.1. I could probably install 14, but now I’m curious: is there an easy way to replicate the functionality without calling the function?

Opher

---

<div class="post-metadata">

**Author:** ![opherdonchin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/opherdonchin/32/5948_2.png) [@opherdonchin](https://discourse.pymc.io/u/opherdonchin)\
**Post date:** [December 10, 2022, 12:41pm UTC](https://discourse.pymc.io/t/sample-posterior-predictive-w/10982/4 "2022-12-10T12:41:45Z")

</div>

I’m sorry, @aloctavodia : I just installed version 0.14.0 on Colab and it doesn’t have a `az.weights_prediction()` function. Do I have the name wrong?

---

<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:** [December 10, 2022, 1:50pm UTC](https://discourse.pymc.io/t/sample-posterior-predictive-w/10982/5 "2022-12-10T13:50:02Z")

</div>

The function’s name is `weight_predictions`

Also the fuction is relatively simple, given a list of idatas with posterior predictive samples it takes a new set of samples from each idata, proportional to the weights. So if you have two models/idatas one with weight 0.6 and the other 0.4 and you ask for 1000 weighted samples, the function will return 600 samples from one model/idata and 400 from the other. You can check the code here

> <https://github.com/arviz-devs/arviz/blob/24e66c37c7b12d68fbe7b1c1bf5f0e28bc13a4fa/arviz/stats/stats.py#L2049>
