model { #### Priors and constraints ---- ## the recapture parameters: time periods 1:40 for( t in 1:40 ){ eps.p1[t] ~ dnorm(0, tau.p1) logit(p[t]) <- mu.p1 + eps.p1[t] q[t] <- 1 - p[t] } #t mean.p1 ~ dunif(0, 1) mu.p1 <- logit(mean.p1) sigma.p1 ~ dt(0,1,1)T(0,) tau.p1 <- pow(sigma.p1, -2) ## the recapture parameters: time periods 41:... for( t in 41:(n.occ-1) ){ eps.p2[t] ~ dnorm(0, tau.p2) logit(p[t]) <- mu.p2 + eps.p2[t] q[t] <- 1 - p[t] } #t mean.p2 ~ dunif(0, 1) mu.p2 <- logit(mean.p2) sigma.p2 ~ dt(0,1,2)T(0,) tau.p2 <- pow(sigma.p2, -2) ## the survival parameters, note adults only so no age indices # need to set the first one logit(month.phi[1]) <- mu.phi[1] + eps.phi[1] for( t in 2:(n.occ-1) ){ # and then the rest depend on the previous time interval logit(month.phi[t]) <- mu.phi[season[t]] + rho1[season[t]]*yr.phi[t-1] + eps.phi[t] } #t for( t in 1:(n.occ-1) ){ # using the residual rather than the actual value seems to converge much better eps.phi[t] ~ dnorm(0, tau.phi[season[t]]) yr.phi[t] <- logit(month.phi[t]) - mu.phi[season[t]] # now convert to the relevant time periods phi[t] <- pow(month.phi[t], ad.days[t]) } #t for( s in 1:2 ){ # the season specific means mean.phi[s] ~ dbeta(2, 1) mu.phi[s] <- logit(mean.phi[s]) ## now the autocorrelated term rho1[s] ~ dnorm(0, 0.1) sigma.phi[s] ~ dt(0, 1, 1)T(0, ) tau.phi[s] <- pow(sigma.phi[s], -2) } #s #### Define the multinomial likelihood ---- for (t in 1:(n.occ-1)){ marr.4[t, 1:n.occ] ~ dmulti(pr.4[t, ], rel.4[t]) } #t #### Define the cell probabilities of the m-arrays ---- for (t in 1:(n.occ-1)){ # The main diagonal pr.4[t, t] <- phi[t] * p[t] # Above the diagonal for( u in (t+1):(n.occ-1) ){ pr.4[t, u] <- prod(phi[t:u]) * prod(q[t:(u-1)]) * p[u] } #u ## Last column: probability of non-recapture pr.4[t, n.occ] <- 1 - sum(pr.4[t, 1:(n.occ-1)]) # Below the diagonal for ( u in 1:(t-1) ){ pr.4[t, u] <- 0 } #u } #t }