Dear all,
I am trying to estimate the drift rate in a task-switching paradigm.
In my experiment, which is a two-by-two design, I am exploring two stimulus types(“congruent” vs “incongruent”) and two task types (“repeat trial” vs “switch trial”). And I used the Wiener diffusion model together with brms package to fit the parameters. Generally I followed the tutorial by Dr. Singmann here.
Unfortunately, I got the error message upon the initialization phase.
I ran one chain, and it says,
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: Exception: wiener_lpdf: Nondecision time is -0.000770665, but must be positive finite! (in ‘string’, line 29, column 7 to column 55) (in ‘string’, line 29, column 7 to column 55)
Chain 1:
Chain 1: Initialization between (-2, 2) failed after 100 attempts.
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] “Error : Initialization failed.”
[1] “error occurred during calling the sampler; sampling not done”
To address this, I tried
- filter the fast RT trials, set a threshold of 0.1s and remove those trials below.
- set a small non-decision time, I tried 0.001, 0.05 and a uniform(0.001, 0.05) as random initial value for ndt.
- Operating system: x86_64-w64-mingw32
- R version: 4.3.1 (2023-06-16 ucrt)
- brms version: 2.20.4
Below, I have included the relevant portion of my code for your reference:
library(brms)
formula <- bf(
rt | dec(acc) ~ 0 + stimtype:tasktype + (0 + stimtype:tasktype | p | subj_num),
bs ~ 0 + stimtype:tasktype + (0 + stimtype:tasktype | p | subj_num),
ndt ~ 0 + stimtype:tasktype + (0 + stimtype:tasktype | p | subj_num),
bias = 0.5
)
prior <- c(
prior("cauchy(0, 5)", class = "b"),
set_prior("gamma(3, .5)", class = "b", dpar = "bs",lb=0),
set_prior("gamma(1, .5)" , class = "b", dpar = "ndt",lb=0)
)
make_stancode(formula,
family = wiener(link_bs = "identity",
link_ndt = "identity"),
data = data_pre,
prior = prior)
pre_dat <- make_standata(
formula,
family = wiener(
link_bs = "identity",
link_ndt = "identity"
),
data = data_pre,
prior = prior
)
initfun <- function() {
list(
b = rnorm(pre_dat$K),
b_bs = runif(pre_dat$K_bs, 1, 2),
b_ndt = runif(pre_dat$K_ndt, 0.001, 0.05),
# b_ndt = 0.05,
sd_1 = runif(pre_dat$M_1, 0.5, 1),
z_1 = matrix(rnorm(pre_dat$M_1*pre_dat$N_1, 0, 0.01),
pre_dat$M_1, pre_dat$N_1),
L_1 = diag(pre_dat$M_1)
)
}
fit_wiener_pre <- brm(
formula,
data = data_pre,
family = wiener(
link_bs = "identity",
link_ndt = "identity"
),
prior = prior,
init = initfun,
iter = 1000, warmup = 500,
chains = 1, cores = 4,
control = list(max_treedepth = 15,adapt_delta = 0.9)
)
Could someone help me out what went wrong with the initialization? Or how could I debug the model?
Help is much appreciated!
Best, Shuai