forked from gavinfay/fluke-mafmc-recdisc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGAMPredictScale.Rmd
536 lines (423 loc) · 14.8 KB
/
GAMPredictScale.Rmd
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
---
title: "GAMPredictScale"
author: "Kamran Walsh"
date: "2024-04-29"
output: html_document
---
```{r}
#setwd("/Users/kam-macpro/Desktop/FlounderMSE")
#fluke <- readRDS("/Users/kam-macpro/Desktop/FlounderMSE/state_lookup.rds")
fluke <- readRDS("mse/state_lookup.rds")
#View(fluke)
#View(fluke)
library(dplyr)
library(tidyr)
library(data.table)
flukecatch <- tibble(fluke)
```
```{r}
len <- seq(10,28)
#states <- c("DE", "MD", "NJ", "NY", "VA", "CT", "MA", "RI", "NC")
#waves <- 2:6
#Bag <- bag #9 calls to the gam with state constrained
#MinLen <- minlen
#SeasLen <- catchallstates_commonreg$SeasonLen[1]
#separate prediction of 2019 catch from gam given 2019 regulations
#scale the RHL from 2019 to now using scaling factor gained from comparing gam 2019 regulations predicted catch to rec demand model predicted catch
# multiply RHL by scaling factor when comparing to CI boundaries
```
Delaware
No option for 365 day season, did number of days fished in regulations_option1 sheet
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 4 #9 calls to the gam with state constrained
MinLen <- 16.5
SeasLen <- 245
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "DE",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
library(mgcv)
gamland <- readRDS("mse/gam_land.rds")
summary(gamland)
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#fit with log(x) ~ instead of x ~
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedDE <- sum(exp(output2$fit))
expectedDE
#outputland <- sum(output2$fit)
#outputland
upperCI_testDE <- sum(output2$upr)
upperCI_testDE
lowerCI_testDE <- sum(output2$lwr)
lowerCI_testDE
```
Maryland
No option for 365 day season, did number of days fished in regulations_option1 sheet
I assume no need to worry about the greater regulatory complexity, e.g. NJ, CT, and RI shore sites, NJ/DE Bay, PRFC
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 4 #9 calls to the gam with state constrained
MinLen <- 16.5
SeasLen <- 229
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "MD",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedMD <- sum(exp(output2$fit))
expectedMD
#outputland <- sum(output2$fit)
#outputland
upperCI_testMD <- sum(output2$upr)
upperCI_testMD
lowerCI_testMD <- sum(output2$lwr)
lowerCI_testMD
```
Virginia
No option for 365 day season, did number of days fished in regulations_option1 sheet
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 4 #9 calls to the gam with state constrained
MinLen <- 16.5
SeasLen <- 244
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "VA",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedVA <- sum(exp(output2$fit))
expectedVA
#outputland <- sum(output2$fit)
#outputland
upperCI_testVA <- sum(output2$upr)
upperCI_testVA
lowerCI_testVA <- sum(output2$lwr)
lowerCI_testVA
```
North Carolina
For here I did the open season since it allowed the GAM to produce estimates
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 4 #9 calls to the gam with state constrained
MinLen <- 15
SeasLen <- 235
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "NC",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedNC <- sum(exp(output2$fit))
expectedNC
#outputland <- sum(output2$fit)
#outputland
upperCI_testNC <- sum(output2$upr)
upperCI_testNC
lowerCI_testNC <- sum(output2$lwr)
lowerCI_testNC
```
Massachusetts
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 5 #9 calls to the gam with state constrained
MinLen <- 17
SeasLen <- 140
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "MA",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedMA <- sum(exp(output2$fit))
expectedMA
#outputland <- sum(output2$fit)
#outputland
upperCI_testMA <- sum(output2$upr)
upperCI_testMA
lowerCI_testMA <- sum(output2$lwr)
lowerCI_testMA
```
Rhode Island
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 6 #9 calls to the gam with state constrained
MinLen <- 19
SeasLen <- 243
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "RI",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedRI <- sum(exp(output2$fit))
expectedRI
#outputland <- sum(output2$fit)
#outputland
upperCI_testRI <- sum(output2$upr)
upperCI_testRI
lowerCI_testRI <- sum(output2$lwr)
lowerCI_testRI
```
CT
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 4 #9 calls to the gam with state constrained
MinLen <- 19
SeasLen <- 150
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "CT",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedCT <- sum(exp(output2$fit))
expectedCT
#outputland <- sum(output2$fit)
#outputland
upperCI_testCT <- sum(output2$upr)
upperCI_testCT
lowerCI_testCT <- sum(output2$lwr)
lowerCI_testCT
```
New York
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 4 #9 calls to the gam with state constrained
MinLen <- 19
SeasLen <- 150
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "NY",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedNY <- sum(exp(output2$fit))
expectedNY
#outputland <- sum(output2$fit)
#outputland
upperCI_testNY <- sum(output2$upr)
upperCI_testNY
lowerCI_testNY <- sum(output2$lwr)
lowerCI_testNY
```
New Jersey
```{r}
#Regs
len <- seq(10,28)
waves <- 2:6
Bag <- 3 #9 calls to the gam with state constrained
MinLen <- 18
SeasLen <- 121
mround <- function(x,base){
base*round(x/base)
}
wave_seasons <- data.frame(seas = seq(60,300,15),
w2 = c(rep(0,9),seq(15,60,15),rep(60,4)),
w3 = c(rep(0,1),seq(15,60,15),rep(60,12)),
w4 = rep(60,17),
w5 = c(rep(0,5),seq(15,60,15),rep(60,8)),
w6 = c(rep(0,13),seq(15,60,15)))
dat.all <- expand.grid(State = "NJ",
Length = len,
Bag = Bag,
MinLen = MinLen,
Wave = waves
)
dat.all$SeasonLen <- as.numeric(wave_seasons[wave_seasons$seas==as.integer(mround(as.numeric(SeasLen),15)),-1])[dat.all$Wave-1]
# dat.all$SeasonLen <- SeasonLen[dat.all$Wave-1]
gamfit <- predict.gam(gamland, newdata = dat.all, type = "link" , se.fit = TRUE)
#lognormal CI
upr <- exp(gamfit$fit + (1.96 * gamfit$se.fit))
lwr <- exp(gamfit$fit - (1.96 * gamfit$se.fit))
# Extract upper + lower CIs
output2 = cbind(dat.all, gamfit, lwr, upr)
expectedNJ <- sum(exp(output2$fit))
expectedNJ
#outputland <- sum(output2$fit)
#outputland
upperCI_testNJ <- sum(output2$upr)
upperCI_testNJ
lowerCI_testNJ <- sum(output2$lwr)
lowerCI_testNJ
```
Sum
```{r}
# Coastwide expected landings
sumstates1 <- expectedDE + expectedMD + expectedVA + expectedNC + expectedMA + expectedRI + expectedCT + expectedNY +
expectedNJ
sumstates1
#Rec demand estimates from Lou
harvestrecdemand <- 8826699. # GF - this is weight (pounds) but output of GAM is numbers.
sdrecdemand <- 530839
CVrecdemand <- 0.06
#rec demand 2019 harvest estimate in numbers of fish
harvestrecdemand <- 2357629
#Scaling factor
SF <- harvestrecdemand/sumstates1
SF
#scale the RHL from 2019 to now using scaling factor gained from comparing gam 2019 regulations predicted catch to rec demand model predicted catch
# multiply RHL by scaling factor when comparing to CI boundaries
#I'm not sure if the RHL is supposed to be scaled up or down (e.g. is RHL on the scale of the rec demand or the GAM?)
SFup <- harvestrecdemand/sumstates1
SFup
SFdown <- sumstates1/harvestrecdemand
SFdown
#Notes from meeting:
#scale the RHL from 2019 to now using scaling factor gained from comparing gam 2019 regulations predicted catch to rec demand model predicted catch
#multiply RHL by scaling factor when comparing to CI boundaries
```