Divergent random effect in brms

Hello everyone,

I’ve been trying to fit the following brms model and the cor random effect doesn’t seem to converge.
What would be the appropriate solution? I attached the code, data and output of the model.
Thanks for the help!

rm(list=ls())
library(brms)
library(cmdstanr)

#get data
df=read.csv('./data/empirical_data/df.csv')

#formulas
formula_reveal =  coherence ~ 0 + Intercept+reveal + (reveal|subject)

#set priors
Intercept_prior = set_prior(
  prior = "normal(0,0.2)",
  class = "b",
  coef = "Intercept"
)
reveal_prior_weak = set_prior(
  prior = "normal(0,0.4)", 
  class = "b",
  coef = "reveal"
)


prior_reveal_weak=c(Intercept_prior,reveal_prior_weak)
#run reveal models
model_reveal_weak =
  brm(
    formula = formula_reveal,
    data = df,
    prior=prior_reveal_weak,
    family = bernoulli(link = "logit"),
    warmup = 1000,
    iter = 2000,
    chains = 4,
    cores = 4,
    seed = 123,
    backend ="cmdstanr"
  )

df.Rdata (1.8 MB)

1 Like

You could dive a bit deeper into the model output to understand why the divergent transitions are occurring, see e.g. this vignette from the bayesplot package.

If the problem is specifically with estimating the correlation between the random effects (Intercept and slope of reveal), you could also try simplifying the model by suppressing that correlation via the double vertical bar, i.e. formula_reveal = coherence ~ 0 + Intercept+reveal + (reveal||subject). But of course, I don’t know if that’s a sensible approach for your research questions etc.