# Prior predictive distribution as in posterior\_predict/epred

**URL:** <https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541>\
**Category:** rstanarm\
**Tags:** prior-predictive\
**Created:** [January 31, 2021, 12:35pm UTC](https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541 "2021-01-31T12:35:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Angelo\_D\_Ambrosio](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/angelo_d_ambrosio/32/5298_2.png) [@Angelo\_D\_Ambrosio](https://discourse.mc-stan.org/u/Angelo_D_Ambrosio)\
**Post date:** [January 31, 2021, 12:35pm UTC](https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541/1 "2021-01-31T12:35:35Z")

</div>

Hello,

Is there a way to have a prior predictive distribution with the same output structure as posterior\_predict/epred. I was only able to extract the parameters prior, not the output one.

Thanks

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [February 9, 2021, 8:25am UTC](https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541/2 "2021-02-09T08:25:12Z")

</div>

Hi,

don’t know if this will help you but in `brms` one can always sample with `sample_prior="only"`, and thus get a “posterior” which consists of values sampled only from the priors.

I’m a bit unsure what you mean by “not the output one.”

---

<div class="post-metadata">

**Author:** ![Angelo\_D\_Ambrosio](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/angelo_d_ambrosio/32/5298_2.png) [@Angelo\_D\_Ambrosio](https://discourse.mc-stan.org/u/Angelo_D_Ambrosio)\
**Post date:** [February 11, 2021, 7:39pm UTC](https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541/3 "2021-02-11T19:39:12Z")

</div>

Sorry, it was unclear, I meant the prior distribution of the outcome of the model, that is solving the model using the prior values for the parameters, which is what posterior\_predict/epred does.

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [February 12, 2021, 7:44am UTC](https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541/4 "2021-02-12T07:44:15Z")

</div>

I might misunderstand you but,

run with `brms` (notice I only sample from the priors using `sample_prior="only"`)

```r
library(rethinking)
data(chimpanzees)
d <- chimpanzees
detach(package:rethinking, unload = T)
library(brms)
rm(chimpanzees)

m <-
  brm(data = d, family = binomial,
      pulled_left | trials(1) ~ 1 + prosoc_left,
      prior = c(prior(normal(0, 10), class = Intercept),
                prior(normal(0, 10), class = b)),
      sample_prior = "only")

pl <- posterior_linpred(m)
pe <- posterior_epred(m)
pp <- posterior_predict(m)

```

Each variable now contains 504 rows and 4000 cols. So the model looks like this:

\mathrm{pulled\_left}\_i \sim \mathrm{Binomial}(1,p\_i)\\ p\_i = \mathrm{inv\_logit}(q\_i)\\ q\_i = \alpha + \beta\_p \cdot \mathrm{prosoc\_left}\_i \\ \alpha \sim \mathrm{Normal}(0, 10)\\ \beta\_p \sim \mathrm{Normal}(0, 10)

then,

- `pl` has posterior draws of q
- `pe` has draws of p, i.e., applying the link function, in this case `inv_logit()`
- `pp` has draws from \mathrm{Binomial}(1,p), i.e., the data is on the outcome scale (0/1). (Binomial has no dispersion).

```r
> table(pp)
pp
      0 1 
1006469 1009531

```

See here for the example I use translated by @Solomon from McElreath’s book:

> **[10 Counting and Classification | Statistical Rethinking with brms, ggplot2,...](https://bookdown.org/ajkurz/Statistical_Rethinking_recoded/counting-and-classification.html)**
>
> This project is an attempt to re-express the code in McElreath’s textbook. His models are re-fit in brms, plots are redone with ggplot2, and the general data wrangling code predominantly follows the tidyverse style.

and here where @jonah explains it very nicely:

> [@Reproduce posterior\_predict from posterior\_linpred for a neg binom spline model](https://discourse.mc-stan.org/t/reproduce-posterior-predict-from-posterior-linpred-for-a-neg-binom-spline-model/18835/2):
>
> Hi Angelo, here’s a brief explanation of the difference. Suppose you have a negative binomial regression with a log link: \eta\_i = a + bx\_i \\ \lambda\_i = \exp(\eta\_i) \\ y\_i \sim {\rm NegBinom}(\lambda\_i, \phi) posterior\_linpred() gives you posterior draws of \eta. posterior\_linpred(transform=TRUE), or equivalently posterior\_epred(), gives you posterior draws of \lambda, that is, it does the inverse link transformation for you. posterior\_predict() gives you draws from {\rm NegBinom}(\l…

---

<div class="post-metadata">

**Author:** ![Angelo\_D\_Ambrosio](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/angelo_d_ambrosio/32/5298_2.png) [@Angelo\_D\_Ambrosio](https://discourse.mc-stan.org/u/Angelo_D_Ambrosio)\
**Post date:** [February 19, 2021, 4:19pm UTC](https://discourse.mc-stan.org/t/prior-predictive-distribution-as-in-posterior-predict-epred/20541/5 "2021-02-19T16:19:29Z")

</div>

Thanks! I actually solved too using brms since rstanarm seemingly doesn’t allow this!
