# Struggling with priors and standardization

**URL:** <https://discourse.mc-stan.org/t/struggling-with-priors-and-standardization/10042>\
**Category:** Modeling\
**Created:** [August 3, 2019, 1:21pm UTC](https://discourse.mc-stan.org/t/struggling-with-priors-and-standardization/10042 "2019-08-03T13:21:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/gang/32/13572_2.png) [@Gang](https://discourse.mc-stan.org/u/Gang)\
**Post date:** [August 3, 2019, 1:21pm UTC](https://discourse.mc-stan.org/t/struggling-with-priors-and-standardization/10042/1 "2019-08-03T13:21:42Z")

</div>

For the first dataset, here is the model I have been trying to fit with brms:

> y\_{ij} \sim N(a\_0 + a\_1 x\_i + b\_{0i} + b\_{1i} x \_i+ c\_j, s^2)  
> b\_{ki} \sim N(0, s\_{ki}^2), k = 0,1  
> c\_j \sim N(0, s\_2^2)

With

`mean(y) = 73, sd(y) = 556`

if I use the defaults priors in brms (improper uniform distribution for the population effects and half-Student(3) for the scale parameters, it took about 13 minutes with 4 chains and 1000 iterations. However, if I standardize the response variable y, convergence was fine, but the runtime was 3.5 hours with the same chains and iterations! My questions are:

(1) I have trouble properly adjusting the results in a hierarchical model due to centering and scaling from the standardization. Making adjustment at the random draw level or population/group effects level?

(2) Is it really a bad idea to standardize the response variable y? I got mixed information when reading the discussions from various sources. Why was the runtime dramatically worse after the standardization of the response variable (13 minutes vs. 3.5 hours)?

For the second dataset, the model is a little simpler:

> y\_{ij} \sim N(a + b\_i + c\_j, s^2)  
> b\_i \sim N(0, s\_1^2)  
> c\_j \sim N(0, s\_2^2)

With

`mean(y) = 0.025, sd(y) = 0.265`

I managed to get the model converged with the default priors, 8 chains and 2000 iterations. However, the results do not make sense because all the posterior distributions for

a + b\_i

were pretty much the same. I noticed that the posterior standard deviation s\_1 was very small: 0.0017 with a 95% quantile interval [0.00007, 0.00469]. So, I suspect the problem is the default priors. So, my third question is

(3) How to properly set priors in this context of hierarchical model?

---

<div class="post-metadata">

**Author:** ![scholz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/scholz/32/14298_2.png) [@scholz](https://discourse.mc-stan.org/u/scholz)\
**Post date:** [August 3, 2019, 1:52pm UTC](https://discourse.mc-stan.org/t/struggling-with-priors-and-standardization/10042/2 "2019-08-03T13:52:15Z")

</div>

> [@Gang](#):
>
> (3) How to properly set priors in this context of hierarchical model?

Hey, here are some sources on how to find to find the right priors that I found that might help you as well:

- There are two examples here: [https://github.com/torkar/BDA\_in\_ESE](https://github.com/torkar/BDA_in_ESE) both in the toy example and in the missing data example.
- McElreath talks about how to find good priors in the second edition of his book a little. You can find lectures, slides and a draft here: [GitHub - rmcelreath/statrethinking\_winter2019: Statistical Rethinking course at MPI-EVA from Dec 2018 through Feb 2019](https://github.com/rmcelreath/statrethinking_winter2019)

From what I understand, it essentially comes down to you plotting the combined prior and trying out different values so prevent too much weight on extreme values but still allow the sampling to explore the parameter space properly.  
As far as I understand, this is essentially a trial and error thing combined with some experience.

I don’t think I have enough experience to help with the other two questions so I’d rather not add my thoughts and let someone with more experience do that instead.

And discourse does support math mode:

```no-highlight
$y_{ij} \sim N(a + b_i +c_j, s²)$

```

turns into:  
y\_{ij} \sim N(a + b\_i +c\_j, s²)
