# Posterior\_linpred for brms

**URL:** <https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548>\
**Category:** brms\
**Created:** [March 5, 2020, 7:48pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548 "2020-03-05T19:48:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lauren](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@lauren](https://discourse.mc-stan.org/u/lauren)\
**Post date:** [March 5, 2020, 7:48pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/1 "2020-03-05T19:48:09Z")

</div>

Hi @paul.buerkner

I’m trying to use posterior\_linpred with a brms logisitic regression. Can I just confirm that if I do

posterior\_linpred(brms.object, transform=TRUE)

then to get the probability that a single response is 0 o 1 I need to divide by the number of observations for that particular row? It seems like that makes sense but I just want to be sure.

@kuriwaki @mitzimorris

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [March 5, 2020, 8:00pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/2 "2020-03-05T20:00:41Z")

</div>

I would recommend using `pp_expect(...)` instead of `posterior_linpred(..., transform = TRUE)` but they will yield the same results, which is the posterior of the expected value of the PPD. If the number of trials in the logistic regression is 1, this will indeed correspond to the probabilities.

---

<div class="post-metadata">

**Author:** ![kuriwaki](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kuriwaki/32/5983_2.png) [@kuriwaki](https://discourse.mc-stan.org/u/kuriwaki)\
**Post date:** [March 5, 2020, 8:37pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/3 "2020-03-05T20:37:20Z")

</div>

Thank you. Didn’t know about `pp_expect` – I see it was introduced in brms 2.11 ([https://github.com/paul-buerkner/brms/issues/644](https://github.com/paul-buerkner/brms/issues/644))

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [March 5, 2020, 8:40pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/4 "2020-03-05T20:40:43Z")

</div>

It is a new brms method which will eventually be used in rstanarm as well. I prefer it because, for more complex models, the transformed linear predictor is no longer the mean of the response distribution (take the lognormal distribution as an example).

---

<div class="post-metadata">

**Author:** ![kuriwaki](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kuriwaki/32/5983_2.png) [@kuriwaki](https://discourse.mc-stan.org/u/kuriwaki)\
**Post date:** [March 5, 2020, 8:51pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/5 "2020-03-05T20:51:16Z")

</div>

> [@paul.buerkner](#):
>
> If the number of trials in the logistic regression is 1, this will indeed correspond to the probabilities.

Following up, if its binomial and `trials(n) > 1`, is there a way to get posterior expectation in probabilities there? (e.g. where trials = 3 and the estimated expectation is 2.5, `pp_expect` will output 0.83.) I can see you can get these by dividing by the appropriate `model$data$n`, but we were wondering if there was a way to do that internally.

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [March 5, 2020, 8:54pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/6 "2020-03-05T20:54:37Z")

</div>

If the information passed to `trials` is a variable, say `n`, you can set `n = 1` in `newdata`.

---

<div class="post-metadata">

**Author:** ![kuriwaki](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kuriwaki/32/5983_2.png) [@kuriwaki](https://discourse.mc-stan.org/u/kuriwaki)\
**Post date:** [March 5, 2020, 9:46pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/7 "2020-03-05T21:46:35Z")

</div>

That’s a great trick – thank you.

---

<div class="post-metadata">

**Author:** ![stefanoc88](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stefanoc88/32/17953_2.png) [@stefanoc88](https://discourse.mc-stan.org/u/stefanoc88)\
**Post date:** [December 4, 2025, 4:22pm UTC](https://discourse.mc-stan.org/t/posterior-linpred-for-brms/13548/8 "2025-12-04T16:22:16Z")

</div>

In relation to this, I noticed that `posterior_linpred(transform = TRUE)` for lognormal models gives the same result as `posterior_linpred(transform = FALSE)`. Is this expected?

~~EDIT: I was only looking at mu. So then the question is, why is mu still on the link scale even if transform = TRUE? Or am I misunderstanding? Actually, I am totally confused… :/~~

~~EDIT 2: I think I misunderstand what transform = TRUE does in posterior\_linpred with lognormal models.~~

EDIT 3: I think the answer is that the link for mu is identity while for sigma it is log.
