Error: the model does not contain samples

I was torn whether to make a new post or reply in a comment ton my last, but since it could be an issue with anything in my code, I decided to make a new post.

I am attempting to run my 1st DDM in brms.

x1 is a continuous predictor of drift rate that ranges in the data from -2 to 3.

x2 is a categorical feature of the stimulus with three levels, treatment-coded, which I am also using to prdict drift rate.

I also intend to fix all other parameters (starting point, etc.).

I have excluded all trials with RTs under 200ms.

Here is my code so far:

formula <- brms::bf(
  # drift rate formula
  rt | dec(response) ~ x1+ x2+ (x2|p|subID) + (1|Stimulus),
  
  # 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)
)

#-----Set priors

#Now we are going to set our own priors while incorporating some of the base priors
get_prior(formula,
         data = data,
         family = wiener)

family <- wiener()
#Set priors
prior <- c(
  set_prior("normal(-2, 2)", coef = "x2level2", class="b"),
  set_prior("normal(-2, 2)", coef = "x2level3", class="b"),
  set_prior("normal(-2, 2)", coef = "x1", class = "b")
) |>  brms::validate_prior(formula,
                           family = family,
                           data = data)


#We should set a lower and upper bound on NDT

#Set a lower bound of 50ms on NDT
prior[prior$dpar=="ndt" & prior$coef==""& prior$class=="Intercept", "lb"]=0.050

#Set an upper bound of 100ms on NDT (all trials with rts under 200ms were dropped: smallest rt is # just above 200ms now
prior[prior$dpar=="ndt" & prior$coef=="" & prior$class=="Intercept", "ub"]=0.1


#Write the STAN code
make_stancode(formula,
              family = wiener(),
              data = data,
              prior = prior)

tmp_dat <- make_standata(formula, 
                         family = wiener(),
                         data = data, prior = prior)

fit_wiener <- brm(formula, 
                  data = data,
                  family = family,
                  prior = prior,
                  iter = 1000, warmup = 500, 
                  chains = 4, cores = 4)


I get the following error:

Compiling Stan program...
Start sampling
here are whatever error messages were returned
[[1]]
Stan model 'anon_model' does not contain samples.

[[2]]
Stan model 'anon_model' does not contain samples.

[[3]]
Stan model 'anon_model' does not contain samples.

[[4]]
Stan model 'anon_model' does not contain samples.

Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug

My priors look like this:

prior class coef group resp dpar nlpar lb ub source
b default
normal(-2, 2) b X2level2 user
normal(-2, 2) b X2level3 user
normal(-2, 2) b x1 user
student_t(3, 0.9, 2.5) Intercept default
logistic(0, 1) Intercept bias default
normal(-0.6, 1.3) Intercept bs default
Intercept ndt 0.05 0.1 default
lkj_corr_cholesky(1) L default
L subID default
student_t(3, 0, 2.5) sd 0 default
student_t(3, 0, 2.5) sd bias 0 default
student_t(3, 0, 2.5) sd bs 0 default
student_t(3, 0, 2.5) sd ndt 0 default
sd Stimulus default
sd Intercept Stimulus default
sd subID default
sd x2level2 subID default
sd x2level3 subID default
sd Intercept subID default
sd subID bias default
sd Intercept subID bias default
sd subID bs default
sd Intercept subID bs default
sd subID ndt default
sd Intercept subID ndt default

When setting the prior for ndt where class == sd, creating the stan code was not possible (I should have recored the exact error wording, my bad). So, I only put the priors where class == Intercept. I’m not sure if this is what is causing the error, or if it is something else concerning my priors or model. What exactly does this mean? Any insight is appreciated!

Just a quick guess: there might not necessarily be something wrong with your model, but it might be an issue with initialising the MCMC sampling. Specifically when using the DDM (or other evidence accumulation models of speeded decision-making) I’ve found that some of the random initial parameter values can be quite poor, potentially leading to non-finite log probability values.

@Solomon wrote about the issue of initial values for modelling response time data here.

As a first test, you could set the init argument to 0 to constrain the initial parameter values to zero on the unconstrained space. Quoting from the brms documentation:

If 0 , all parameters are initialized to zero on the unconstrained space. This option is sometimes useful for certain families, as it happens that default random initial values cause draws to be essentially constant. Generally, setting init = 0 is worth a try, if chains do not initialize or behave well.

Alternatively you could reduce the complexity of your model, dropping some terms from your model formulae.

There may also be other issues but it’s hard to tell based on the limited console output. Unfortunately the DDM can really be quite tricky to fit to empirical data (if you search this forum you’ll find quite a few posts of people encountering fitting issues for the Wiener first passage time distribution).

2 Likes

Thank you for the response! Unfortunately setting init = 0 produced the same error message.

Additionally, setting the chains equal to 1 produced more information:

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: Exception: wiener_lpdf: Random variable  = 1.054, but must be greater than nondecision time = 1.07788 (in 'string', line 17, column 7 to column 55) (in 'string', line 142, column 6 to column 84)
[1] "Error : Initialization failed."
[1] "error occurred during calling the sampler; sampling not done"

which I believe confirms your suspicions about the error. (I should also mentioned I tried dropping the categorical predictor in my model, which changed nothing unfortunately.)

I guess the error was due to the non-decision time is larger than the fastest RT. Maybe you can generate the stan code from brms and then adding a constrain to the ndt?

Yes, we briefly touched on issues related to the non-decision time parameter in this previous post.

In your case @pbranc even though you have a very tight prior on the intercept (i.e., population-level mean), the actual participant-wise non-decision time values could still vary widely, due to the random effect on the intercept of the non-decision time by participants.

As a starting point, you could try to remove the random intercept on the non-decision time, so just estimating a single value population-level mean:

formula <- brms::bf(
  # drift rate formula
  rt | dec(response) ~ x1+ x2+ (x2|p|subID) + (1|Stimulus),
  
  # boundary separation formula
  bs ~ 1 + (1|p|subID),
  
  # non-decision time formula
  ndt ~ 1,
  
  # starting point formula
  bias ~ 1 + (1|p|subID)
)

and see if that way, you’re at least able to get some sampling going.

If you then want to go a step further with participant-wise adjustments to the non-decision time, you’ll probably have to follow the suggestion of @mingqian.guo by using brms::make_stancode and brms::make_standata, and manually tweak the Stan code to enforce constraints on participant-wise non-decision time values.

1 Like