Error compiling brms model

I am attempting to fit a model in brms and I am using cmdstanr as the backend. I am getting the following error:

fatal error: bracket nesting level exceeded maximum of 256
...
note: use -fbracket-depth=N to increase maximum nesting level

The model formula is

response ~ X + X:Y

(because Y is nested within X). X is a factor with 17 levels, Y is a factor with 22 levels.

Running on a subset of the data such that X has 9 levels and Y has 12 levels, the model compiles without problems and produces a sensible fit without issues.

For this reason, I am guessing this has something to do with the number of levels (which is large, due to the interaction), but that’s just a guess.

Is there a suggested solution? For example, what do I need to do to “use -fbracket-depth=N to increase maximum nesting level”?

For this you’ll need to update the make/local file of your cmdstanr install.

Run:

library(cmdstanr)

cpp_options <- list(
  "CXXFLAGS+= -fbracket-depth=1024"
)
cmdstan_make_local(cpp_options = cpp_options)

And then try your brms model again

1 Like

Beautiful – that works, thank you! Is there a way to make the -fbracket-depth=1024 change permanent? EDIT – Oh, I realise now, this is a permanent change!

1 Like