-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.R
171 lines (142 loc) · 4.23 KB
/
models.R
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
#jags w overdisersion on each observation
#area mean
writeLines("
model{
# priors:
alpha[1] <- 0 #area baseline
for (a in 2:A){alpha[a] ~ dnorm(0, 0.0001)}
tau ~ dgamma(0.001, 0.001) # prior for mixed effect precision
sd <- sqrt(1/tau)
for(f in 1:2){ #loop around fleet
for(y in 1:Y){ # loop around years
count[y,f,1:A] ~ dmulti(q[y,f,1:A], M[y,f])
for(a in 1:A){
re[y,f,a] ~ dnorm(0, tau)
q[y,f,a] <- phi[y,f,a]/sum(phi[y,f,])
log(phi[y,f,a]) <- alpha[a] + re[y,f,a]
}
}
}
}
", con="model_alpha.txt")
modfile_alpha <- 'model_alpha.txt'
#area mean with only 1 fleet
writeLines("
model{
# priors:
alpha[1] <- 0 #area baseline
for (a in 2:A){alpha[a] ~ dnorm(0, 0.0001)}
tau ~ dgamma(0.001, 0.001) # prior for mixed effect precision
sd <- sqrt(1/tau)
for(y in 1:Y){ # loop around years
count[y,1:A] ~ dmulti(q[y,1:A], M[y])
for(a in 1:A){
re[y,a] ~ dnorm(0, tau)
q[y,a] <- phi[y,a]/sum(phi[y,])
log(phi[y,a]) <- alpha[a] + re[y,a]
}
}
}
", con="model_alpha0.txt")
modfile_alpha0 <- 'model_alpha0.txt'
#fleet/area mean
writeLines("
model{
# priors:
alpha[1] <- 0 #area baseline
for (a in 2:A){alpha[a] ~ dnorm(0, 0.0001)}
for (a in 1:A){beta[1,a] <- 0 } #fleet baseline
beta[2, 1] <- 0 ; #area baseline
for (a in 2:A){ beta[2,a] ~ dnorm(0, 0.0001)}
tau ~ dgamma(0.001, 0.001) # prior for mixed effect precision
sd <- sqrt(1/tau)
for(f in 1:2){ #loop around fleet
for(y in 1:Y){ # loop around years
count[y,f,1:A] ~ dmulti(q[y,f,1:A], M[y,f])
for(a in 1:A){
re[y,f,a] ~ dnorm(0, tau)
q[y,f,a] <- phi[y,f,a]/sum(phi[y,f,])
log(phi[y,f,a]) <- alpha[a] + beta[f,a] + re[y,f,a]
}
}
}
}
", con="model_beta.txt")
modfile_beta <- 'model_beta.txt'
#area slopes w/ only 1 fleet
writeLines("
model{
# priors:
alpha[1] <- 0 #area baseline
for (a in 2:A){alpha[a] ~ dnorm(0, 0.0001)}
epsilon[1] <- 0 #area baseline
for (a in 2:A){epsilon[a] ~ dnorm(0, 0.0001)}
tau ~ dgamma(0.001, 0.001) # prior for mixed effect precision
sd <- sqrt(1/tau)
for(y in 1:Y){ # loop around years
count[y,1:A] ~ dmulti(q[y,1:A], M[y])
for(a in 1:A){
re[y,a] ~ dnorm(0, tau)
q[y,a] <- phi[y,a]/sum(phi[y,])
log(phi[y,a]) <- alpha[a] + epsilon[a]*yearc[y] + re[y,a]
}
}
}
", con="model_epsilon0.txt")
modfile_epsilon0 <- 'model_epsilon0.txt'
#area slopes
writeLines("
model{
# priors:
alpha[1] <- 0 #area baseline
for (a in 2:A){alpha[a] ~ dnorm(0, 0.0001)}
for (a in 1:A){beta[1,a] <- 0 } #fleet baseline
beta[2, 1] <- 0 ; #area baseline
for (a in 2:A){ beta[2,a] ~ dnorm(0, 0.0001)}
epsilon[1] <- 0 #area baseline
for (a in 2:A){epsilon[a] ~ dnorm(0, 0.0001)}
tau ~ dgamma(0.001, 0.001) # prior for mixed effect precision
sd <- sqrt(1/tau)
for(f in 1:2){ #loop around fleet
for(y in 1:Y){ # loop around years
count[y,f,1:A] ~ dmulti(q[y,f,1:A], M[y,f])
for(a in 1:A){
re[y,f,a] ~ dnorm(0, tau)
q[y,f,a] <- phi[y,f,a]/sum(phi[y,f,])
log(phi[y,f,a]) <- alpha[a] + beta[f,a] + epsilon[a]*yearc[y] + re[y,f,a]
}
}
}
}
", con="model_epsilon.txt")
modfile_epsilon <- 'model_epsilon.txt'
writeLines("
model{
# priors:
alpha[1] <- 0 #area baseline
for (a in 2:A){alpha[a] ~ dnorm(0, 0.0001)}
for (a in 1:A){beta[1,a] <- 0 } #fleet baseline
beta[2, 1] <- 0 ; #area baseline
for (a in 2:A){ beta[2,a] ~ dnorm(0, 0.0001)}
# gamma[1] <- 0 #area baseline
# for (a in 2:A){gamma[a] ~ dnorm(0, 0.0001)}
epsilon[1] <- 0 #area baseline
for (a in 2:A){epsilon[a] ~ dnorm(0, 0.0001)}
for (a in 1:A){gamma[1,a] <- 0 } #fleet baseline
gamma[2,1] <- 0 ; #area baseline
for (a in 2:A){ gamma[2,a] ~ dnorm(0, 0.0001)}
tau ~ dgamma(0.001, 0.001) # prior for mixed effect precision
sd <- sqrt(1/tau)
for(f in 1:2){ #loop around fleet
for(y in 1:Y){ # loop around years
count[y,f,1:A] ~ dmulti(q[y,f,1:A], M[y,f])
for(a in 1:A){
re[y,f,a] ~ dnorm(0, tau)
q[y,f,a] <- phi[y,f,a]/sum(phi[y,f,])
log(phi[y,f,a]) <- alpha[a] + beta[f,a] + epsilon[a]*yearc[y] + gamma[f,a]*yearc[y] + re[y,f,a]
}
}
}
}
", con="model_gamma.txt")
modfile_gamma <- 'model_gamma.txt'