Subsetting from an array of matrices

I have a parameter declaration for K distinct parameters for each of R regions in each of Y years like this:

matrix[K,R] alpha[Y];

It’s valuable to have this particular form because there are Y matrix products (B * alpha[y]) to calculate.

But, for each (k,r) combination I also need to access the Y elements alpha[1][k][r] … alpha[Y][k][r] as a vector. Something like

for (k in 1:K) {
  for (r in 1:R) {
    alpha[ ][k,r] ~ my_custom_lpdf
  }
}

But that doesn’t work. Is there a simple syntax for getting those Y-dimensional vectors out of this structure?

Thanks.

1 Like

After some experimenting it seems that

to_vector(alpha[,k,r]) ~ my_custom_lpdf

does what I needed.

3 Likes