BRMS model fails- Multivariate Mixed Model and Hurdle model

I have a GAMM that’s multivariate. It’s also a hurdle_gamma() model due to the presence of 0’s throughout the dataset. I continuously get errors when attempting to run the model and I’m not sure where they are coming from.

model <- bf(mvbind(var1, var2, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15 ) ~ gear_type + s(effort, k = 55) + s(doy, bs = 'cc', k = 20) + s(landing_year, k = 22) + s(forest, k = 15) + s(herbaceous, k = 15) + s(open_water, k = 15) + s(X,Y, bs= 'ts', k = 44) + (1|boat_id) + (1|landing_mun) + (1|basin_id),
            hu ~ gear_type + s(effort, k = 55) + s(doy, bs = 'cc', k = 20) + s(landing_year, k = 22) + s(forest, k = 15) + s(herbaceous, k = 15) + s(open_water, k = 15) + s(X,Y, bs= 'ts', k = 44) + (1|boat_id) + (1|landing_mun) + (1|basin_id)) + hurdle_gamma()

M1 <- 
  brm(formula = model,
      data = completed_catch_data,
      iter = 2000,
      warmup = 1000,
      cores = 4,
      save_warmup = FALSE)

I get the following error:

Compiling Stan program...
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
 parser failed badly

I’ve tried the recommended steps of uninstalling rstan and StanHeaders and reinstalling the github libraries for rstan and StanHeaders. I’ve double checked that my RTools C++ toolchain was downloaded and installed. What other explanations are there for this error?

A few questions that might also help me figure out the problem:
Do the knots for each smooth need to be specified by the knots argument in the brm() function instead of within the smooth? e.g., my model has s(x, bs =, k = ), should the knots for each smoothing term instead be moved to brm(knots = )?
Does the family argument in brm() need to be specified for the hurdle model to work? i.e., brm(family = hurdle_gamma())
Is there something about mvbind() that is causing this issue? I was able to run a single variable model with the same model as above without errors.

Insight appreciated.

  • Operating System: Windows 11
  • brms Version: 2.19.0
  • R version 4.3.1
  • RTools43

The brm formula specification appears ok, but this is a massively complicated model. My suggestion would be to start from a simple model and build up until you encounter the error. That would probably be the best way to isolate the problematic parts.

Does this mean you were able to run the entire model on each outcome, one at a time (i.e. 15 different models), with no problem? If so, I guess you could try writing out each formula and then using the brm(m1 + m2 + m3 + ...., syntax to see if mvbind was the problem.

Can you run the following on your system without errors (you might well get warnings about diagnostics etc, but this isn’t of interest for now).


df <- data.frame(a = abs(rnorm(10)), b = abs(rnorm(10)), c = rnorm(10))

brm(bf(a ~ c) + hurdle_gamma(), data = df)

brm(bf(a ~ c, hu ~ c) + hurdle_gamma(), data = df)

brm(bf(mvbind(a, b) ~ c, hu ~ c) + hurdle_gamma(), data = df)

Hello, I ran each of these models without an error. I am curious if the number of variables in mvbind() could be a problem, since I had 15 variables? I repeated your code with an additional variable without issue thought. I’m checking my data to make sure all variables are formatted correctly, since now it seems that my data could be the root of the problem

It is massively complicated lol. The full model fails, I am waiting to see if a single variable model goes through or if a 2 variable model using mvbind() works as well. The models take too long to run one by one but I may go that route next to determine if one of the 15 variables has an issue. I will try that syntax as well. Thanks!

The next thing to try is switching the backend to cmdstanr, which might give a more informative error message (or might just work!). Install R package cmdstanr and set up cmdstan following instructions here Getting started with CmdStanR • cmdstanr, then add backend = "cmdstanr" to your brm call.