
    model{

    # Priors
      for(p in 1:nPops){
        alpha[p] ~ dnorm(mu, tau.alpha)
      }

      mu ~ dnorm(0, 0.01)
      tau.alpha ~ dgamma(0.001,0.001)
      sd.alpha <- 1/pow(tau.alpha, 0.5)

      for(r in 1:nRoutes){
        route[r] ~ dnorm(0, tau.rte)
      }
      tau.rte ~ dgamma(0.001, 0.001)
      sd.rte <- 1/pow(tau.rte, 0.5)

      tau.noise  ~ dgamma(0.001, 0.001)
      sd.noise  <-  1/pow(tau.noise,0.5)

      beta1 ~ dnorm(0, 0.01)

    # Likelihood
     for(i in 1:nYears){
      eps[i] ~ dnorm(0, tau.noise)
      for(j in 1:nRoutes){
        C[i,j] ~ dpois(lambda[i,j])
        log(lambda[i,j]) <- alpha[pop[j]] + beta1*year[i] + route[j] + eps[i]
      }
     }

    # Derived parameters
      totalN <- sum(popN[1:nPops])

      for(i in 1:nPops){
        popN[i] <- exp(alpha[i] + beta1*nYears + eps[nYears])*routePerPop[i]
        relN[i] <- popN[i]/totalN
      }

  }

