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 survival depends on z logit(sv[2,i,j]) <- beta[1] + beta[2]*z[i,j] # If dead, then you are unavailable for capture pcap[1,i,j+1] <- 0 # If alive, then capture prob depends on z logit(pcap[2,i,j+1]) <- beta[3] + beta[4]*z[i,j+1] } for(j in first[i]+1:k){ # model for z z[i,j] ~ dnorm(muz[i,j],tauz) # describes the mean muz[i,j] <- z[i,j-1] + driftz[j-1] } } for(j in 1:k-1){ # prior distributions for the drift parameters driftz[j] ~ dnorm(0,0.0001) } for(j in 1:4){ # prior distributions for the beta parameters beta[j] ~ dnorm(0,0.0001) } # prior distribution for tauz tauz ~ dgamma(0.001,0.001) # also monitor the standard deviation. sd[1] <- 1/sqrt(tauz) }