################################################################## # BUG MODEL # ################################################################## # parameters used # phiW persistence wet (W) sites # phiD persistence dry (D) sites # gammaW probability of colonization in wet sites # gammaD probability of colonization in dry sites # pW species detectability in wet (W) sites (species detectability in dry (D) sites in set on 0) # psi initial occupancy probability ########################################## # SSM for multistate occupancy data # ########################################## # OBSERVATIONS (O) # With regard to the state dry or wet of the site # 1: visited wet site # 2: visited dry site # With regard to the presence of the species # 1: species not detected (i.e., corresponds to dry or wet site) # 2 species detected (i.e., corresponds only to wet site since species detectability in dry site is 0) # STATES (X) # 1 occupied site # 2 non-occupied site model { #################### # PRIORS and SSVS # #################### psi ~ dunif(0, 1) pW ~ dunif(0,1) for(j in 1:3){ beta[j] ~ dunif(0,1) } for(i in 1:nsite){ for(j in 1:(nyear-1)){ phiW[i,j] <- beta[1] phiD[i,j] <- beta[2] gammaW[i,j] <- beta[3] gammaD[i,j] <- 0 } } for (i in 1:nsite) # for each site { ##################### # DEFINE PARAMETERS # ##################### # probabilities for each initial state px0[i,1] <- 1-psi px0[i,2] <- psi # probabilities of observations given states and states given states for (j in 1:(nyear-1)) # loop over time { # define probabilities of X(t+1) given X(t) / transition probability matrices # correspond to equation 1 px[1,i,j,1] <- X[i,j] * X[i,j+1] * PxA[1,i,j,1] + X[i,j] * (1-X[i,j+1]) * PxB[1,i,j,1] + (1-X[i,j]) * (1-X[i,j+1]) * PxC[1,i,j,1] + (1-X[i,j]) * X[i,j+1] * PxD[1,i,j,1] px[1,i,j,2] <- X[i,j] * X[i,j+1] * PxA[1,i,j,2] + X[i,j] * (1-X[i,j+1]) * PxB[1,i,j,2] + (1-X[i,j]) * (1-X[i,j+1]) * PxC[1,i,j,2] + (1-X[i,j]) * X[i,j+1] * PxD[1,i,j,2] px[2,i,j,1] <- X[i,j] * X[i,j+1] * PxA[2,i,j,1] + X[i,j] * (1-X[i,j+1]) * PxB[2,i,j,1] + (1-X[i,j]) * (1-X[i,j+1]) * PxC[2,i,j,1] + (1-X[i,j]) * X[i,j+1] * PxD[2,i,j,1] px[2,i,j,2] <- X[i,j] * X[i,j+1] * PxA[2,i,j,2] + X[i,j] * (1-X[i,j+1]) * PxB[2,i,j,2] + (1-X[i,j]) * (1-X[i,j+1]) * PxC[2,i,j,2] + (1-X[i,j]) * X[i,j+1] * PxD[2,i,j,2] #### PDD (fig. 1): transition probability matrice between a site dry at(j) and dry at (j+1) PxA[1,i,j,1] <- 1-gammaD[i,j] PxA[1,i,j,2] <- gammaD[i,j] PxA[2,i,j,1] <- (1-phiD[i,j]) * (1-gammaD[i,j]) PxA[2,i,j,2] <- phiD[i,j] + (1-phiD[i,j]) * gammaD[i,j] #### PDW (fig. 1): transition probability matrice between a site dry at(j) and wet at (j+1) PxB[1,i,j,1] <- 1-gammaW[i,j] PxB[1,i,j,2] <- gammaW[i,j] PxB[2,i,j,1] <- (1-phiD[i,j]) * (1-gammaW[i,j]) PxB[2,i,j,2] <- phiD[i,j] + (1-phiD[i,j]) * gammaW[i,j] #### PWW (fig. 1): transition probability matrice between a site wet at(j) and wet at (j+1) PxC[1,i,j,1] <- 1-gammaW[i,j] PxC[1,i,j,2] <- gammaW[i,j] PxC[2,i,j,1] <- (1-phiW[i,j]) * (1-gammaW[i,j]) PxC[2,i,j,2] <- phiW[i,j] + (1-phiW[i,j]) * gammaW[i,j] #### PWD (fig. 1): transition probability matrice between a site wet at(j) and dry at (j+1) PxD[1,i,j,1] <- 1-gammaD[i,j] PxD[1,i,j,2] <- gammaD[i,j] PxD[2,i,j,1] <- (1-phiW[i,j]) * (1-gammaD[i,j]) PxD[2,i,j,2] <- phiW[i,j] + (1-phiW[i,j]) * gammaD[i,j] } for (j in 1:nyear) # loop over time { # define probabilities of O(t) given X(t) # correspond to equation 3 po[1,i,j,1] <- (1-X[i,j]) * PoA[1,i,j,1] + X[i,j] * PoB[1,i,j,1] po[1,i,j,2] <- (1-X[i,j]) * PoA[1,i,j,2] + X[i,j] * PoB[1,i,j,2] po[2,i,j,1] <- (1-X[i,j]) * PoA[2,i,j,1] + X[i,j] * PoB[2,i,j,1] po[2,i,j,2] <- (1-X[i,j]) * PoA[2,i,j,2] + X[i,j] * PoB[2,i,j,2] # POW: probabilities of O(t) given X(t) in wet site PoA[1,i,j,1] <- 1 PoA[1,i,j,2] <- 0 PoA[2,i,j,1] <- 1-pW PoA[2,i,j,2] <- pW # POD: probabilities of O(t) given X(t) in dry site PoB[1,i,j,1] <- 1 PoB[1,i,j,2] <- 0 PoB[2,i,j,1] <- 1 PoB[2,i,j,2] <- 0 } } ################################ # STATE-SPACE MODEL LIKELIHOOD # ################################ for(i in 1:nsite) { # t=1 z[i,e[i]] ~ dcat(px0[i,1:2]) for(j in (e[i]+1):fin[i]){ ## STATE EQUATIONS ## # draw X(t) given X(t-1) z[i,j] ~ dcat(px[z[i,j-1],i,j-1,1:2]) } } ## OBSERVATION EQUATIONS ## # draw O(t) given X(t) for(i in 1:nsite){ for(j in e[i]:fin[i]){ for(t in 1:nrep){ y[i,j,t] ~ dcat(po[z[i,j],i,j,1:2]) } } } }