title: How can I set a random seed using the jags() function?
body: <p>Each time I run my JAGS model using the <code>jags()</code> function, I get very different values of fitted parameters. However, I want other people to reproduce my results.</p>
  
  <p>I tried to add <code>set.seed(123)</code>, but it didn't help. <a href="https://sourceforge.net/p/mcmc-jags/discussion/610037/thread/359a4c90/" rel="nofollow noreferrer">This link</a> describes how to achieve my goal using the <code>run.jags()</code> function. I wonder how I can do similar things using <code>jags()</code>. Thank you!</p>
  
  <p>Below is my model in R:</p>
  
  <pre><code>##------------- read data -------------##
  m &lt;- 6 
  l &lt;- 3 
  node &lt;- read.csv("answer.csv", header = F)
  n &lt;- nrow(node)
  
  # values of nodes
  ## IG
  IG &lt;- c(c(0.0, 1.0, 0.0), c(0.0, 0.0, 1.0), c(1.0, 0.0, 0.0), c(1.0, 0.0, 0.0), c(0.0, 1.0, 0.0), c(0.0, 0.0, 1.0))
  IG &lt;- matrix(IG, nrow=6, ncol=3, byrow=T)
  V_IG &lt;- array(0, dim=c(n, m, l)) 
  for (i in 1:n){
    for (j in 1:m){
      for (k in 1:l)
      {
        V_IG[i,j,k] &lt;- IG[j,k] # alternatively, V[i,j,k] &lt;- PTS[j,k]
      }
    }
  } 
  
  ## PTS
  PTS &lt;- c(c(1.0, 0.5, 0.0), c(1.0, 0.0, 0.5), c(1.0, 1.0, 0.0), c(1.0, 0.0, 1.0), c(0.0, 0.5, 1.0), c(0.0, 1.0, 0.5))
  PTS &lt;- matrix(PTS, nrow=m, ncol=3, byrow=T)
  V_PTS &lt;- array(0, dim=c(n, m, l))
  for (i in 1:n){
    for (j in 1:m){
      for (k in 1:l)
      {
        V_PTS[i,j,k] &lt;- PTS[j,k] 
      }
    }
  } 
  
  ##------------- fit model -------------##
  set.seed(123)
  data &lt;- list("n", "m", "V_IG", "V_PTS", "node") 
  myinits &lt;- list(list(tau = rep(1,n), theta = rep(0.5,n))) 
  parameters &lt;- c("tau", "theta")
  
  samples &lt;- jags(data, inits=myinits, parameters,
                  model.file ="model.txt", n.chains=1, n.iter=10000, 
                  n.burnin=1, n.thin=1, DIC=T)
  </code></pre>
  
  <p>And my model file model.txt:</p>
  
  <pre><code>model{
      # data: which node (1, 2, 3) was chosen by each child in each puzzle
      for(i in 1:n) # for each child
      {
          for (j in 1:m) # for each problem
          {
              # node chosen
              node[i,j] ~ dcat(mu[i,j,1:3])
              mu[i,j,1:3] &lt;- exp_v[i,j,1:3] / sum(exp_v[i,j,1:3])
                for (k in 1:3) {
                  exp_v[i,j,k] &lt;- exp((V_IG[i,j,k]*theta[i] + V_PTS[i,j,k]*(1-theta[i]))/tau[i])
               }
      }
  }
      # priors on tau and theta
      for (i in 1:n)
      {
          tau[i] ~ dgamma(0.001,0.001)
          theta[i] ~ dbeta(1,1)
      }
  }
  </code></pre>