# Brms / non-linear models / correlated random effects

**URL:** <https://discourse.mc-stan.org/t/brms-non-linear-models-correlated-random-effects/12852>\
**Category:** brms\
**Created:** [January 28, 2020, 9:33pm UTC](https://discourse.mc-stan.org/t/brms-non-linear-models-correlated-random-effects/12852 "2020-01-28T21:33:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [January 28, 2020, 9:33pm UTC](https://discourse.mc-stan.org/t/brms-non-linear-models-correlated-random-effects/12852/1 "2020-01-28T21:33:37Z")

</div>

Hi!

I am wondering how I can fit correlations between random effects in non-linear models. For example:

```R
fit_loss <- brm(
  bf(cum ~ ult * (1 - exp(-(dev/theta)^omega)),
     ult ~ 1 + (1|AY), omega ~ 1, theta ~ 1 + (1|AY), 
     nl = TRUE),
  data = loss, family = gaussian(),
  prior = c(
    prior(normal(5000, 1000), nlpar = "ult"),
    prior(normal(1, 2), nlpar = "omega"),
    prior(normal(45, 10), nlpar = "theta")
  ),
  control = list(adapt_delta = 0.9)

```

So `ult` and `theta` now have a random effect on the intercept…but how can I fit their correlations?

Thanks.

Sebastian

---

<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:** [January 28, 2020, 9:40pm UTC](https://discourse.mc-stan.org/t/brms-non-linear-models-correlated-random-effects/12852/2 "2020-01-28T21:40:02Z")

</div>

Replace `(1 | AY)` by `(1 | ID | AY)` where ID can be anything as long as it is the same across terms you want to model as correlated. See `vignette("brms_multilevel")` for details.
