# Quantile computations in Stan vs custom computation

**URL:** <https://discourse.mc-stan.org/t/quantile-computations-in-stan-vs-custom-computation/29440>\
**Category:** Modeling\
**Created:** [November 11, 2022, 3:28pm UTC](https://discourse.mc-stan.org/t/quantile-computations-in-stan-vs-custom-computation/29440 "2022-11-11T15:28:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaronas](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jmaronas/32/9949_2.png) [@jmaronas](https://discourse.mc-stan.org/u/jmaronas)\
**Post date:** [November 11, 2022, 3:28pm UTC](https://discourse.mc-stan.org/t/quantile-computations-in-stan-vs-custom-computation/29440/1 "2022-11-11T15:28:17Z")

</div>

Hello,

I am fitting a linear model and I am having a small trouble with the quantiles computation. In particular I have:

```nohighlight
transformed parameters {
  
  vector[N] mu = alpha + beta*x;

}

model {

  beta ~ normal( 0, sigma_beta );
  alpha ~ normal( mu_alpha, sigma_alpha );
  
  y ~ normal(mu, sigma);
}

```

and I am interested in computing the quantiles of `mu`. As far as I know it is correct to compute the quantiles of alpha and beta, and propagate them with the transformation. In other words I can do quantile\_alpha and quantile\_beta and get quantile\_mu = quantile\_beta \* x + quantile\_alpha. I am basing this claim on this paper [http://www.gatsby.ucl.ac.uk/~snelson/gpwarp.pdf](http://www.gatsby.ucl.ac.uk/~snelson/gpwarp.pdf) (sec 3.2).

However I am getting different results with this computation that with the quantiles that Stan returns. Can someone provide light into where this difference comes from?. I guess stan obtains mu\_post using alpha\_post and beta\_post and then compute quantiles directly from mu\_post

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [November 11, 2022, 3:59pm UTC](https://discourse.mc-stan.org/t/quantile-computations-in-stan-vs-custom-computation/29440/2 "2022-11-11T15:59:24Z")

</div>

> [@jmaronas](#):
>
> As far as I know it is correct to compute the quantiles of alpha and beta, and propagate them with the transformation. In other words I can do quantile\_alpha and quantile\_beta and get quantile\_mu = quantile\_beta \* x + quantile\_alpha. I am basing this claim on this paper [http://www.gatsby.ucl.ac.uk/~snelson/gpwarp.pdf](http://www.gatsby.ucl.ac.uk/~snelson/gpwarp.pdf) (sec 3.2).

That paper only considers a one-dimensional warping function.  
If either alpha or beta is known with certainty then the quantiles of the other are related to the quantiles of mu as you describe but I don’t think that holds when _both_ are uncertain.

For example, let’s say you have x=1 so that `mu = alpha + beta` and medians of both alpha and beta are zero. Now you know that there’s a 25% chance that both alpha and beta are \< 0 and thus mu \< 0, _and_ a 25% chance that both alpha and beta are \> 0 and thus mu \> 0 _but_ you still can’t say anything about the remaining 50% case where the signs of alpha and beta disagree.  
There’s no guarantee that median(alpha) + median(beta) = 0 is going to be the 50% quantile of mu, only that it is some quantile between 25% and 75%.

---

<div class="post-metadata">

**Author:** ![jmaronas](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jmaronas/32/9949_2.png) [@jmaronas](https://discourse.mc-stan.org/u/jmaronas)\
**Post date:** [November 11, 2022, 4:05pm UTC](https://discourse.mc-stan.org/t/quantile-computations-in-stan-vs-custom-computation/29440/3 "2022-11-11T16:05:41Z")

</div>

Okay that is what I was hoping, that the result from that paper only holds for a one-dimensional warping function.
