Search code examples
rjags

Similar function to R "rep" in jags to create array?


Is there a similar function in jags as the R function rep? I want to create an array using similar code as the following:

n ~ dmulti(pi, N) # pi is a 3 dimensional probability vector, N is fixed
  # the dimension of n is hard coded in this line:
a <- c(rep(0, n[1]), rep(1, n[2]), rep(2, n[3])) 

I read through the manual and wasn't able to find a way to achieve this. I understand that Stan would probably allow this but I couldn't use Stan because I need to do inference on discrete parameters. I really appreciate your help!

This question is also posted on the JAGS help forum.


Solution

  • I have added a rep function to the development version (future JAGS 4.0.0) as Matt and John have alluded to, this requires the second argument to be fixed so that the length of the resulting vector can be determined at compile time.