Error composing multiple brms formulas for multivariate model - failure to create sampler, variable name not found

Hi folks,

I’m trying to fit a multivariate model to some data - the same participants, three different tasks, a few shared predictors. The data for the model is here multivar_dat.csv (223.5 KB)
, and the code is below - also I’m using brms 2.15.9.

bf_blicks <- bf(PreferAntepenult|subset(Blicks == TRUE) ~ (1|a|Subject)+(1|Item))+bernoulli()

  
bf_trisyllabic_local <- bf(DerivativeStressTrisyll|subset(DerivativesTrisyll == TRUE) ~ 
                            scale(LocalBaseFreq)+
                            StressProfile+
                            TypeOfRemoteBase+
                            (1+
                               scale(LocalBaseFreq)+
                               StressProfile+                 
                               TypeOfRemoteBase|a|Subject)+
                            (1|Item)
                            )+categorical()

bf_disyllabic_local <- bf(DerivativeStressDisyll|subset(DerivativesDisyll == TRUE) ~
                      scale(LocalBaseFreq)+
                      TypeOfRemoteBase+
                      StressProfile+
                      (1+
                         scale(LocalBaseFreq)+
                      TypeOfRemoteBase+
                      StressProfile
                      |a|Subject)+
                      (1|Item))+bernoulli()
                      
                      

job({multivar_model<- brm(
  formula = bf_blicks+bf_trisyllabic_local+bf_disyllabic_local, 
  data = multivar_dat,
  chains = 4, 
  cores = 4, 
  warmup = 1000, 
  iter = 2000, 
  file = "./Models/a_first_multivariate_model", 
  save_all_pars = T, 
  save_model = './Models/a_first_multivariate_model_stan'
  )})


I’m running into the error

Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  Exception: variable does not exist; processing stage=data initialization; variable name=Z_2_mu2_DerivativeStressTrisyll_7; base type=double (in 'string', line 50, column 2 to column 70)
failed to create the sampler; sampling not done

And I’m not sure what to do - the same thing happens when I run only two of the models together at a time. Any suggestions on how to proceed? Also, I’m not sure if this is a brms-level error or a stan-level error, so please let me know if I’m posting this in the wrong place.

Sincerely,
Canaan

1 Like

Update here - I continued fussing around with the model, and it looks like this problem only pops up if I have random slopes. I’d definitely still like to fix that problem, but if I get the model to fit without it, the model throws an error when a specific main effect is included, ‘TypeOfRemoteBase’ - I get errors like

Warning in x$fit@sim$fnames_oi[change$pos] <- change$fnames :
  number of items to replace is not a multiple of replacement length
Warning in names(x$fit@sim$samples[[i]])[change$pos] <- change$fnames :
  number of items to replace is not a multiple of replacement length
Warning in names(x$fit@sim$samples[[i]])[change$pos] <- change$fnames :
  number of items to replace is not a multiple of replacement length
Warning in names(x$fit@sim$samples[[i]])[change$pos] <- change$fnames :
  number of items to replace is not a multiple of replacement length
Warning in names(x$fit@sim$samples[[i]])[change$pos] <- change$fnames :
  number of items to replace is not a multiple of replacement length

The error looks a lot like the ones noticed here and here, but those were apparently resolved via a subsequent update. Any advice on what to do in this case?

Thanks,
Canaan

1 Like

Hi, sorry for not getting to you earlier.

This indeed could be a bug in brms. However, the model as it stands is quite complex, could you help us by removing formulas/terms to find the simplest example that still exhibits the issue?