title: Logistic regression with categorical predictors using JAGS
body: <p>I'm new to JAGS and I'm trying to predict a binary outcome (0/1) using 9 non-continuous predictors. Predictor values may be 0, 1 or 2. This is my first time doing this, and even though I can get the model to run, I am 100% sure there's definitely a number of issues here.</p>
  
  <h1>Data file sample (list)</h1>
  
  <pre><code>$y
  [1] 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
  [29] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
  
  $N
  [1] 50
  
  $oAnt
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1
  [29] 1 1 1 1 1 1 2 1 1 0 1 1 1 1 1 2 1 1 1 1 1 1
  
  $nAnt
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  [29] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  
  $cAnt
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0
  [29] 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0
  
  $oPen
  [1] 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 0
  [29] 1 0 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 0 2 1 1
  
  $nPen
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 2 1
  [29] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1
  
  $cPen
  [1] 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0
  [29] 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0
  
  $oFin
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1
  [29] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  
  $nFin
  [1] 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1
  [29] 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 3
  
  $cFin
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1
  [29] 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0
  </code></pre>
  
  <h1>Model</h1>
  
  <pre><code>model {
      for( i in 1 : N ){
          y[i] ~ dbern(mu[i])
          mu[i] &lt;- 1/(1+exp(-(b0 + b1*oAnt[i] + b2*nAnt[i] + b3*cAnt[i] + b4*oPen[i] + b5*nPen[i] + b6*cPen[i] + b7*oFin[i] + b8*nFin[i] + b9*cFin[i])))
  }
  b0 ~ dnorm(0, 1.0e-12)
  b1 ~ dnorm(0, 1.0e-12)
  b2 ~ dnorm(0, 1.0e-12)
  b3 ~ dnorm(0, 1.0e-12)
  b4 ~ dnorm(0, 1.0e-12)
  b5 ~ dnorm(0, 1.0e-12)
  b6 ~ dnorm(0, 1.0e-12)
  b7 ~ dnorm(0, 1.0e-12)
  b8 ~ dnorm(0, 1.0e-12)
  b9 ~ dnorm(0, 1.0e-12)
  }
  </code></pre>
  
  <p>I used estimates from a <code>glm()</code> model as inits (as suggest by A. Gelman)—but for the sake of simplicity, let's just assume I'll let JAGS pick the initial values for the chains.</p>
  
  <h1>Running model etc.</h1>
  
  <pre><code>jagsModel = jags.model(file = "antPenFin.txt", data = dataList, n.chains = 2, n.adapt = 500)
  
  update(jagsModel, n.iter = 500)
  
  codaSamples = coda.samples(jagsModel,
  variable.names = names(dataList)[3:11], n.iter = 5000)
  </code></pre>
  
  <h1>Problems</h1>
  
  <p>The output of my model looks totally off (which becomes clear when I try to plot it). I'm sure there's some very basic issue here. Could somebody help out?</p>
  
  <p>Thanks a lot.</p>