model {
	### Calculate x from log x
	for (i in 1:N) {
		x[i] <- pow(10, log10x[i])
	}
	
	### Calibration data
	# Each ISE emf response is based on x and a, b, c, and tau for the particular ISE
	for (i in 1:N) {
		emf[i] ~ dnorm(mu.emf[i], Tau[i])
		mu.emf[i] <- a[ISEID[i]] + b[ISEID[i]] *log(x[i] + c[ISEID[i]])/log(10)
		Tau[i] <- tau[ISEID[i]]
	}
	
	### Priors for each ISE
	for (j in 1:R) {
		a[j] ~ dnorm(0, 0.000001)
		#############################
		# ISE-specific priors       #
		b[j] ~ dnorm(mu.b, 0.01)    #
		cstar[j] ~ dunif(0.1, 0.5)  #
		sigma[j] ~ dunif(0,10)      #
		#############################

		# Logical nodes
		c[j] <- pow(cstar[j], 10)
		logsigma[j] <- log(sigma[j])
		tau[j] <- 1/(sigma[j]*sigma[j])

		# Separate ISE parameter estimation from sample calibration
		a.cut[j] <- cut(a[j])
		b.cut[j] <- cut(b[j])
		c.cut[j] <- cut(c[j])
		tau.cut[j] <- cut(tau[j])
	}

	### Experimental samples
	for (i in 1:M) {
		##################################
		# Prior on log x                 #
		log10x.exp[i] ~ dunif(-12, -2)   #
		################################## 
		x.exp[i] <- pow(10, log10x.exp[i])
	}
	
	for (i in 1:M.obs) {		
		emf.exp[i] ~ dnorm(mu.emf.exp[i], Tau.exp[i])
		mu.emf.exp[i] <- a.cut[ISEID.exp[i]] + b.cut[ISEID.exp[i]] *log(x.exp[xID.exp[i]] + c.cut[ISEID.exp[i]])/log(10)
		Tau.exp[i] <- tau.cut[ISEID.exp[i]]
		SD.exp[i] <- 1/sqrt(Tau.exp[i])			
	}
}