I started to dig deeper into hierarchical models with STAN and got to a version of my model which successfully runs. However, on the full dataset, (200 binary decisions per subject; 300 subjects), the model takes around 15 hours to run.

My solution is a combination of searching similar problems and trial-and-error, so I’m sure there is something to optimize here. Im glad for any feedback! Thank you!

Without going into the nitty gritty (or maybe going into the model at all), I’m assuming you are modeling each subject with their own parameter and (partially-)pooling them using a group-level distribution.

If you are getting started with that kind of model one didactic way (in my opinion) of building up to that is implementing an individual subject, then a hierarchical model with two subjects, and then scale up, it will probably give you good sense of model (in)efficiency and whether the individual subject performance is doing as expected in the hierarchical version.

I’d could also suggest that yo don’t constrain the upper bound of the parameters in the first runs so you get a better view of the posterior. Finally, there’s an faster approximation for the probit model that may also be helpful.

I think something is off with the indexing in the transformed parameters. The model has one ratio, gamma and alpha for each observation and it probably needs to be one per subject.

Stan picks out the alpha, gamma, and ratio for the subject i and not for observation i.

I am also not sure what the goal is of

for (n in 1:N) {
nu[subject_id[n]] ~ normal(nu_mu[condition_id[n]], nu_sigma[condition_id[n]]);
}

It looks to me that you are putting 200 (#observations per subject) priors on nu[i] where i is a subject.

These might be two things that you actually want so my apologies if the comments are off the mark. I just mention them because I think they will not lead to errors or warnings but in the most common experimental setups and with a simple hierarchical structure they are not what I would expect. The issues also create a lot of extra parameters, 200*300 instead of 300, which might cause the slow runs.

Hei! .No need to apologize! I just started learning how to use STAN, so I’m grateful for any feedback. So thank you!

About your comments:

You’re absolutely right; I want ratio, gamma and alpha to be one per subject, not one per observation. So thanks for spotting this mistake.

The idea behind nu[subject_id[n]] is that I want one prior for each subject (so in total 300 priors), but -importantly- the means differ between the conditions. So ,the fix here would be to do

for j in 1:n_subject {
nu[j] ~ normal(nu_mu[condition_id[j]], nu_sigma[condition_id[j]]);
}