model{ for (i in 1:plots) { for (j in 1 : spp) #Loop through the species { muSp[i,j] ~ dnorm(muS[i], tauS[i]) #muSp is the mean of the logarithmn of abundance log(lambda[i,j]) <- muSp[i,j] #lambda is the poisson parameter x[i,j] ~ dpois(lambda[i,j] ) #x's are data points p[i,j]<-lambda[i,j]/tot[i] #p's are proportional posterior abundances H1[i,j]<--p[i,j]*log(p[i,j]) # A step in calculating Shannon's index S1[i,j]<-p[i,j]*p[i,j] # A step in calculating Simpson's index } ###################################################################### #Some example diversity indices Shan[i]<-sum(H1[i, ]) # Shannon's index Simp[i]<-sum(S1[i, ]) # Simpson's index InvS[i]<-1/Simp[i] # The inverse of Simpson's index Hill[i]<-(InvS[i]-1)/(exp(Shan[i])-1) PieJ[i]<-Shan[i]/log(spp) Equi[i]<-exp(Shan[i])/spp tot[i]<-sum(lambda[i, ]) # A step in calculating proportional abundances ################################################################## #Priors muS[i]~dnorm(0, 0.001) tauS[i]~ dgamma(1,0.01) Sigm[i]<-1/sqrt(tauS[i]) #####################################3 for (n in 1:(i-1)){ DifSi[n,i]<-Sigm[n]-Sigm[i] ## Calculate all the differences between pairs of sites DifSh[n,i]<-Shan[n]-Shan[i] DifIS[n,i]<-InvS[n]-InvS[i] DifHi[n,i]<-Hill[n]-Hill[i] DifPJ[n,i]<-PieJ[n]-PieJ[i] DifEq[n,i]<-Equi[n]-Equi[i] for (j in 1 : spp) { a1[n,i,j]<-abs(lambda[n,j]-lambda[i,j]) ra1[n,i,j]<-abs(lambda[n,j]/tot[n]-lambda[i,j]/tot[i]) e1[n,i,j]<-pow((lambda[n,j]-lambda[i,j]),2) } City[n,i]<-sum(a1[n,i, ]) ## Calculate all the differences between pairs of sites Eucl[n,i]<-sqrt(sum(e1[n,i, ])) Sore[n,i]<-sum(a1[n,i, ])/(tot[i]+tot[n]) RelS[n,i]<-0.5*sum(ra1[n,i,]) Jaca[n,i]<-2*sum(a1[n,i, ])/(tot[i]+tot[n]+sum(a1[n,i, ])) } } }