Drift Diffusion Modeling with Continuous Predictors; dimensions mismatch

I am trying to run a drift diffusion model based on code from Henrik Singmann’s tutorial using brms in R. I have two continuous predictors that I would like to use to predict drift rate. Since Singmann’s tutorial is for categorical predictors, I started by turning my predictors into factors with arbitrary splits for the sake of testing the code. When I did this, all my code ran fine with no issues.

However, when I tried changing to a continuous setting, I started getting an error:

Exception: mismatch in dimension declared and found in context; processing stage=parameter initialization; variable name=b; position=0; dims declared=(2); dims found=(3) (in ‘string’, line 64, column 2 to column 15)

When I suppress the intercept (i.e., with specification ~ 0 + x1 + x2 on the right hand of the drift rate formula) I do not get this same error. Since my predictors are continuous, I would rather not have to suppress the intercept.

I have all of my code attached below. The main modification I made from Signmann’s code is that I added a prior for the slope terms to estimate drift rate.

Has anyone else delt with this error before, or have any ideas on how to resolve it? Any insights are greatly appreciated!

formula <- bf(rt | dec(iComp) ~ t.z + c.z + (1|p|participant_ID), 
               bs ~ 1 + (1|p|participant_ID), 
               ndt ~ 1 + (1|p|participant_ID),
               bias ~ 1 + (1|p|participant_ID))

prior <- c(
 prior("cauchy(0, 5)", class = "Intercept"),
 prior("normal(0,1)", class = "b"), 
 set_prior("normal(1.5, 1)", class = "Intercept", dpar = "bs"),
 set_prior("normal(0.2, 0.1)", class = "Intercept", dpar = "ndt"),
 set_prior("normal(0.5, 0.2)", class = "Intercept", dpar = "bias")
)

tmp_dat <- make_standata(formula, 
                         family = wiener(link_bs = "identity", 
                              link_ndt = "identity",
                              link_bias = "identity"),
                            data = fyp.ddm, prior = prior)

initfun <- function() {
  list(
    b = rnorm(tmp_dat$K),
    Intercept = rnorm(tmp_dat$K),
   b_bs = runif(tmp_dat$K_bs, 1, 2),
   b_ndt = runif(tmp_dat$K_ndt, 0.1, 0.15),
   b_bias = rnorm(tmp_dat$K_bias, 0.5, 0.1),
    sd_1 = runif(tmp_dat$M_1, 0.5, 1),
    z_1 = matrix(rnorm(tmp_dat$M_1*tmp_dat$N_1, 0, 0.01),
                 tmp_dat$M_1, tmp_dat$N_1),
    L_1 = diag(tmp_dat$M_1)
  )
}

fit_wiener <- brm(formula, 
                  data = fyp.ddm,
                  family = wiener(link_bs = "identity", 
                                  link_ndt = "identity",
                                  link_bias = "identity"),
                  prior = prior, 
                  #sample_prior = TRUE,
                  init = initfun,
                  iter = 1100, warmup = 100, 
                  chains = 1, cores = 4, 
                  control = list(max_treedepth = 15))

Technical Information:

  • Operating System: Windows
  • brms Version: 2.22.0
  • R Version: 4.4.1

To add to @mattewwade06’s comment

As the error is from the initialization, the variable is b, and the dimension mismatch is reported

You should check that b is initialized to have length 2 and not 3.

1 Like

Thanks for the insight! I changed rnorm(tmp_dat_K) to just be rnorm(2) and then added an initialization for the intercept separately. My model is able to run now. Is this sufficient in solving the underlying issue, or should I take steps to change the entire design matrix to ensure the model is running as intended?