Reduce_sum for multi-level model

Hello. I am using CmdStanR.

Is there any example of a multi-level model using reduce_sum, slicing over the group-level parameter vector? I’d believe slicing over the data is rather similar for multi-level models and the minimal example. (Please confirm?) Much appreciated. Thank you very much.

1 Like

Thank you. When you have time, are you able to provide a bit more commentary on what is going on? I am not fully able to follow it. I will also try again when my mind is fresher. Thanks.

I have a varying intercept by group “g”. It makes thus sense to do the partial sums over groups formed by “g”. To do that I am sorting the data-set first by group membership. The code exemplifies everything.

Anything more specific you have questions on?

What are N_1 in line 127, J_1 in line 128, and N in the next few lines?

I believe J_1 is an array or vector, but I don’t know what it looks like.


That’s standard brms way of coding. You should look at the Stan data if in doubt.

Ah. I use RStan and now CmdStanR. I never use brms. Sorry about that. I will look into it. Thanks again for your help.?

1 Like

Sorry to bother you again. Can you explain r_1_1? I see that it is not even initialized anywhere…thanks.