I have a simplex, z, of dimension "D" under a dirichlet prior from which I compose ranks, "r". I want to convert the ranks to an ordering to permute the rows of a parameter matrix. The code snippet to implement the intent is:

z ~ ddirch(alpha) ## D x 1. "alpha" = rep(1,D) input as data

r <- rank(z)

pos[r] <- ord_dim ## ordering of dimensions conforming to ranking, "r". ord_dim = 1:D

For example, if D = 10 and rank(z) = c(4, 5, 8, 2, 10, 9, 6, 7, 1, 3)

then pos = c(9, 4, 10, 1, 2, 7, 8, 3, 6, 5)

I receive the compile step error message "Missing values in subset expression of pos". I've tried placing 'pos' in a loop, but receive the same error. This comes from a large model, which otherwise runs without this piece. I can create a toy example if that would be helpful, but I believe i've hit something fundamental to how JAGS works such that someone may readily tell me that it is not possible to create an ordering vector from another integer vector derived from parameters or, alternatively, point me to how this may be done.