### JAGS model ###
model {
  for(i in 1:nobs){
    r[i] ~ dbin(p[i], n[i])
    p[i] <- ilogit(mu[s[i]] + delta[s[i], t[i]])
    delta[s[i], t[i]] ~ dnorm(md[i], tau)
    md[i] <- d[t[i]] - d[b[s[i]]]
  }
  for(i in 1:ns){
    mu[i] ~ dnorm(0, 0.0001)
    AbsTrEf[i] <- ifelse(b[i] == 1, mu[i] , 0)
  }
  pi0 <- sum(AbsTrEf[])/incb
  tau <- pow(sd, -2)
  sd ~ dunif(0.00001, 2)
  d[1] <- 0
  for(k in 2:nt){
    d[k] ~ dnorm(0, 0.0001)
  }
  for(j in 1:nt){
    logit(pi[j]) <- pi0 + d[j]
    for (k in 1:nt){
      lor[j, k] <- d[j] - d[k]
      log(or[j, k]) <- lor[j, k]
      rr[j, k] <- pi[j]/pi[k]
    }
  }
}
