Parsing error with random effect in brms

I am using brms 2.18.0 and get an error message when estimating a model with a random effect.

This is the model code:

M1 <- brm(
  fluency ~ 1 + Occ2*FL + Occ2*MT + Occ3*FL + Occ3*MT + (1|student) ,
  data = Subtitles,
  cores = 4,
  backend = "cmdstanr",
  seed = 1975,
  prior = Custom_prior1

This generates the following error:

Syntax error in '/var/folders/x9/dk2f_b5575ddx5s7sscrgtch0000gn/T/RtmpkeCz4K/model_ca7319f434761380a27341051b9df070.stan', line 12, column 18 to column 19, parsing error:
    10:    int<lower=1> N_1;  // number of grouping levels
    11:    int<lower=1> M_1;  // number of coefficients per level
    12:    int<lower=1> J_1[N];  // grouping indicator per observation
    13:    // group-level predictor values
    14:    vector[N] Z_1_1;

";" expected after variable declaration.

Error: Syntax error found! See the message above for more information.

When leaving out the +(1|student) in the model, the model compiles and gets estimated.

I have no clue what’s happening. But could it be due to the fact that I updated my laptop to macOS Sonoma (v. 14.3)?

Thanks for your help

Under the hood, brms translates your formula to raw Stan code and passes the code off to cmdstan to run it. I think this error is because your version of brms is doing this translation using an older, now deprecated Stan syntax. Your model fits when you remove the random group-level intercept term for student because the problematic line containing the old syntax isn’t added in.

I suggest updating to the latest versions of these tools:

  1. Restart a fresh R session
  2. Update brms package the usual way
  3. Update cmdstanr package, then run cmdstanr::install_cmdstan()to make sure cmdstan is up to date. This step may not be necessary since it looks like your Stan version is newer and is not allowing the older syntax. Still, it’d be a good idea and might help avoid other version incompatibilities.
  4. Re-try your code

If you’re still getting an error, let us know.

Thanks! Makes perfect sense. I updated everything and the error is gone.

1 Like