model{

for(i in 1:278){
	Nfrat[i] ~ dpois(lambda[i])
	log(rho[i]) <- beta0 + beta.ses[Ses3b[i]] + beta.dur*mu.dur[i] + pow(beta.dur,2)*sigmasq.dur[i]/2 + psi[i] + nu[i]
	log(lambda[i]) <- log(Npop[i]) + log(rho[i])
	log(RR[i]) <- beta0 + psi[i] + nu[i]
	psi[i] ~ dnorm(0,tau.psi)
	for(j in 1:10){
		x[i,j] ~ dnorm(mu.dur[i],tau.dur[i]) # exposure sub-sample
	}
	mu.dur[i] ~ dnorm(0, 0.001) # mean area-level exposure
	#tau.dur[i] ~ dgamma(0.5,0.005) # precision area-level exposure
	#sigmasq.dur[i] <- 1/tau.dur[i] # area-level exposure variance
	sigmasq.dur[i] ~ dgamma(0.5,0.005)
	tau.dur[i] <- 1/sigmasq.dur[i]
}

nu[1:278] ~ car.normal(adj[],weights[],num[],tau.nu) #CAR prior for spatially structured effects


tau.psi ~ dgamma(0.5,0.005)
tau.nu ~ dgamma(0.5, 0.005) # diffuse gamma hyperprior for tau.nu
beta0 ~ dnorm(0,0.001)
beta.ses[1] <- 0
beta.ses[2] ~ dnorm(0,0.001)
beta.ses[3] ~ dnorm(0,0.001)
beta.dur ~ dnorm(0,0.001)

}
