I think you'll need to write a short nimbleFunction to do the summation. Something like this:
```
summation <- nimbleFunction(
run = function(gamma = double(1), regions = double(1), nregions = double(0)) {
returnType(double(0))
return(sum(gamma[regions[2:nregions]]))
}
```
and in your model:
```
sum(gamma_rt[1:M, t], regions_s[s,1:P], nregions_s[s])
```
where M and P are what they need to be to indicate the extent of the relevant dimensions.
Let me know if that doesn't do it and we can iterate as needed.
-chris