# Sampling from posterior predictive distribution

**URL:** <https://discourse.julialang.org/t/sampling-from-posterior-predictive-distribution/32738>\
**Category:** Probabilistic Programming\
**Created:** [December 27, 2019, 9:11am UTC](https://discourse.julialang.org/t/sampling-from-posterior-predictive-distribution/32738 "2019-12-27T09:11:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirtsar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kirtsar/32/7222_2.png) [@kirtsar](https://discourse.julialang.org/u/kirtsar)\
**Post date:** [December 27, 2019, 9:11am UTC](https://discourse.julialang.org/t/sampling-from-posterior-predictive-distribution/32738/1 "2019-12-27T09:11:11Z")

</div>

I’m completely new to Bayesian Inference stuff, now I’m reading “Statistical Rethinking” book chap. 3. There is a concept of “posterior predictive distribution” when I take the “sum” of weighted distributions according to posterior distribution of those parameters.

I was able to make it for coin toss example using Mixture Model from Distributions:

```julia
mix = MixtureModel(map(p -> Binomial(9, p), 0 : 1/1000 : 1), posterior)

```

where `posterior` is the posterior probability mass function for parameter p.

I wonder whether it could be implemented more clearly using all these packages, like Turing or Gen or something else.

---

<div class="post-metadata">

**Author:** ![trappmartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trappmartin/32/1165_2.png) [@trappmartin](https://discourse.julialang.org/u/trappmartin)\
**Post date:** [December 27, 2019, 10:11am UTC](https://discourse.julialang.org/t/sampling-from-posterior-predictive-distribution/32738/2 "2019-12-27T10:11:37Z")

</div>

The recently merged PR in Turing allows you to do this concisely after inference has been performed using sampling (MCMC) or variational Bayes (VI).

So the answer is, yes this exists in Turing master. We will add some documentation to explain what the syntax is.

---

<div class="post-metadata">

**Author:** ![cscherrer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cscherrer/32/7631_2.png) [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Post date:** [December 27, 2019, 1:13pm UTC](https://discourse.julialang.org/t/sampling-from-posterior-predictive-distribution/32738/3 "2019-12-27T13:13:59Z")

</div>

Yes! There’s an example in the Soss.jl README using the `predictive` function. Please let me know if you have any trouble with it

---

<div class="post-metadata">

**Author:** ![torkar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkar/32/5646_2.png) [@torkar](https://discourse.julialang.org/u/torkar)\
**Post date:** [December 27, 2019, 4:32pm UTC](https://discourse.julialang.org/t/sampling-from-posterior-predictive-distribution/32738/4 "2019-12-27T16:32:38Z")

</div>

For the future: Rob’s statistical rethinking for Julia package could be of interest:  
[https://github.com/StatisticalRethinkingJulia/StatisticalRethinking.jl](https://github.com/StatisticalRethinkingJulia/StatisticalRethinking.jl)
