I am new to the world of stan and drift diffusion modeling. I want to create a model where I examine of drift rate is affected by either x1 (a continuous variable) or x2 (a factor with three levels). I would like to fix all other parameters (NDT, bias, and boundary separation). I have been following Henrik Singmann’s tutorial online (Diffusion/Wiener Model Analysis with brms – Part I: Introduction and Estimation | Henrik Singmann - Computational Psychology) and I want to confirm that my code is doing what I think it’s doing. I am sing the brms package in R to do this.
If possible, I also want to specify some additional random effects. Namely, I would like to incorporate whatever the equivalent of a random slope in a multilevel model would be for x2 on drift rate, and I would like to make sure the variance accounted for the the individual stimulus present on each trial is accounted for (in multilevel model terms, incorporating a random intercept not only for subID but also for stimulus).
Does this look somewhat correct? Also, does anyone know if including the p in between the x2|subID is necessary? I’m, unsure exactly what that is denoting, but I included it because it is in the tutorial. While the tutorial is for the most part easy to follow, some things are left out, like the explanation of that the p means exactly.
Currently, the right-hand sides of your formulae are identical. So if you only want to model effects on the drift rate, I think you need the following:
formula <- brms::bf(
# drift rate formula
rt | dec(response) ~ x1 + x2 + (x2|p|subID),
# boundary separation formula
bs ~ 1 + (1|p|subID),
# non-decision time formula
ndt ~ 1 + (1|p|subID),
# starting point formula
bias ~ 1 + (1|p|subID)
)
So the drift rate is allowed to vary as a function of x1 and x2, with participant-wise adjustments to the effect of x2, whereas for the boundary separation, non-decision time, and starting point we only estimate an intercept, with participant-wise adjustments to that intercept.
Note that I’ve dropped the 0 + formula setup that Henrik Singmann uses in his tutorial. I personally find that less intuitive than a more “regression-like” setup with an intercept and effects relative to that intercept, especially if you are working with continuous predictors (as is the case for your study with x1). But I suppose you could try to play around with the formulae and see how they influence your model setup, using the brms functions make_stancode and get_prior (as Singmann demonstrates in his tutorial).
I might have misunderstood this, but do you mean adding an additional random effect term like (1 | stimulus) to each of your formulae? e.g. for the drift rate it would then be: rt | dec(response) ~ x1 + x2 + (x2|p|subID) + (1|stimulus)
This is actually explained in the tutorial - quoting from Singmann:
Second, brms formulas provide a way to estimate correlations among random-effects parameters of different formulas. To achieve this, one can place an identifier in the middle of the random-effects formula that is separated by | on both sides. Correlations among random-effects will then be estimated for all random-effects formulas that share the same identifier. In our case, we want to estimate the full random-effects matrix with correlations among all model parameters, following the “latent-trait approach” . We therefore place the same identifier (p) in all formulas. Thus, correlations will be estimated among all individual-level deviations across all four Wiener parameters. To estimate correlations only among the random-effects parameters of each formula, simply omit the identifier (e.g., (0 + condition|id)). Furthermore, note that brms, similar to afex, supports suppressing the correlations among categorical random-effects parameters via || (e.g., (0 + condition||id)).
So, if you omit the p identifier in the middle, you do still estimate the correlations between random effect terms within a given parameter, but you ignore potential correlations between random effect terms across the different parameters (drift rate, boundary separation, non-decision time, starting point).
To clarify, if we stick with my revised model formula but drop the p identifiers, starting with the drift rate:
rt | dec(response) ~ x1 + x2 + (x2|subID)
here, you would estimate the correlations between random effects (participant-wise adjustments) on the intercept and the effect(s) of x2.
you would no longer estimate any correlations, because each parameter only has a single random effect, namely the participant-wise adjustment of the intercept.
Crucially, by dropping the p identifier, you would no longer estimate correlations between random effects of different parameters - for example, the correlation between the random effect term of x2 on the drift rate, and the random effect term of the intercept on the starting point bias.
Obviously dropping the p identifier simplifies the model significantly, but you might be specifically interested in these correlation terms, in which case it would be better to follow Singmann’s code.