Error: Can only combine group-level terms of the same grouping factors

Please also provide the following information in addition to your question:

  • Operating System: Mac OS High Sierra v10.13.6
  • brms Version: 2.10.0

Hello again!

While running my imputation multilevel model I have been receiving the error:

“Error: Can only combine group-level terms of the same grouping factors”.


I am trying to model hormone values as the result of a series of demographic/social parameters in 2 primate species.

A simplified version of the model is:

brm(log_hormone ~ (1|q|Harem) * Species1Dummy + Species + Sex + Age)

Basically here is the issue: One of the species I am researching forms harems while the other does not. I wanted to include a random effect for harem membership since it is possible that some female hormone values may be the result of which harem they belong to; however, I was unsure how to do this considering that the other species does not even form this social grouping. It was suggested to me to include a dummy variable so that the harem effect would only be calculated for one of the species and ignored for the other.

However, I get the above error when I try to run this model.

Does anyone have a suggestion of how to circumvent this problem? I would prefer to do as much as possible in a single model rather than making multiple models, especially if that means I would have to reduce my sample size by half to focus on just the harem-forming species.

Thanks for the help!

Can you provide a minimaly fully reproducible example for me to check the problem myself?

Hey! Sure!

I just generated this example dataset and when I run it, I get the same error as before:

log_hormone   <- log(sample(1:100,100, replace = T))
Species       <- c(rep("A",50), rep("B",50))
Sex           <- sample(c("M","F"),100, replace = T )
Age           <- log(sample(5:25,100, replace = T))
Species1Dummy <- c(rep(1,50), rep(0,50))
Harem         <- c(sample(c("Prince","Hendrix","Elvis"), 50, replace = T), rep("No_Harem",50))
  d <- cbind(log_hormone,Species,Sex,Age,Species1Dummy,Harem)
  model <- brm(log_hormone ~ (1|q|Harem) * Species1Dummy + Species + Sex + Age, data = d)

Error: Can only combine group-level terms of the same grouping factors.

Thanks for helping me with this!

I see it now. You cannot multiple group level terms with other predictors. This is not supported by the syntax.

Ah! Thanks for letting me know. Are there any plans to potentially alter the syntax to allow this sort of computation in the future?