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 12, 12, 12, 12, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 0, 4, 0, 0, 0, 3, 3, 3, 3, 0, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 9, 8, 2, 2, 9, 9, 9, 8, 2, 2, 2, 2, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 7, 5, 0, 0, 0, 5, 5, 12, 0, 12, 0, 12, 0, 5, 0, 0, 0, 4, 4, 4, 4, 11, 7, 0, 0, 11, 4, 4, 8, 4, 8, 4, 0, 0, 10, 3, 0, 10, 0, 0, 10, 10, 3, 10, 0, 8, 2, 2, 2, 7, 2, 2, 2, 2, 2, 2, 8, 8, 7, 2, 2, 2, 9, 2), nrow = 142, byrow = FALSE) # First capture occasion get.first <- function(x) min(which(x!=0)) f <- apply(CH, 1, get.first) # Recode CH observations # 16 = not seen, not detected rCH <- CH rCH[rCH==0] <- 16 # read matrix of known latent states zCH <- matrix(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2, 2, 7, 7, 7, 7, 2, 7, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, 7, 16, 16, 16, 16, 7, 16, 2, NA, NA, 2, 7, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4, 16, 16, 16, 16, 16, 16, 16, 3, NA, NA, 3, 16, 2, 8, 8, 2, 2, 2, 2, 2, 8, 2, 7, 8, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, 11, 16, NA, 16, 16, 3, 3, 3, 3, 3, 16, 3, 16, 16, 2, 2, 2, 2, 2, 2, 2, 2, 8, 2, 9, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, NA, 16, 16, 11, 11, 11, NA, NA, 16, 11, 16, 16, 3, 3, 3, 3, 3, 3, 3, 3, 16, 8, NA, 9, 7, 8, 7, 2, 2, 2, 2, NA, 2, 2, 2, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, NA, 16, 16, NA, NA, NA, NA, NA, 16, 15, 16, 16, 4, 4, 4, 4, 4, 4, 4, 11, 16, 16, NA, NA, 16, 16, 16, 3, 3, NA, NA, NA, 3, 3, 3, 3, 2, 2, 2, 2, 8, 8, 8, 2, 8, 7, 9, 2, NA, NA, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, NA, 16, 16, NA, NA, NA, NA, NA, 16, 16, 16, 16, 5, 5, 5, 5, 5, NA, NA, NA, 16, 16, NA, NA, 16, 16, 16, 4, 7, NA, NA, NA, 4, 4, 4, 4, 7, 7, 8, 7, 16, 16, 16, 7, 16, 16, NA, NA, NA, NA, 16, 3, NA, 3, 3, 3, 3, 3, 3, 3, 2, 8, 7, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, NA, 2, 2, 2, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, NA, 16, 16, NA, NA, NA, NA, NA, 16, 16, 16, 16, 13, 13, 13, 13, 13, 13, 13, NA, 16, 16, NA, NA, 16, 16, 16, 7, 16, NA, NA, NA, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 16, 16, 16, 7, 3, 3, 3, 3, NA, 3, 3, 3, 3, 3, 3, 3, NA, 3, NA, NA, NA, 2, 2, 2, 2, 2, 2, 8, NA, 2, 2, 2, 2, 2, 2, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, NA, 16, 16, NA, NA, NA, NA, NA, 16, 16, 16, 16, 13, 13, NA, NA, NA, NA, NA, NA, 16, 16, NA, NA, 16, 16, 16, 16, 16, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 16, 4, 4, 4, 4, NA, 4, 4, 4, 4, 4, 4, 4, NA, 4, NA, NA, NA, 3, 3, 3, 3, NA, 3, 16, NA, 3, 3, 3, 3, 3, 3, 3, 9, 8, 2, 2, 9, 9, 9, 8, 2, 2, 2, 2, 7, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, NA, 16, 16, NA, NA, NA, NA, NA, 16, 16, 16, 16, NA, 13, NA, NA, NA, NA, NA, NA, 16, 16, 14, NA, 16, 16, 16, 16, 16, NA, NA, NA, NA, NA, NA, NA, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, NA, NA, NA, NA, 16, 13, NA, NA, NA, NA, NA, NA, NA, 13, 16, 16, 16, 16, 16, 7, 5, NA, NA, NA, 5, 5, 12, NA, 12, NA, 12, NA, 5, NA, NA, NA, 4, 4, 4, 4, 11, 7, 16, NA, 11, 4, 4, 8, 4, 8, 4, NA, 16, 10, 3, NA, 10, NA, 16, 10, 10, 3, 10, 16, 8, 2, 2, 2, 7, 2, 2, 2, 2, 2, 2, 8, 8, 7, 2, 2, 2, 9, 2), nrow = 142, byrow = FALSE) # Number of years nyears <- 12 # Population count data popcount <- c(4,5,2,5,8,7,13,10,14,12,13,17) # Reproductive success data nestlings <- c(8,8,5,12,14,11,26,20,18,17,24,19) # number of offspring R <- c(4,5,2,5,8,7,13,10,14,12,13,17) # number of surveyed broods # Unmarked birds found dead by poison or other causes rec.dead.poison <- c(0,0,1,0,0,0,0,0,0,1,1,1) rec.dead.other <- c(1,1,0,0,0,0,1,1,0,2,3,2) # Load R2WinBUGS package library("R2WinBUGS") # WinBUGS MODEL: sink("ipm_redkite.txt") cat(" model { ############################################################################### # # Integrated population model for the red kite population of Mallorca (Spain) # - Age structured, female-based model with 3 age classes: # - Pre-breeding census # - Age at first breeding: 2 years old # ############################################################################### ############################################################ # 1. Priors for the parameters ############################################################ # Probabilities for telemetry data # Priors and constraints for (t in 1:(n.occasions-1)){ s[t] <- mean.s betajuv[t] <- mean.betajuv beta1y[t] <- mean.beta1y beta2my[t] <- mean.beta2my alpha1[t] <- mean.alpha1 alpha2[t] <- mean.alpha2 alpha3[t] <- mean.alpha3 p[t] <- mean.p c[t] <- mean.c d1[t] <- mean.d1 d2[t] <- mean.d2 } mean.s ~ dunif(0, 1) mean.betajuv ~ dunif(0, 1) mean.beta1y ~ dunif(0, 1) mean.beta2my ~ dunif(0, 1) mean.alpha1 ~ dunif(0, 1) mean.alpha2 ~ dunif(0, 1) mean.alpha3 ~ dunif(0, 0.1) mean.p ~ dunif(0, 1) mean.c ~ dunif(0, 1) mean.d1 ~ dunif(0, 0.1) mean.d2 ~ dunif(0, 1) # Initial population sizes N1[1] ~ dnorm(10, 0.001)I(1,) # 1-year old individuals N2[1] ~ dnorm(10, 0.001)I(1,) # 2-year old individuals Nad[1] ~ dnorm(10, 0.001)I(1,) # Adults > 2 years # Proportion of adult breeders SBad ~ dunif(0.5, 1) # Mean fecundity (on log scale) l.mfec ~ dnorm(0, 0.0001)I(-10,10) # Fecundity temporal variability sig.fec ~ dunif(0, 10) tau.fec <- pow(sig.fec, -2) for (t in 1:(nyears-1)){ epsilon.fec[t] ~ dnorm(0, tau.fec)I(-15,15) } # Initial population size of unmarked birds dead by poison Ndp[1] ~ dnorm(1, 0.01)I(0,) # Initial population size of unmarked birds dead by other causes Ndo[1] ~ dnorm(1, 0.01)I(0,) ############################################################ # 2. Constrain fecundity ############################################################ for (t in 1:(nyears-1)){ log(b[t]) <- l.mfec + epsilon.fec[t] } ############################################################ # 3. Derived and fixed parameters ############################################################ # Mean fecundity (on real scale) mfec <- exp(l.mfec) # Population growth rate for (t in 1:(nyears-1)){ lambda[t] <- Ntot[t+1] / Ntot[t] logla[t] <- log(lambda[t]) } mlam <- exp((1/(nyears-1))*sum(logla[1:(nyears-1)])) # Geometric mean # Survival probability in absence of illegal poisoning Snp.juv <- 1 - (1-mean.s) * (1-mean.betajuv) Snp.1y <- 1 - (1-mean.s) * (1-mean.beta1y) Snp.ad <- 1 - (1-mean.s) * (1-mean.beta2my) # Mean probability of death due to poisoning mean.betahat <- (mean.betajuv + mean.beta1y + mean.beta2my) / 3 # Probability of dying because of poisoning mdp <- (1-mean.s) * mean.betahat # Probability of dying for causes other than poison mdo <- (1-mean.s) * (1-mean.betahat) # Complementary probability for (mdp+mdo) msurv <- 1-mdp-mdo ################################################################################### # 4. The likelihoods of the single data sets ################################################################################### ########################################################################## # 4.1. Likelihood for population population count data (state-space model) ########################################################################## ############################# # 4.1.1 System process ############################# for (t in 2:nyears){ mean1[t] <- 0.5 * b[t-1] * mean.s * (N2[t-1] * 0.10 + Nad[t-1] * SBad) N1[t] ~ dpois(mean1[t]) # total number of 1y N2[t] ~ dbin(mean.s, N1[t-1]) # total number of 2y tot2ad[t-1] <- N2[t-1] + Nad[t-1] Nad[t] ~ dbin(mean.s, tot2ad[t-1]) # total number of adults Npop[t-1] <- N1[t-1] + N2[t-1] + Nad[t-1] # unmarked birds found dead # Multinomial distribution with unknown order N was coded as a sequence of conditional univariate binomial distributions # For further details see WinBUGS manual (Spiegelhalter 2007) Ndp[t] ~ dbin(mdp, Npop[t-1]) # number of birds dead by poison Ndo[t] ~ dbin(mdo, Npop_minus_dp[t-1]) # number of birds dead by other causes (CONDITIONAL on Ndp) Npop_minus_dp[t-1] <- Npop[t-1] - Ndp[t] # *(see comment below) Nsurv[t] ~ dbin(msurv, Npop_surv[t-1]) # number of survived birds Npop_surv[t-1] <- Npop[t-1] - Ndp[t] - Ndo[t] # *this makes the three conditional binomial as a multinomial distribution } # ############################# # 4.1.2 Observation process ############################# for (t in 1:nyears){ Ntot[t] <- (N2[t] * 0.10 + Nad[t] * SBad) census[t] ~ dpois(Ntot[t]) deaths_p[t] ~ dbin(mean.d1, Ndp[t]) deaths_o[t] ~ dbin(mean.d2, Ndo[t]) } ############################################################################## # 4.2 Likelihood for capture-recapture data: multistate model (6 age classes) ############################################################################## #################################################### # Parameters: # # alpha1: probability of radio signal retention during the first 3 years of life # alpha2: probability of radio signal retention during the fourth year of life # alpha3: probability of radio signal retention from the fifth year of life onwards # betajuv: probability of death due to poisoning given an animal has died as juvenile (between the birth and the first spring) # beta1y: probability of death due to poisoning given an animal has died as 1-year old (between the first and the secod spring) # beta2my: probability of death due to poisoning given an animal has died as 2 or more year old # c: probability of encounter of an animal alive without the radio signal # p: probability of encounter of an animal with a functioning radio # d1: probability of encounter of an animal dead by poisoning and without the radio signal # d2: probability of encounter of an animal dead by other causes and without the radio signal # s: survival probability # ################################################### # States (S) # 1 alive as juvenile # 2 alive as 1-year old with tag # 3 alive as 2-year old with tag # 4 alive as 3-year old with tag # 5 alive as 4-year old with tag # 6 alive as 5-year old or more with tag # 7 dead by poison with tag # 8 dead by other causes with tag # 9 alive as 1-year old without tag # 10 alive as 2-year old without tag # 11 alive as 3-year old without tag # 12 alive as 4-year old without tag # 13 alive as 5-year old or more without tag # 14 dead by poison without tag # 15 dead by other causes without tag # 16 unobserved dead # # Observations (O) # 1 detected alive as juvenile # 2 detected alive as 1-year old with tag # 3 detected alive as 2-year old with tag # 4 detected alive as 3-year old with tag # 5 detected alive as 4-year old with tag # 6 detected alive as 5-year old or more with tag # 7 detected dead by poison with tag # 8 detected dead by other causes with tag # 9 detected alive as 1-year old without tag # 10 detected alive as 2-year old without tag # 11 detected alive as 3-year old without tag # 12 detected alive as 4-year old without tag # 13 detected alive as 5-year old or more without tag # 14 detected dead by poison without tag # 15 detected dead by other causes without tag # 16 not detected ################################################### # Define parameters for (i in 1:nind){ # Define probabilities of state S(t+1) given S(t); see Figure S1 for (t in f[i]:(n.occasions-1)){ # loop over time # First index = states at time t-1, last index = states at time t ps[1,i,t,1] <- 0 ps[1,i,t,2] <- s[t] * alpha1[t] ps[1,i,t,3] <- 0 ps[1,i,t,4] <- 0 ps[1,i,t,5] <- 0 ps[1,i,t,6] <- 0 ps[1,i,t,7] <- (1-s[t]) * betajuv[t] * alpha1[t] ps[1,i,t,8] <- (1-s[t]) * (1-betajuv[t]) * alpha1[t] ps[1,i,t,9] <- s[t] * (1-alpha1[t]) ps[1,i,t,10] <- 0 ps[1,i,t,11] <- 0 ps[1,i,t,12] <- 0 ps[1,i,t,13] <- 0 ps[1,i,t,14] <- (1-s[t]) * betajuv[t] * (1-alpha1[t]) ps[1,i,t,15] <- (1-s[t]) * (1-betajuv[t]) * (1-alpha1[t]) ps[1,i,t,16] <- 0 ps[2,i,t,1] <- 0 ps[2,i,t,2] <- 0 ps[2,i,t,3] <- s[t] * alpha1[t] ps[2,i,t,4] <- 0 ps[2,i,t,5] <- 0 ps[2,i,t,6] <- 0 ps[2,i,t,7] <- (1-s[t]) * beta1y[t] * alpha1[t] ps[2,i,t,8] <- (1-s[t]) * (1-beta1y[t]) * alpha1[t] ps[2,i,t,9] <- 0 ps[2,i,t,10] <- s[t] * (1-alpha1[t]) ps[2,i,t,11] <- 0 ps[2,i,t,12] <- 0 ps[2,i,t,13] <- 0 ps[2,i,t,14] <- (1-s[t]) * beta1y[t] * (1-alpha1[t]) ps[2,i,t,15] <- (1-s[t]) * (1-beta1y[t]) * (1-alpha1[t]) ps[2,i,t,16] <- 0 ps[3,i,t,1] <- 0 ps[3,i,t,2] <- 0 ps[3,i,t,3] <- 0 ps[3,i,t,4] <- s[t] * alpha1[t] ps[3,i,t,5] <- 0 ps[3,i,t,6] <- 0 ps[3,i,t,7] <- (1-s[t]) * beta2my[t] * alpha1[t] ps[3,i,t,8] <- (1-s[t]) * (1-beta2my[t]) * alpha1[t] ps[3,i,t,9] <- 0 ps[3,i,t,10] <- 0 ps[3,i,t,11] <- s[t] * (1-alpha1[t]) ps[3,i,t,12] <- 0 ps[3,i,t,13] <- 0 ps[3,i,t,14] <- (1-s[t]) * beta2my[t] * (1-alpha1[t]) ps[3,i,t,15] <- (1-s[t]) * (1-beta2my[t]) * (1-alpha1[t]) ps[3,i,t,16] <- 0 ps[4,i,t,1] <- 0 ps[4,i,t,2] <- 0 ps[4,i,t,3] <- 0 ps[4,i,t,4] <- 0 ps[4,i,t,5] <- s[t] * alpha2[t] ps[4,i,t,6] <- 0 ps[4,i,t,7] <- (1-s[t]) * beta2my[t] * alpha2[t] ps[4,i,t,8] <- (1-s[t]) * (1-beta2my[t]) * alpha2[t] ps[4,i,t,9] <- 0 ps[4,i,t,10] <- 0 ps[4,i,t,11] <- 0 ps[4,i,t,12] <- s[t] * (1-alpha2[t]) ps[4,i,t,13] <- 0 ps[4,i,t,14] <- (1-s[t]) * beta2my[t] * (1-alpha2[t]) ps[4,i,t,15] <- (1-s[t]) * (1-beta2my[t]) * (1-alpha2[t]) ps[4,i,t,16] <- 0 ps[5,i,t,1] <- 0 ps[5,i,t,2] <- 0 ps[5,i,t,3] <- 0 ps[5,i,t,4] <- 0 ps[5,i,t,5] <- 0 ps[5,i,t,6] <- s[t] * alpha3[t] ps[5,i,t,7] <- (1-s[t]) * beta2my[t] * alpha3[t] ps[5,i,t,8] <- (1-s[t]) * (1-beta2my[t]) * alpha3[t] ps[5,i,t,9] <- 0 ps[5,i,t,10] <- 0 ps[5,i,t,11] <- 0 ps[5,i,t,12] <- 0 ps[5,i,t,13] <- s[t] * (1-alpha3[t]) ps[5,i,t,14] <- (1-s[t]) * beta2my[t] * (1-alpha3[t]) ps[5,i,t,15] <- (1-s[t]) * (1-beta2my[t]) * (1-alpha3[t]) ps[5,i,t,16] <- 0 ps[6,i,t,1] <- 0 ps[6,i,t,2] <- 0 ps[6,i,t,3] <- 0 ps[6,i,t,4] <- 0 ps[6,i,t,5] <- 0 ps[6,i,t,6] <- s[t] * alpha3[t] ps[6,i,t,7] <- (1-s[t]) * beta2my[t] * alpha3[t] ps[6,i,t,8] <- (1-s[t]) * (1-beta2my[t]) * alpha3[t] ps[6,i,t,9] <- 0 ps[6,i,t,10] <- 0 ps[6,i,t,11] <- 0 ps[6,i,t,12] <- 0 ps[6,i,t,13] <- s[t] * (1-alpha3[t]) ps[6,i,t,14] <- (1-s[t]) * beta2my[t] * (1-alpha3[t]) ps[6,i,t,15] <- (1-s[t]) * (1-beta2my[t]) * (1-alpha3[t]) ps[6,i,t,16] <- 0 ps[7,i,t,1] <- 0 ps[7,i,t,2] <- 0 ps[7,i,t,3] <- 0 ps[7,i,t,4] <- 0 ps[7,i,t,5] <- 0 ps[7,i,t,6] <- 0 ps[7,i,t,7] <- 0 ps[7,i,t,8] <- 0 ps[7,i,t,9] <- 0 ps[7,i,t,10] <- 0 ps[7,i,t,11] <- 0 ps[7,i,t,12] <- 0 ps[7,i,t,13] <- 0 ps[7,i,t,14] <- 0 ps[7,i,t,15] <- 0 ps[7,i,t,16] <- 1 ps[8,i,t,1] <- 0 ps[8,i,t,2] <- 0 ps[8,i,t,3] <- 0 ps[8,i,t,4] <- 0 ps[8,i,t,5] <- 0 ps[8,i,t,6] <- 0 ps[8,i,t,7] <- 0 ps[8,i,t,8] <- 0 ps[8,i,t,9] <- 0 ps[8,i,t,10] <- 0 ps[8,i,t,11] <- 0 ps[8,i,t,12] <- 0 ps[8,i,t,13] <- 0 ps[8,i,t,14] <- 0 ps[8,i,t,15] <- 0 ps[8,i,t,16] <- 1 ps[9,i,t,1] <- 0 ps[9,i,t,2] <- 0 ps[9,i,t,3] <- 0 ps[9,i,t,4] <- 0 ps[9,i,t,5] <- 0 ps[9,i,t,6] <- 0 ps[9,i,t,7] <- 0 ps[9,i,t,8] <- 0 ps[9,i,t,9] <- 0 ps[9,i,t,10] <- s[t] ps[9,i,t,11] <- 0 ps[9,i,t,12] <- 0 ps[9,i,t,13] <- 0 ps[9,i,t,14] <- (1-s[t]) * beta1y[t] ps[9,i,t,15] <- (1-s[t]) * (1-beta1y[t]) ps[9,i,t,16] <- 0 ps[10,i,t,1] <- 0 ps[10,i,t,2] <- 0 ps[10,i,t,3] <- 0 ps[10,i,t,4] <- 0 ps[10,i,t,5] <- 0 ps[10,i,t,6] <- 0 ps[10,i,t,7] <- 0 ps[10,i,t,8] <- 0 ps[10,i,t,9] <- 0 ps[10,i,t,10] <- 0 ps[10,i,t,11] <- s[t] ps[10,i,t,12] <- 0 ps[10,i,t,13] <- 0 ps[10,i,t,14] <- (1-s[t]) * beta2my[t] ps[10,i,t,15] <- (1-s[t]) * (1-beta2my[t]) ps[10,i,t,16] <- 0 ps[11,i,t,1] <- 0 ps[11,i,t,2] <- 0 ps[11,i,t,3] <- 0 ps[11,i,t,4] <- 0 ps[11,i,t,5] <- 0 ps[11,i,t,6] <- 0 ps[11,i,t,7] <- 0 ps[11,i,t,8] <- 0 ps[11,i,t,9] <- 0 ps[11,i,t,10] <- 0 ps[11,i,t,11] <- 0 ps[11,i,t,12] <- s[t] ps[11,i,t,13] <- 0 ps[11,i,t,14] <- (1-s[t]) * beta2my[t] ps[11,i,t,15] <- (1-s[t]) * (1-beta2my[t]) ps[11,i,t,16] <- 0 ps[12,i,t,1] <- 0 ps[12,i,t,2] <- 0 ps[12,i,t,3] <- 0 ps[12,i,t,4] <- 0 ps[12,i,t,5] <- 0 ps[12,i,t,6] <- 0 ps[12,i,t,7] <- 0 ps[12,i,t,8] <- 0 ps[12,i,t,9] <- 0 ps[12,i,t,10] <- 0 ps[12,i,t,11] <- 0 ps[12,i,t,12] <- 0 ps[12,i,t,13] <- s[t] ps[12,i,t,14] <- (1-s[t]) * beta2my[t] ps[12,i,t,15] <- (1-s[t]) * (1-beta2my[t]) ps[12,i,t,16] <- 0 ps[13,i,t,1] <- 0 ps[13,i,t,2] <- 0 ps[13,i,t,3] <- 0 ps[13,i,t,4] <- 0 ps[13,i,t,5] <- 0 ps[13,i,t,6] <- 0 ps[13,i,t,7] <- 0 ps[13,i,t,8] <- 0 ps[13,i,t,9] <- 0 ps[13,i,t,10] <- 0 ps[13,i,t,11] <- 0 ps[13,i,t,12] <- 0 ps[13,i,t,13] <- s[t] ps[13,i,t,14] <- (1-s[t]) * beta2my[t] ps[13,i,t,15] <- (1-s[t]) * (1-beta2my[t]) ps[13,i,t,16] <- 0 ps[14,i,t,1] <- 0 ps[14,i,t,2] <- 0 ps[14,i,t,3] <- 0 ps[14,i,t,4] <- 0 ps[14,i,t,5] <- 0 ps[14,i,t,6] <- 0 ps[14,i,t,7] <- 0 ps[14,i,t,8] <- 0 ps[14,i,t,9] <- 0 ps[14,i,t,10] <- 0 ps[14,i,t,11] <- 0 ps[14,i,t,12] <- 0 ps[14,i,t,13] <- 0 ps[14,i,t,14] <- 0 ps[14,i,t,15] <- 0 ps[14,i,t,16] <- 1 ps[15,i,t,1] <- 0 ps[15,i,t,2] <- 0 ps[15,i,t,3] <- 0 ps[15,i,t,4] <- 0 ps[15,i,t,5] <- 0 ps[15,i,t,6] <- 0 ps[15,i,t,7] <- 0 ps[15,i,t,8] <- 0 ps[15,i,t,9] <- 0 ps[15,i,t,10] <- 0 ps[15,i,t,11] <- 0 ps[15,i,t,12] <- 0 ps[15,i,t,13] <- 0 ps[15,i,t,14] <- 0 ps[15,i,t,15] <- 0 ps[15,i,t,16] <- 1 ps[16,i,t,1] <- 0 ps[16,i,t,2] <- 0 ps[16,i,t,3] <- 0 ps[16,i,t,4] <- 0 ps[16,i,t,5] <- 0 ps[16,i,t,6] <- 0 ps[16,i,t,7] <- 0 ps[16,i,t,8] <- 0 ps[16,i,t,9] <- 0 ps[16,i,t,10] <- 0 ps[16,i,t,11] <- 0 ps[16,i,t,12] <- 0 ps[16,i,t,13] <- 0 ps[16,i,t,14] <- 0 ps[16,i,t,15] <- 0 ps[16,i,t,16] <- 1 # Define probabilities of O(t) given S(t); see Figure S2 # First index = states at time t, last index = observations at time t po[1,i,t,1] <- 0 po[1,i,t,2] <- 0 po[1,i,t,3] <- 0 po[1,i,t,4] <- 0 po[1,i,t,5] <- 0 po[1,i,t,6] <- 0 po[1,i,t,7] <- 0 po[1,i,t,8] <- 0 po[1,i,t,9] <- 0 po[1,i,t,10] <- 0 po[1,i,t,11] <- 0 po[1,i,t,12] <- 0 po[1,i,t,13] <- 0 po[1,i,t,14] <- 0 po[1,i,t,15] <- 0 po[1,i,t,16] <- 1 po[2,i,t,1] <- 0 po[2,i,t,2] <- p[t] po[2,i,t,3] <- 0 po[2,i,t,4] <- 0 po[2,i,t,5] <- 0 po[2,i,t,6] <- 0 po[2,i,t,7] <- 0 po[2,i,t,8] <- 0 po[2,i,t,9] <- 0 po[2,i,t,10] <- 0 po[2,i,t,11] <- 0 po[2,i,t,12] <- 0 po[2,i,t,13] <- 0 po[2,i,t,14] <- 0 po[2,i,t,15] <- 0 po[2,i,t,16] <- 1-p[t] po[3,i,t,1] <- 0 po[3,i,t,2] <- 0 po[3,i,t,3] <- p[t] po[3,i,t,4] <- 0 po[3,i,t,5] <- 0 po[3,i,t,6] <- 0 po[3,i,t,7] <- 0 po[3,i,t,8] <- 0 po[3,i,t,9] <- 0 po[3,i,t,10] <- 0 po[3,i,t,11] <- 0 po[3,i,t,12] <- 0 po[3,i,t,13] <- 0 po[3,i,t,14] <- 0 po[3,i,t,15] <- 0 po[3,i,t,16] <- 1-p[t] po[4,i,t,1] <- 0 po[4,i,t,2] <- 0 po[4,i,t,3] <- 0 po[4,i,t,4] <- p[t] po[4,i,t,5] <- 0 po[4,i,t,6] <- 0 po[4,i,t,7] <- 0 po[4,i,t,8] <- 0 po[4,i,t,9] <- 0 po[4,i,t,10] <- 0 po[4,i,t,11] <- 0 po[4,i,t,12] <- 0 po[4,i,t,13] <- 0 po[4,i,t,14] <- 0 po[4,i,t,15] <- 0 po[4,i,t,16] <- 1-p[t] po[5,i,t,1] <- 0 po[5,i,t,2] <- 0 po[5,i,t,3] <- 0 po[5,i,t,4] <- 0 po[5,i,t,5] <- p[t] po[5,i,t,6] <- 0 po[5,i,t,7] <- 0 po[5,i,t,8] <- 0 po[5,i,t,9] <- 0 po[5,i,t,10] <- 0 po[5,i,t,11] <- 0 po[5,i,t,12] <- 0 po[5,i,t,13] <- 0 po[5,i,t,14] <- 0 po[5,i,t,15] <- 0 po[5,i,t,16] <- 1-p[t] po[6,i,t,1] <- 0 po[6,i,t,2] <- 0 po[6,i,t,3] <- 0 po[6,i,t,4] <- 0 po[6,i,t,5] <- 0 po[6,i,t,6] <- p[t] po[6,i,t,7] <- 0 po[6,i,t,8] <- 0 po[6,i,t,9] <- 0 po[6,i,t,10] <- 0 po[6,i,t,11] <- 0 po[6,i,t,12] <- 0 po[6,i,t,13] <- 0 po[6,i,t,14] <- 0 po[6,i,t,15] <- 0 po[6,i,t,16] <- 1-p[t] po[7,i,t,1] <- 0 po[7,i,t,2] <- 0 po[7,i,t,3] <- 0 po[7,i,t,4] <- 0 po[7,i,t,5] <- 0 po[7,i,t,6] <- 0 po[7,i,t,7] <- p[t] po[7,i,t,8] <- 0 po[7,i,t,9] <- 0 po[7,i,t,10] <- 0 po[7,i,t,11] <- 0 po[7,i,t,12] <- 0 po[7,i,t,13] <- 0 po[7,i,t,14] <- 0 po[7,i,t,15] <- 0 po[7,i,t,16] <- 1-p[t] po[8,i,t,1] <- 0 po[8,i,t,2] <- 0 po[8,i,t,3] <- 0 po[8,i,t,4] <- 0 po[8,i,t,5] <- 0 po[8,i,t,6] <- 0 po[8,i,t,7] <- 0 po[8,i,t,8] <- p[t] po[8,i,t,9] <- 0 po[8,i,t,10] <- 0 po[8,i,t,11] <- 0 po[8,i,t,12] <- 0 po[8,i,t,13] <- 0 po[8,i,t,14] <- 0 po[8,i,t,15] <- 0 po[8,i,t,16] <- 1-p[t] po[9,i,t,1] <- 0 po[9,i,t,2] <- 0 po[9,i,t,3] <- 0 po[9,i,t,4] <- 0 po[9,i,t,5] <- 0 po[9,i,t,6] <- 0 po[9,i,t,7] <- 0 po[9,i,t,8] <- 0 po[9,i,t,9] <- c[t] po[9,i,t,10] <- 0 po[9,i,t,11] <- 0 po[9,i,t,12] <- 0 po[9,i,t,13] <- 0 po[9,i,t,14] <- 0 po[9,i,t,15] <- 0 po[9,i,t,16] <- 1-c[t] po[10,i,t,1] <- 0 po[10,i,t,2] <- 0 po[10,i,t,3] <- 0 po[10,i,t,4] <- 0 po[10,i,t,5] <- 0 po[10,i,t,6] <- 0 po[10,i,t,7] <- 0 po[10,i,t,8] <- 0 po[10,i,t,9] <- 0 po[10,i,t,10] <- c[t] po[10,i,t,11] <- 0 po[10,i,t,12] <- 0 po[10,i,t,13] <- 0 po[10,i,t,14] <- 0 po[10,i,t,15] <- 0 po[10,i,t,16] <- 1-c[t] po[11,i,t,1] <- 0 po[11,i,t,2] <- 0 po[11,i,t,3] <- 0 po[11,i,t,4] <- 0 po[11,i,t,5] <- 0 po[11,i,t,6] <- 0 po[11,i,t,7] <- 0 po[11,i,t,8] <- 0 po[11,i,t,9] <- 0 po[11,i,t,10] <- 0 po[11,i,t,11] <- c[t] po[11,i,t,12] <- 0 po[11,i,t,13] <- 0 po[11,i,t,14] <- 0 po[11,i,t,15] <- 0 po[11,i,t,16] <- 1-c[t] po[12,i,t,1] <- 0 po[12,i,t,2] <- 0 po[12,i,t,3] <- 0 po[12,i,t,4] <- 0 po[12,i,t,5] <- 0 po[12,i,t,6] <- 0 po[12,i,t,7] <- 0 po[12,i,t,8] <- 0 po[12,i,t,9] <- 0 po[12,i,t,10] <- 0 po[12,i,t,11] <- 0 po[12,i,t,12] <- c[t] po[12,i,t,13] <- 0 po[12,i,t,14] <- 0 po[12,i,t,15] <- 0 po[12,i,t,16] <- 1-c[t] po[13,i,t,1] <- 0 po[13,i,t,2] <- 0 po[13,i,t,3] <- 0 po[13,i,t,4] <- 0 po[13,i,t,5] <- 0 po[13,i,t,6] <- 0 po[13,i,t,7] <- 0 po[13,i,t,8] <- 0 po[13,i,t,9] <- 0 po[13,i,t,10] <- 0 po[13,i,t,11] <- 0 po[13,i,t,12] <- 0 po[13,i,t,13] <- c[t] po[13,i,t,14] <- 0 po[13,i,t,15] <- 0 po[13,i,t,16] <- 1-c[t] po[14,i,t,1] <- 0 po[14,i,t,2] <- 0 po[14,i,t,3] <- 0 po[14,i,t,4] <- 0 po[14,i,t,5] <- 0 po[14,i,t,6] <- 0 po[14,i,t,7] <- 0 po[14,i,t,8] <- 0 po[14,i,t,9] <- 0 po[14,i,t,10] <- 0 po[14,i,t,11] <- 0 po[14,i,t,12] <- 0 po[14,i,t,13] <- 0 po[14,i,t,14] <- d1[t] po[14,i,t,15] <- 0 po[14,i,t,16] <- 1-d1[t] po[15,i,t,1] <- 0 po[15,i,t,2] <- 0 po[15,i,t,3] <- 0 po[15,i,t,4] <- 0 po[15,i,t,5] <- 0 po[15,i,t,6] <- 0 po[15,i,t,7] <- 0 po[15,i,t,8] <- 0 po[15,i,t,9] <- 0 po[15,i,t,10] <- 0 po[15,i,t,11] <- 0 po[15,i,t,12] <- 0 po[15,i,t,13] <- 0 po[15,i,t,14] <- 0 po[15,i,t,15] <- d2[t] po[15,i,t,16] <- 1-d2[t] po[16,i,t,1] <- 0 po[16,i,t,2] <- 0 po[16,i,t,3] <- 0 po[16,i,t,4] <- 0 po[16,i,t,5] <- 0 po[16,i,t,6] <- 0 po[16,i,t,7] <- 0 po[16,i,t,8] <- 0 po[16,i,t,9] <- 0 po[16,i,t,10] <- 0 po[16,i,t,11] <- 0 po[16,i,t,12] <- 0 po[16,i,t,13] <- 0 po[16,i,t,14] <- 0 po[16,i,t,15] <- 0 po[16,i,t,16] <- 1 } #t } #i # State-space model likelihood for (i in 1:nind){ z[i,f[i]] <- Y[i,f[i]] for (t in (f[i]+1):n.occasions){ # loop over time # State equation: draw S(t) given S(t-1) z[i,t] ~ dcat(ps[z[i,t-1], i, t-1,]) # Observation equation: draw O(t) given S(t) Y[i,t] ~ dcat(po[z[i,t], i, t-1,]) } #t } # i ############################################################ # 4.3. Likelihood for reproductive data: Poisson regression ############################################################ for (t in 1:(nyears-1)){ J[t] ~ dpois(rho[t]) rho[t] <- R[t] * b[t] } } # End Model ",fill = TRUE) sink() # combine all data bugs.data <- list(nyears = nyears, census = popcount, deaths_p = rec.dead.poison, deaths_o = rec.dead.other, J = nestlings[1:(nyears-1)], R = R[1:(nyears-1)], Y = rCH, f = f, n.occasions = dim(rCH)[2], nind = dim(rCH)[1], z = zCH) # Initial values # Function to create initial values for unknown z (modified from [42]) ms.init.z <- function(ch, f){ for (i in 1:dim(ch)[1]){ for (c in (f[i]+1):dim(ch)[2]){ if (is.na(ch[i,c])) {ch[i,c] <- sample(c(3,4,5,6,11,12,13), 1, replace = TRUE)} else {ch[i,c] <- NA} } } return(ch) } inits <- function(){list(SBad = runif(1, 0.5, 1), l.mfec = rnorm(1, 0.2, 0.5), sig.fec = runif(1, 0.1, 10), N1 = c(NA, round(runif((nyears-1), 8,12),0)), N2 = c(NA, round(runif((nyears-1), 6,8),0)), Nad = c(NA, round(runif((nyears-1), 4,6),0)), Ndp = c(NA, rep(4,nyears-1)), Ndo = c(NA, rep(4,nyears-1)), mean.s = runif(1, 0.5, 0.6), mean.betajuv = runif(1, 0, 1), mean.beta1y = runif(1, 0, 1), mean.beta2my = runif(1, 0, 1), mean.alpha1 = runif(1, 0.5, 1), mean.alpha2 = runif(1, 0, 0.5), mean.alpha3 = runif(1, 0, 0.1), mean.p = runif(1, 0.5, 1), mean.c = runif(1, 0, 0.5), mean.d1 = runif(1, 0, 0.1), mean.d2 = runif(1, 0, 0.5), z = ms.init.z(zCH, f) )} # Define parameters to be monitored parameters <- c("b", "lambda", "mfec", "mlam", "sig.fec", "N1", "N2", "Nad", "Ntot", "mean.s", "mean.betajuv", "mean.beta1y", "mean.beta2my", "mean.alpha1", "mean.alpha2", "mean.alpha3", "mean.p", "mean.c", "mean.d1", "mean.d2", "SBad", "Snp.juv", "Snp.1y", "Snp.ad", "mean.betahat", "Npop", "Ndp", "mdp", "Ndo", "mdo" ) # MCMC settings niter <- 1000000 nthin <- 20 nburn <- 500000 nchains <- 3 # Call WinBUGS from R (on a unix machine) out <- bugs(bugs.data, inits, parameters, "ipm_redkite.txt", n.chains = nchains, n.thin = nthin, n.iter = niter, n.burnin = nburn, debug = TRUE, bugs.directory = wb, working.directory = getwd(), useWINE = TRUE)