model {
   for(j in 1:T) {
 
      #   beta0[j] ~ dnorm(0,0.001); # include this when using Poisson trick

      for(i in 1:N) {
 
         dN[i,j]   ~ dpois(Idt[i,j]);              # Likelihood
         Idt[i,j] <- Y[i,j]*exp(beta*Z[i])*dL0[j]; # Intensity 
   
         /*                          
         Try Poisson trick - independent log-normal hazard increments
                           - enables dL0, c, r, mu to be dropped from model
         Idt[i,j] <- Y[i,j]*exp(beta0[j]+beta*Z[i]); # Intensity    
         */
      }     
                       
     dL0[j] ~ dgamma(mu[j], c);
     mu[j] <- dL0.star[j] * c;    # prior mean hazard

     # Survivor function = exp(-Integral{l0(u)du})^exp(beta*z)    
     S.treat[j] <- pow(exp(-sum(dL0[1:j])), exp(beta * -0.5));
     S.placebo[j] <- pow(exp(-sum(dL0[1:j])), exp(beta * 0.5));	
   } 
 
   c <- 0.001; r <- 0.1; 
   for (j in 1:T) {  
     dL0.star[j] <- r * (t[j+1]-t[j])  
   } 

   beta ~ dnorm(0.0,0.000001);                 
}
