model
{
  K <-1000
  for(i in 1:n)
  {	   	
    random[i] <- alpha[EUID[i]]

    for(j in 1:q)
    {		
      d1[i,j]<- step(y[i,j]-0.9999)    #d=1 if y=1  

      # 1: mean
      logit(ph1[i,j,1])  <- inprod(b[,j], xmu.1[i,]) +random[i]*rid[1]
      cloglog(ph1[i,j,2])<- inprod(b[,j], xmu.1[i,]) +random[i]*rid[1]
      probit(ph1[i,j,3]) <- inprod(b[,j], xmu.1[i,]) +random[i]*rid[1]
      mu[i,j]<- inprod(ph1[i,j, ],link[1,])

      # 2: sum  
      log(den[i,j]) <- inprod(d[,j],  xsum.1[i,])+ random[i]*rid[2]
  
      s1[i,j]<- den[i,j]*mu[i,j]
      s2[i,j]<- den[i,j]*(1-mu[i,j])  
  
      # 4: one
      logit(ph3[i,j,1])  <- (inprod(b1[,j], x1.1[i,])  + random[i]*rid[4])
      cloglog(ph3[i,j,2])<- (inprod(b1[,j], x1.1[i,])  + random[i]*rid[4])
      probit(ph3[i,j,3]) <- (inprod(b1[,j], x1.1[i,])  + random[i]*rid[4])
      p1[i,j]<- inprod(ph3[i,j, ],link[3,])*inflate1[j]
     
      ll[i,j]<- d1[i,j]*log(p1[i,j])+(1-d1[i,j])*log(1-p1[i,j])+ 
                (1-d1[i,j])*((s1[i,j]-1)*log(y[i,j])+(s2[i,j]-1)*log(1-y[i,j])+
                  loggam(s1[i,j]+s2[i,j])-loggam(s1[i,j])-loggam(s2[i,j]))
      trick[i,j] <- K-ll[i,j]  
      zero[i,j] ~ dpois(trick[i,j])    

      ypred[i,j] <- p1[i,j] + (1-p1[i,j])*mu[i,j]
      # phi[i,j] <- den[i,j]
    }
  }
                                                          
  for(j in 1:q)
  {  	
    tmp1[j] ~ dnorm(0, hyper[j,1,1])
    b[1,j] <- tmp1[j]
    for(i in 1:(p.xmu-1))
  	{
      ###   diffuse normal ###
  		b.tmp[i,j,1] ~ dnorm(0.0, hyper[j,1,2]) 
      
      ###   L1 (larsso) ### 
  		b.tmp[i,j,2] ~ dnorm(0.0,taub.L1[i,j]);  
      taub.L1[i,j] <- 1/sigmab.L1[i,j]; 	        
      sigmab.L1[i,j] ~ dexp(hyper[j,1,3]); 
  		
      ###   L2  (ridge) ###
      b.tmp[i,j,3] ~ dnorm(0.0, taub.L2[j]); 
      
  		###   ARD  ###
  		b.tmp[i,j,4] ~ dnorm(0.0,taub.ARD[i,j]);       
      taub.ARD[i,j] ~ dgamma(hyper[j,1,5], hyper[j,1,5]); 	      
      
      b[i+1,j] <- inprod(b.tmp[i,j, ],prior1[1,,j ])   	
   	}
    taub.L2[j] ~ dgamma(hyper[j,1,4],hyper[j,1,4]);  # L2 (ridge)
    
    tmp2[j]  ~ dnorm(0, hyper[j,2,1])
    d[1,j] <- tmp2[j]
  	for(i in 1:(p.xsum-1))
  	{
  		d.tmp[i,j,1] ~ dnorm(0, hyper[j,2,2]) 
      
  		d.tmp[i,j,2] ~ dnorm(0.0,taud.L1[i,j]);  
      taud.L1[i,j] <- 1/sigmad.L1[i,j]; 	        
      sigmad.L1[i,j] ~ dexp(hyper[j,2,3]); 

      d.tmp[i,j,3] ~ dnorm(0.0,taud.L2[j]);
  		
  		d.tmp[i,j,4] ~ dnorm(0.0,taud.ARD[i,j]);       
      taud.ARD[i,j] ~ dgamma(hyper[j,2,5], hyper[j,2,5]); 
      	          
      d[i+1,j] <- inprod(d.tmp[i,j, ],prior1[2, ,j])   	
   	}
    taud.L2[j] ~ dgamma(hyper[j,2,4],hyper[j,2,4]);  
    

    tmp3[j] ~ dnorm(0, hyper[j,4,1]) 
    b1[1,j] <- inflate1[j]*tmp3[j]; 
    for(i in 1:(p.x1-1))
  	{
  		b1.tmp[i,j,1] ~ dnorm(0, hyper[j,4,2]) 
      
  		b1.tmp[i,j,2] ~ dnorm(0.0,taub1.L1[i,j]);  
      taub1.L1[i,j] <- 1/sigmab1.L1[i,j]; 	        
      sigmab1.L1[i,j] ~ dexp(hyper[j,4,3]); 

      b1.tmp[i,j,3] ~ dnorm(0.0,taub1.L2[j]);
      
  		b1.tmp[i,j,4] ~ dnorm(0.0,taub1.ARD[i,j]);       
      taub1.ARD[i,j] ~ dgamma(hyper[j,4,5],hyper[j,4,5]); 	 
           
      b1[i+1,j] <- inprod(b1.tmp[i,j, ],prior1[4, ,j])*inflate1[j]   	
   	}
    taub1.L2[j] ~ dgamma(hyper[j,4,4],hyper[j,4,4]);  
    
  }


  # only the VC structure is available of there is only one random effect
  # all the levels of that single random effects comes from the same 
  # univariate normal distribution 
  
  for(i in 1:nEU)  { 
    alpha[i] ~ dnorm(0,invsigma) }
  sigma <- inverse(invsigma)
  
  sigma1 ~ dunif(0, hyper2) # uniform 

  scale2 ~ dt(0, pow(hyper2,-2), 1); 
  sigma2 <- abs(scale2) 
    
  invsigma <- pow(sigma1,-2)*prior2[1,1] + pow(sigma2,-2)*prior2[1,2]
}
