model{ for (i in 1:udot) { for (j in first[i]+1:k){ # asuse and apuse are required because WinBUGS does not allow indexing # to begin at 0. Therefore we take a[i,j] = 0 or 1 and make it a 1 or 2. asuse[i,j] <- a[i,j-1] + 1 apuse[i,j] <- a[i,j] + 1 # This specifies the distribution [a|S] a[i,j] ~ dbern(sv[asuse[i,j],i,j-1]) # This specifies the distribution [X|a,p] X[i,j] ~ dbern(pcap[apuse[i,j],i,j]) } for(j in first[i]:k-1){ # If you are dead at time j-1 then you remain dead sv[1,i,j] <- 0 # If alive then state dependent survival rate sv[2,i,j] <- S[zms[i,j],j] # If dead, then you are unavailable for capture pcap[1,i,j+1] <- 0 # If alive then state dependent capture probability pcap[2,i,j+1] <- p[zms[i,j+1],j+1] } for(j in first[i]+1:k){ # Model the state transitions zms[i,j] ~ dcat(psi[zms[i,j-1],1:ns]) # could also have a time specific psi } } for(j in 1:ns){ # prior distribution for psi psi[j,1:ns] ~ ddirch(alpha[1:ns]) } for(j in 1:ns){ # specifies the values for alpha in the prior for psi alpha[j] <- 1 } for(j in 1:k-1){ for(h in 1:ns){ # prior distribution for S and p - random effects distributions logit(S[h,j]) <- mu[h,1] + epsS[h,j] epsS[h,j] ~ dnorm(0,tau[1]) logit(p[h,j+1]) <- mu[h,2] + epsp[h,j+1] epsp[h,j+1] ~ dnorm(0,tau[2]) } } for(j in 1:2){ # prior distribution for tau tau[j] ~ dgamma(0.001,0.001) sd[j] <- 1/sqrt(tau[j]) for(h in 1:ns){ # prior distribution for mu. A logistic(0,1) distribution is flat on the [0,1] scale mu[h,j] ~ dlogis(0,1) } } }