Reduce_sum with hierarchical vector auto-regression

the first argument of the partial-sum function must be an array of whatever is being sliced.

To make progress in this case i suggest you to

  1. Do NOT use reduce_sum to start!
  2. Define two functions: a function for summing a region - call it region_lpdf, for example
  3. define a “partial_sum” function which you pass in the entire data and all parameters, but it does the slicing of the large data set and passes it into region_lpdf one region by another region - basically this is the body of the for loop which you show.
  4. Write in the model block a for loop where you loop 1:R and call the partial_sum function partial_sum(r, r, …);
  5. Once that works, then call in the model things without a loop, but like

target += partial_sum(1, R/2, …);
target += partial_sum(R/2+1, R, …);

and only then plug in reduce_sum to drive it all.

Please go in small steps. Only make progress once you have a firm and correctly working model. Always check that the model is still the same model (by having some data and a parameter draw for which you compute “lp__” as you can do easily in rstan).