# Reparamterization in Stan

**URL:** <https://discourse.mc-stan.org/t/reparamterization-in-stan/22187>\
**Category:** Modeling\
**Tags:** specification\
**Created:** [April 29, 2021, 1:09am UTC](https://discourse.mc-stan.org/t/reparamterization-in-stan/22187 "2021-04-29T01:09:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [April 29, 2021, 1:09am UTC](https://discourse.mc-stan.org/t/reparamterization-in-stan/22187/1 "2021-04-29T01:09:58Z")

</div>

Hi,

Currently I am fitting such normal likelihood model in Stan:

```stan
model {
  y ~ normal(mu, sigma); 
} 

```

where mu and sigma are complex functions of parameters. I am currently thinking about reparamterization the model by directly modeling log(y), but not sure in this scenerio to what degree should I modify my Stan program. For example, could I just add ‘transformed data’ chunk and then using the following code:

```stan
data {
  int <lower = 0> N;
  vector[N] y;
}
transformed data {
  real<lower=0> sqrt_J;
  vector[N] y_trans = log(y);
}
model {
  exp(y_trans) ~ normal(mu, sigma); 
}

```

Thx!

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [April 29, 2021, 1:16am UTC](https://discourse.mc-stan.org/t/reparamterization-in-stan/22187/2 "2021-04-29T01:16:46Z")

</div>

If you want to model:

```stan
  log(y) ~ normal(mu, sigma)

```

Then you can just use the `lognormal` distribution:

```stan
  y ~ lognormal(mu, sigma);

```

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [April 29, 2021, 2:57am UTC](https://discourse.mc-stan.org/t/reparamterization-in-stan/22187/3 "2021-04-29T02:57:53Z")

</div>

Thanks so much for your kindly reply!

But now Y ~ normal rather than Y ~ lognormal, so I am a little bit confused about the reparamterization.

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [April 29, 2021, 3:16am UTC](https://discourse.mc-stan.org/t/reparamterization-in-stan/22187/4 "2021-04-29T03:16:57Z")

</div>

I think there are different things that you might intend here, and it’s worth sorting them out one-by-one. In what follows, I mean the exact same thing by `mu` and `sigma` (i.e. the exact same complex functions of parameters) everywhere I write `mu` and `sigma`. When I need to introduce other variables, I give them different names.

The question boils down to why you think this reparameterization is a good idea, or what you are trying to accomplish with the reparameterization.

- Maybe you want literally the same model, but somehow parameterized in terms of log(y) rather than in terms of `y`. This is sorta what it _looks_ like you’re aiming for with your posted code. If so, I think the answer is: _No, you do not want this_. If `y` is normally distributed with some mean and variance that you have expressions for, there is absolutely no way that it would be more convenient or efficient to sample on some other scale that corresponds to a distortion of `y`. Normal distributions are nice and easy. Why would you reparameterize to avoid a normal distribution?

- In recognition of the undesirability of reparameterizing to avoid a normal distribution, @andrjohns assumes (reasonably enough) that maybe you mean that you actually want to model the logarithm of `y` as normal.  
This is not a reparameterization, but rather a different model.

- Thinking more about the lognormal model (i.e. not just a reparameterization), maybe the problem is that you think `y` is distributed lognormally, but you still think that your complex functions that yield `mu` and `sigma` should yield approximately the mean and sd of `y`. In this case, maybe your real question is how to come up with a different pair of functions that might be expected to yield `mu_l` and `sigma_l`, the approximate mean and sd of log(y).

Does any of these feel like it captures your question well?
