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