-
Notifications
You must be signed in to change notification settings - Fork 0
/
mall_agwt_ipm_clean.jags
279 lines (243 loc) · 9.1 KB
/
mall_agwt_ipm_clean.jags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
model {
#############################
#### Band-recovery model ####
#############################
# Model code adapted from Devers et al. (2021). Please see citation at bottom of the script
## Priors for survival rate components
## muN denotes spring/summer survival probabilities, muH denotes fall/winter survival probabilities
## am = adult male, af = adult female, jm = juvenile male, jf = juvenile female.
for(t in 1:(nyrs-1)){
muN.am[t] ~ dnorm(0, 1.51)
muN.af[t] ~ dnorm(0, 1.51)
muN.jm[t] ~ dnorm(0, 1.51)
muN.jf[t] ~ dnorm(0, 1.51)
muH.am[t] ~ dnorm(0, 1.51)
muH.af[t] ~ dnorm(0, 1.51)
muH.jm[t] ~ dnorm(0, 1.51)
muH.jf[t] ~ dnorm(0, 1.51)
}
# Priors for recovery rates
for(t in 1:nyrs){
f.am[t] ~ dbeta(1,1)
f.af[t] ~ dbeta(1,1)
f.jm[t] ~ dbeta(1,1)
f.jf[t] ~ dbeta(1,1)
}
# Priors for environmental covariate coefficients
## alphas are for fall/winter survival, gammas are for spring/summer survival
for(i in 1:4){
alpha_prcp[i] ~ dnorm(0, 0.37)
alpha_dx32[i] ~ dnorm(0, 0.37)
gamma_prcp[i] ~ dnorm(0, 0.37)
gamma_dx32[i] ~ dnorm(0, 0.37)
}
# cohort-specific annual survival probabilities
for(t in 1:(nyrs-1)){
logit(SH.am[t]) <- muH.am[t] + alpha_prcp[1]*prcp[t] + alpha_dx32[1]*dx32[t]
logit(SN.am[t]) <- muN.am[t] + gamma_prcp[1]*prcp[t] + gamma_dx32[1]*dx32[t]
logit(SH.af[t]) <- muH.af[t] + alpha_prcp[2]*prcp[t] + alpha_dx32[2]*dx32[t]
logit(SN.af[t]) <- muN.af[t] + gamma_prcp[2]*prcp[t] + gamma_dx32[2]*dx32[t]
logit(SH.jm[t]) <- muH.jm[t] + alpha_prcp[3]*prcp[t] + alpha_dx32[3]*dx32[t]
logit(SN.jm[t]) <- muN.jm[t] + gamma_prcp[3]*prcp[t] + gamma_dx32[3]*dx32[t]
logit(SH.jf[t]) <- muH.jf[t] + alpha_prcp[4]*prcp[t] + alpha_dx32[4]*dx32[t]
logit(SN.jf[t]) <- muN.jf[t] + gamma_prcp[4]*prcp[t] + gamma_dx32[4]*dx32[t]
}
## M-array banding and recovery cell probabilities
### Pre-hunting season bandings
#### Adults (am = adult male, af = adult female)
# Diagonals
for(t in 1:(nyrs-1)){
recoveries.am[t,t] <- f.am[t]
recoveries.af[t,t] <- f.af[t]
for(j in (t+1):nyrs){
recoveries.am[t,j] <- f.am[j]*prod(SH.am[t:(j-1)])*prod(SN.am[t:(j-1)])
recoveries.af[t,j] <- f.af[j]*prod(SH.af[t:(j-1)])*prod(SN.af[t:(j-1)])
recoveries.am[j,t] <- 0
recoveries.af[j,t] <- 0
}
}
recoveries.am[nyrs,nyrs] <- f.am[nyrs]
recoveries.af[nyrs,nyrs] <- f.af[nyrs]
# Not recovered
for(t in 1:nyrs){
recoveries.am[t,(nyrs+1)] <- 1 - sum(recoveries.am[t,1:nyrs])
recoveries.af[t,(nyrs+1)] <- 1 - sum(recoveries.af[t,1:nyrs])
}
##### Likelihood
for(t in 1:nyrs){
recovmat.am[t,1:(nyrs+1)] ~ dmulti(recoveries.am[t,1:(nyrs+1)], relmat.am[t])
recovmat.af[t,1:(nyrs+1)] ~ dmulti(recoveries.af[t,1:(nyrs+1)], relmat.af[t])
}
#-----------------------------------------------------------------------------------
### juvenils (jm = juvenile male, jf = juvenile female)
# Diagonals
for(t in 1:nyrs){
recoveries.jm[t,t] <- f.jm[t]
recoveries.jf[t,t] <- f.jf[t]
}
# First off diagonal
for(t in 1:(nyrs-1)){
recoveries.jm[t,(t+1)] <- f.am[(t+1)]*SH.jm[t]*SN.jm[t]
recoveries.jf[t,(t+1)] <- f.af[(t+1)]*SH.jf[t]*SN.jf[t]
}
# After first off diagonal
for(t in 1:(nyrs-2)){
for(j in (t+2):nyrs){
recoveries.jm[t,j] <- f.am[j]*SH.jm[t]*SN.jm[t]*prod(SH.am[(t+1):(j-1)])*prod(SN.am[(t+1):(j-1)])
recoveries.jf[t,j] <- f.af[j]*SH.jf[t]*SN.jf[t]*prod(SH.af[(t+1):(j-1)])*prod(SN.af[(t+1):(j-1)])
}
}
# Probability is 0 for the lower triangle
for(t in 1:(nyrs-1)){
for(j in (t+1):nyrs){
recoveries.jm[j,t] <- 0
recoveries.jf[j,t] <- 0
}
}
# Not recovered
for(t in 1:nyrs){
recoveries.jm[t,(nyrs+1)] <- 1 - sum(recoveries.jm[t,1:nyrs])
recoveries.jf[t,(nyrs+1)] <- 1 - sum(recoveries.jf[t,1:nyrs])
}
##### Likelihood
for(t in 1:nyrs){
recovmat.jm[t,1:(nyrs+1)] ~ dmulti(recoveries.jm[t,1:(nyrs+1)], relmat.jm[t])
recovmat.jf[t,1:(nyrs+1)] ~ dmulti(recoveries.jf[t,1:(nyrs+1)], relmat.jf[t])
}
### Post-hunting season bandings
#### Adults
# Diagonals
for(t in 1:(nyrs-2)){
recoveriesP.am[t,t] <- f.am[(t+1)]*SN.am[t]
recoveriesP.af[t,t] <- f.af[(t+1)]*SN.af[t]
for(j in (t+1):(nyrs-1)){
recoveriesP.am[t,j] <- f.am[(j+1)]*prod(SN.am[t:j])*prod(SH.am[(t+1):j])
recoveriesP.af[t,j] <- f.af[(j+1)]*prod(SN.af[t:j])*prod(SH.af[(t+1):j])
recoveriesP.am[j,t] <- 0
recoveriesP.af[j,t] <- 0
}
}
recoveriesP.am[(nyrs-1),(nyrs-1)] <- f.am[nyrs]*SN.am[(nyrs-1)]
recoveriesP.af[(nyrs-1),(nyrs-1)] <- f.af[nyrs]*SN.af[(nyrs-1)]
# Not recovered
for(t in 1:(nyrs-1)){
recoveriesP.am[t,(nyrs)] <- 1 - sum(recoveriesP.am[t,1:(nyrs-1)])
recoveriesP.af[t,(nyrs)] <- 1 - sum(recoveriesP.af[t,1:(nyrs-1)])
}
##### Likelihood
for(t in 1:(nyrs-1)){
recovmatP.am[t,1:nyrs] ~ dmulti(recoveriesP.am[t,1:nyrs], relmatP.am[t])
recovmatP.af[t,1:nyrs] ~ dmulti(recoveriesP.af[t,1:nyrs], relmatP.af[t])
}
#-----------------------------------------------------------------------------------
### Juveniles
# Diagonals
for(t in 1:(nyrs-1)){
recoveriesP.jm[t,t] <- f.am[(t+1)]*SN.jm[t]
recoveriesP.jf[t,t] <- f.af[(t+1)]*SN.jf[t]
}
# First off diagonal
for(t in 1:(nyrs-2)){
for(j in (t+1):(nyrs-1)){
recoveriesP.jm[t,j] <- f.am[(j+1)]*SN.jm[t]*prod(SH.am[(t+1):j])*prod(SN.am[(t+1):j])
recoveriesP.jf[t,j] <- f.af[(j+1)]*SN.jf[t]*prod(SH.af[(t+1):j])*prod(SN.af[(t+1):j])
recoveriesP.jm[j,t] <- 0
recoveriesP.jf[j,t] <- 0
}
}
# Not recovered
for(t in 1:(nyrs-1)){
recoveriesP.jm[t,nyrs] <- 1 - sum(recoveriesP.jm[t,1:(nyrs-1)])
recoveriesP.jf[t,nyrs] <- 1 - sum(recoveriesP.jf[t,1:(nyrs-1)])
}
##### Likelihood
for(t in 1:(nyrs-1)){
recovmatP.jm[t,1:nyrs] ~ dmulti(recoveriesP.jm[t,1:nyrs], relmatP.jm[t])
recovmatP.jf[t,1:nyrs] ~ dmulti(recoveriesP.jf[t,1:nyrs], relmatP.jf[t])
}
#### Annual survival probabilities
for(t in 1:(nyrs-1)){
S.am[t]<-SH.am[t] * SN.am[t]
S.af[t]<-SH.af[t] * SN.af[t]
S.jm[t]<-SH.jm[t] * SN.jm[t]
S.jf[t]<-SH.jf[t] * SN.jf[t]
}
########################################
#### Productivity (age-ratio) model ####
########################################
#Priors
tau.R <- pow(sd.R, -2)
sd.R ~ dunif(0, 1)
beta ~ dnorm(0, 1)
## Priors for environmental covariate coefficients
beta_pond ~ dnorm(0, 0.01)
beta_prcp ~ dnorm(0, 0.01)
beta_dx32 ~ dnorm(0, 0.01)
# priors for missing pond count in 2020
# ponds[16] ~ dnorm(0, 1) # for mallard
ponds[29] ~ dnorm(0, 1) # for agwt
# Likelihood
for (t in 1:nyrs){
#true fall age ratio
mu.R[t] <- beta
esp[t] ~ dnorm(mu.R[t], tau.R)
log(R[t]) <- esp[t] + beta_pond*ponds[t] + beta_prcp*prev.prcp[t] + beta_dx32*prev.dx32[t]
v[t] <- f.jf[t]/f.af[t] # differential vulnerability
q[t] <- R[t]*v[t]/(1 + R[t]*v[t])
W.jv[t] ~ dbinom(q[t], W.tot[t])
} # t
################################
#### Population count model ####
################################
# Priors
sig.t ~ dgamma(3.5,0.05) #agwt
# sig.t ~ dgamma(15, 0.1) #mall
sig2.t <- pow(sig.t, 2)
tau.t <- pow(sig.t, -2)
# Prior for latent Bpop size for eastern survey area prior to 1998
delta ~ dgamma(4, 0.1) #agwt
# initial population size (tsa = traditional survey area, esa = eastern survey area)
##### initial population for MALL
n_HY_fem ~ dnorm(700*0.4*0.45,0.0005)I(0,) #juvenile female
n_HY_mal ~ dnorm(700*0.4*0.55,0.0005)I(0,) #juvenile male
n_AHY_fem ~ dnorm(700*0.6*0.27,0.0005)I(0,) #adult female
n_AHY_mal ~ dnorm(700*0.6*0.73,0.0005)I(0,) #adult male
##### initial population for AGWT
#n_HY_fem ~ dnorm(50, 0.0016)I(0,) #juvenile female
#n_HY_mal ~ dnorm(50, 0.0016)I(0,) #juvenile male
#n_AHY_fem ~ dnorm(50, 0.0016)I(0,) #adult female
#n_AHY_mal ~ dnorm(50, 0.0016)I(0,) #adult male
N_HY_fem[1] <- round(n_HY_fem)
N_AHY_fem[1] <- round(n_AHY_fem)
N_HY_mal[1] <- round(n_HY_mal)
N_AHY_mal[1] <- round(n_AHY_mal)
# Likelihood
# state process
for(t in 2:nyrs){
# Popluation size during the summer (Bpop survey)
N_HY_mal[t] <- (N_HY_fem[t-1] + N_AHY_fem[t-1])*R[t-1]*SH.jm[t-1]*(SN.jm[t-1]^0.25)
N_HY_fem[t] <- (N_HY_fem[t-1] + N_AHY_fem[t-1])*R[t-1]*SH.jf[t-1]*(SN.jf[t-1]^0.25)
N_AHY_mal[t] <- (N_HY_mal[t-1] + N_AHY_mal[t-1])*S.am[t-1]
N_AHY_fem[t] <- (N_HY_fem[t-1] + N_AHY_fem[t-1])*S.af[t-1]
}
for(t in 1:nyrs) {
# Total population size
N_tot[t] <- N_HY_fem[t] + N_HY_mal[t] + N_AHY_fem[t] + N_AHY_mal[t]
}
# Annual population growth rate
for(t in 1:(nyrs-1)) {
lambda[t] <- N_tot[t+1]/N_tot[t]
}
# Observation process
## Years prior to beginning of eastern survey area surveys
for(t in 1:(begin.esa.year-1)){ # Comment this for loop if running mallard model
y_t[t] ~ dnorm(N_tot[t] + delta, tau.t)
}
## Years after eastern survey area surveys began
for(t in begin.esa.year:nyrs){ # Comment this out if running mallard model
# for(t in 1:nyrs){ # Comment this out if running agwt model
y_t[t] ~ dnorm(N_tot[t], tau.t)
}
} # end model
## Literature on which the dead-recovery model is adapted:
# Devers, P. K., R. L. Emmet, G. S. Boomer, G. S. Zimmerman, and J. A. Royle. 2021. “Evaluation of a Two-Season Banding Program to Estimate and Model Migratory Bird Survival.” Ecological Applications 31: 1–18.