# Grouping structure 'gr' expects only a single grouping term

**URL:** <https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196>\
**Category:** brms\
**Tags:** techniques\
**Created:** [September 24, 2020, 11:03pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196 "2020-09-24T23:03:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Afilion](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Afilion](https://discourse.mc-stan.org/u/Afilion)\
**Post date:** [September 24, 2020, 11:03pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/1 "2020-09-24T23:03:38Z")

</div>

Dear Paul,

I have now been working with phylogenetically corrected models in brms for the past two years. I noticed that the previously used cov\_ranef function was now replaced with a grouping argument inside the gr function. However, when I tried the implement the same structure as the one I used with cov\_ranef, I get the following error: Grouping structure ‘gr’ expects only a single grouping term. I am not well versed enough to understand specifically what it means as I only have one grouping factor in my very simple database. I therefore looked at the example that was posted in the phylogenetic vignette of brms and copied it into my R session. However, I still get the same error when trying to run the model… Would you be able to help me on how to solve this issue?

All the best!

Antoine

Session info:  
R version 4.0.0 (2020-04-24)  
Platform: x86\_64-w64-mingw32/x64 (64-bit)  
Running under: Windows 10 x64 (build 18363)

```
phylo <- ape::read.nexus("https://paul-buerkner.github.io/data/phylo.nex")
data_simple <- read.table(
  "https://paul-buerkner.github.io/data/data_simple.txt", 
  header = TRUE
)

A <- ape::vcv.phylo(phylo)

model_simple <- brm(
  phen ~ cofactor + (1|gr(phylo, cov = A)), 
  data = data_simple, 
  family = gaussian(), 
  data2 = list(A = A),
  prior = c(
    prior(normal(0, 10), "b"),
    prior(normal(0, 50), "Intercept"),
    prior(student_t(3, 0, 20), "sd"),
    prior(student_t(3, 0, 20), "sigma")
  )
)

Output: Error: Grouping structure 'gr' expects only a single grouping term

```

If you need to use math formula, use Latex syntax:

Y \sim N(\mu, \sigma)

Don’t forget to attach tags (top right of this form) for application area/class of models or other general subject areas your topic touches on.

---

<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:** [September 25, 2020, 5:27am UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/2 "2020-09-25T05:27:17Z")

</div>

Your brms version is likely just out of date.

---

<div class="post-metadata">

**Author:** ![msparks](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@msparks](https://discourse.mc-stan.org/u/msparks)\
**Post date:** [September 30, 2020, 3:42pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/3 "2020-09-30T15:42:37Z")

</div>

I am having the same error with my own data and the " Estimating Phylogenetic Multilevel Models with brms" vignette simple data. brms version is 2.13.5

I am running this on our compute cluster here with R version 3.5.1. Could that be contributing to it?

---

<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:** [September 30, 2020, 3:48pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/4 "2020-09-30T15:48:17Z")

</div>

I don’t think you have brms 2.13.5 on the system as cov argument exists there already. For what it’s worth, try out also the latest github version of brms.

---

<div class="post-metadata">

**Author:** ![msparks](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@msparks](https://discourse.mc-stan.org/u/msparks)\
**Post date:** [September 30, 2020, 4:25pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/5 "2020-09-30T16:25:53Z")

</div>

Here is the code and results from our server:

```
> phylo <- ape::read.nexus("https://paul-buerkner.github.io/data/phylo.nex")
> data_simple <- read.table(
+ "https://paul-buerkner.github.io/data/data_simple.txt",
+ header = TRUE
+ )
> A <- ape::vcv.phylo(phylo)
> model_simple <- brm(
+ phen ~ cofactor + (1|gr(phylo, cov = A)),
+ data = data_simple,
+ family = gaussian(),
+ data2 = list(A = A),
+ prior = c(
+ prior(normal(0, 10), "b"),
+ prior(normal(0, 50), "Intercept"),
+ prior(student_t(3, 0, 20), "sd"),
+ prior(student_t(3, 0, 20), "sigma")
+ )
+ )
Error: Grouping structure 'gr' expects only a single grouping term

 > packageVersion("brms")
[1] ‘2.13.5’

> version
               _
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 5.1
year 2018
month 07
day 02
svn rev 74947
language R
version.string R version 3.5.1 (2018-07-02)
nickname Feather Spray
```

---

<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:** [September 30, 2020, 4:45pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/6 "2020-09-30T16:45:28Z")

</div>

Can you try again with the brms gihub version?

---

<div class="post-metadata">

**Author:** ![Afilion](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Afilion](https://discourse.mc-stan.org/u/Afilion)\
**Post date:** [September 30, 2020, 9:35pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/7 "2020-09-30T21:35:45Z")

</div>

Dear Paul,

I just updated my brms version to 2.13.5 using github and it works perfectly now!

Thank you for your help!

Antoine

---

<div class="post-metadata">

**Author:** ![msparks](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@msparks](https://discourse.mc-stan.org/u/msparks)\
**Post date:** [October 2, 2020, 2:39pm UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/8 "2020-10-02T14:39:30Z")

</div>

I am having issues with the devtools package on our cluster, bur installed the github version on my personal machine and the grouping issue was fixed. Thanks Paul!

---

<div class="post-metadata">

**Author:** ![Verkerk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/verkerk/32/10600_2.png) [@Verkerk](https://discourse.mc-stan.org/u/Verkerk)\
**Post date:** [March 17, 2022, 9:49am UTC](https://discourse.mc-stan.org/t/grouping-structure-gr-expects-only-a-single-grouping-term/18196/9 "2022-03-17T09:49:03Z")

</div>

I encounter the same problem on our cluster. brms is version 2.9.0; R version 3.6.1 (2019-07-05).

I am using Miniconda and I don’t think I can install any newer versions of R/brms, but I will find out. Is there a work around for this cluster set up with older versions of brms/R? Should I use cov\_ranef instead?

Many thanks,  
Annemarie
