# Individuals nested within groups

**URL:** <https://discourse.mc-stan.org/t/individuals-nested-within-groups/24057>\
**Category:** brms\
**Created:** [August 20, 2021, 2:11pm UTC](https://discourse.mc-stan.org/t/individuals-nested-within-groups/24057 "2021-08-20T14:11:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Szymon\_Mizak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/szymon_mizak/32/12303_2.png) [@Szymon\_Mizak](https://discourse.mc-stan.org/u/Szymon_Mizak)\
**Post date:** [August 20, 2021, 2:11pm UTC](https://discourse.mc-stan.org/t/individuals-nested-within-groups/24057/1 "2021-08-20T14:11:34Z")

</div>

Hello!

I have data from a behavioral experiment that I wanted to model using BRMS.In the data there are data of people belonging to 4 experimental groups. Each person has 25 data points. I am trying to describe the dependent variable using the model:

ip\_value = (1) / ((1 + k \* delay) \* (1 + h \* odds)

I would like the nonlinear parameters to be modeled at two levels - the experimental groups and the individuals nested within them. I use following code:

check\_fit = brm(formula = bf(ip\_value ~ (1) / ((1 + k \* delay) \* (1 + h \* odds)), k ~ 1 | condition / id, h ~ 1 | condition / id, nl = TRUE), data = sim, family = “gaussian”, chains = 2, iter = 6000, cores = 4, save\_pars = save\_pars(all = TRUE))

I have two questions:

1. Does the syntax correctly reflect the structure of the model I described in terms of groups and the individuals nested within them?
2. How should I transform the returned parameter values to get “meaningful” individual-level parameter estimates that I can feed into the model and predict a Y value from?

Below i attach the data I’m using

[dataIPS.csv](https://discourse.mc-stan.org/uploads/short-url/w0SOV0gmrrCmSaYxgN3jfhi7Dxt.csv) (159.8 KB)

- Operating System: macOS Big Sur 11.4
- brms Version: 2.15

---

<div class="post-metadata">

**Author:** ![StaffanBetner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/staffanbetner/32/11056_2.png) [@StaffanBetner](https://discourse.mc-stan.org/u/StaffanBetner)\
**Post date:** [August 20, 2021, 2:56pm UTC](https://discourse.mc-stan.org/t/individuals-nested-within-groups/24057/2 "2021-08-20T14:56:22Z")

</div>

> [@Szymon\_Mizak](#):
>
> Does the syntax correctly reflect the structure of the model I described in terms of groups and the individuals nested within them?

I was a bit unsure at first, since the structure is typically specified with parentheses around them, like `(1|higher/lower/evenlower)` but for a simple nested linear regression it seems to work without parentheses. The answer is yes. You might want to model them as correlated as well, like this:

```no-highlight
brm(formula = bf(ip_value ~ (1) / ((1 + k * delay) * (1 + h * odds)), 
                 k ~ (1 |p| condition)+(1 |q| condition:id), 
                 h ~ (1 |p| condition)+(1 |q| condition:id), 
                 nl = TRUE), 
    data = sim, 
    family = "gaussian", 
    chains = 2, 
    iter = 6000, 
    cores = 4, 
    save_pars = save_pars(all = TRUE))

```

---

<div class="post-metadata">

**Author:** ![Szymon\_Mizak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/szymon_mizak/32/12303_2.png) [@Szymon\_Mizak](https://discourse.mc-stan.org/u/Szymon_Mizak)\
**Post date:** [August 20, 2021, 3:18pm UTC](https://discourse.mc-stan.org/t/individuals-nested-within-groups/24057/3 "2021-08-20T15:18:57Z")

</div>

Great! Thank you very much!
