Search code examples
rbayesianjags

Passing existing matrix into JAGS model using R package rjags


Very simple question, but I somehow cannot find a solution. How would you pass existing value(matrices, vectors) into JAGS model using rjags?

Here is a sample code:

model{
      A = inverse(B)
     }

And somehow I want to pass B = diag(100) into the model above, how should I do that?


Solution

  • You pass data to a model with the data arg to jags.model:

    For example:

    library(rjags)
    
    M <- 'model {
      A <- inverse(B)
    }'
    
    j <- jags.model(textConnection(M), data=list(B=diag(10)), n.chains=3)
    jags.samples(j, 'A', 1000)