-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrh_js_phi0_gamTime_pGearEffort_multistate.jags
119 lines (109 loc) · 3.36 KB
/
srh_js_phi0_gamTime_pGearEffort_multistate.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
model{
## Priors
mean.phi ~ dunif(0,1)
p0fyke ~ dunif(0,1) # Capture prob in fyke when effort is 1
p0pit ~ dunif(0,1)
p0seine ~ dunif(0,1)
for(t in 1:(n.occ-1)){
gamma[t] ~ dunif(0,1) # entry probabilities
}
# We don't have much effort info for seine
# Apparently no seining happened in years 4 and 5
pSeine[1] <- 0 # dummy occasion
pSeine[2] <- p0seine #dunif(0,1)
pSeine[3] <- p0seine #dunif(0,1)
pSeine[4] <- p0seine
pSeine[5] <- 0
pSeine[6]<-0
pFyke[1]<-0 # dummy occasion
pPit[1]<-0 # dummy occasion
# Effective capture probability in fyke net in year t
# fykeEffort should be the number of days of effort in each year
for(t in 2:n.occ){
pFyke[t] <- 1-(1-p0fyke)^fykeEffort[t]
#pitEffort is number of days operational across all antennae
pPit[t] <- 1-(1-p0pit)^pitEffort[t]
}
#-------------------------------------
#States:
#1 not yet entered
#2 alive
#3 dead
#Observations
#1 not seen
#2-8 Seen
#-------------------------------------
# probabilities of state S(t+1) given S(t)
for(i in 1:M){
for(t in 1:(n.occ-1)){
ps[1,i,t,1]<-1-gamma[t]
ps[1,i,t,2]<-gamma[t]
ps[1,i,t,3]<-0
ps[2,i,t,1]<-0
ps[2,i,t,2]<-mean.phi
ps[2,i,t,3]<-1-mean.phi
ps[3,i,t,1]<-0
ps[3,i,t,2]<-0
ps[3,i,t,3]<-1
}
for(t in 1:n.occ){
# probabilities of O(t) given S(t)
cap.probs[1,i,t,1] <- 1 # Not yet entered, thus not detected
cap.probs[1,i,t,2] <- 0
cap.probs[1,i,t,3] <- 0
cap.probs[1,i,t,4] <- 0
cap.probs[1,i,t,5] <- 0
cap.probs[1,i,t,6] <- 0
cap.probs[1,i,t,7] <- 0
cap.probs[1,i,t,8] <- 0
cap.probs[2,i,t,1] <- (1-pSeine[t])*(1-pFyke[t])*(1-pPit[t]*tag.dat.aug[i,t]) # Pr(not detected|alive)
cap.probs[2,i,t,2] <- pSeine[t]*(1-pFyke[t])*(1-pPit[t]*tag.dat.aug[i,t]) # Pr(detected in seine, but not by other gear)
cap.probs[2,i,t,3] <- pFyke[t]*(1-pSeine[t])*(1-pPit[t]*tag.dat.aug[i,t]) # Pr(detected in fyke, but not by other gear)
cap.probs[2,i,t,4] <- pPit[t]*tag.dat.aug[i,t]*(1-pFyke[t])*(1-pSeine[t]) # Pr(detected by antenna, but not by other gear)
cap.probs[2,i,t,5] <- pFyke[t]*pPit[t]*tag.dat.aug[i,t]*(1-pSeine[t]) # Pr(detected by fyke and antenna)
cap.probs[2,i,t,6] <- pSeine[t]*pFyke[t]*(1-pPit[t]*tag.dat.aug[i,t]) # Pr(detected by seine and fyke)
cap.probs[2,i,t,7] <- pSeine[t]*pPit[t]*tag.dat.aug[i,t]*(1-pFyke[t]) # Pr(detected by seine and antenna)
cap.probs[2,i,t,8] <- pSeine[t]*pFyke[t]*pPit[t]*tag.dat.aug[i,t] # Pr(detected by all three gears)
cap.probs[3,i,t,1] <- 1 # Dead, thus not detected
cap.probs[3,i,t,2] <- 0
cap.probs[3,i,t,3] <- 0
cap.probs[3,i,t,4] <- 0
cap.probs[3,i,t,5] <- 0
cap.probs[3,i,t,6] <- 0
cap.probs[3,i,t,7] <- 0
cap.probs[3,i,t,8] <- 0
}
}
for (i in 1:M){
z[i, 1] <- 1 # All individuals are in state 0 at t=1
for (t in 2:n.occ){
z[i,t] ~ dcat(ps[z[i,t-1], i, t-1,]) # Actual state (1=alive, 0=dead or not yet entered)
y[i,t] ~ dcat(cap.probs[z[i,t], i, t-1,])
}
}
for( t in 1:(n.occ-1)){
qgamma[t]<-1-gamma[t]
}
cprob[1]<-gamma[1]
for(t in 2:(n.occ-1)){
cprob[t]<-gamma[t]*prod(qgamma[1:(t-1)])
}
psi<-sum(cprob[])
for(i in 1:M){
for(t in 2:n.occ){
al[i, t-1]<-equals(z[i,t], 2)
}
for(t in 1:(n.occ-1)){
d[i,t]<-equals(z[i,t]-al[i,t], 0)
}
alive[i]<-sum(al[i,])
}
for(t in 1:(n.occ-1)){
N[t]<-sum(al[,t])
B[t]<-sum(d[,t])
}
for(i in 1:M){
w[i]<-1-equals(alive[i], 0)
}
Nsuper<-sum(w[])
}