# Having two random effects in brms formula

**URL:** <https://discourse.mc-stan.org/t/having-two-random-effects-in-brms-formula/29121>\
**Category:** General\
**Tags:** brms\
**Created:** [October 13, 2022, 6:48am UTC](https://discourse.mc-stan.org/t/having-two-random-effects-in-brms-formula/29121 "2022-10-13T06:48:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discourse.mc-stan.org/u/ali)\
**Post date:** [October 13, 2022, 6:48am UTC](https://discourse.mc-stan.org/t/having-two-random-effects-in-brms-formula/29121/1 "2022-10-13T06:48:56Z")

</div>

hello,

dear all, i have a question about my analysis.  
i did an experiment with some participants and each participant did some trials.  
we are trying to fit a sigmoid function for the speed profiles of the participants.  
now I want to specify one random effect for each participant and one for the trial.  
I tried in this way and I am not sure If it’s correct. can somebody help me on thin? thanks

bf\_speed ← bf(v ~ ((5-a)/ (1 + exp(c \* (t - b)))+a),  
a+b+c ~ 1 + (1|k|trial\_id) + (1|m|participant\_id)

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [October 13, 2022, 4:32pm UTC](https://discourse.mc-stan.org/t/having-two-random-effects-in-brms-formula/29121/2 "2022-10-13T16:32:11Z")

</div>

Welcome to the forum.

Looks like the response is nonlinear wrt `a`, `b`, and `c` (assume `t` is a predictor). Try add `nl=TRUE` (see [Estimating Non-Linear Models with brms](https://cran.r-project.org/web/packages/brms/vignettes/brms_nonlinear.html)). Also no need for `k` and `m` here, see [Estimating Multivariate Models with brms • brms](https://paul-buerkner.github.io/brms/articles/brms_multivariate.html). In general going through vignettes before diving into modeling usually helps.

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discourse.mc-stan.org/u/ali)\
**Post date:** [October 25, 2022, 7:08am UTC](https://discourse.mc-stan.org/t/having-two-random-effects-in-brms-formula/29121/3 "2022-10-25T07:08:59Z")

</div>

thanks a lot yizhang for your reply.  
i learned a lot from the links that you shared.  
i think my problem is with the priors and the euqtion.
