-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
1822 lines (1569 loc) · 55.3 KB
/
index.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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Integrated approach to modeling to krill population dynamics in Wester Antarctic Peninsula: spatial and ecosystem considerations"
subtitle: "Working Paper to be submitted in a CCAMLR EMM-WG 2024"
author: "Mardones, M; Cárdenas, C., Krüger, L., Santa Cruz, F."
date: "`r format(Sys.time(), '%d %B, %Y')`"
bibliography: SA_krill.bib
csl: apa.csl
link-citations: yes
linkcolor: blue
output:
html_document:
keep_md: true
toc: true
toc_deep: 3
toc_float:
collapsed: false
smooth_scroll: false
theme: cosmo
fontsize: 0.9em
linestretch: 1.7
html-math-method: katex
self-contained: true
code-tools: true
editor_options:
markdown:
wrap: 72
---
```{r setup1, echo=FALSE}
#rm(list = ls())
#set.seed(999)
knitr::opts_chunk$set(echo = FALSE,
message = FALSE,
warning = FALSE,
fig.align = 'center',
fig.pos = "H",
dev = 'jpeg',
dpi = 300,
tidy.opts=list(width.cutoff=50),
tidy=TRUE)
#XQuartz is a mess, put this in your onload to default to cairo instead
options(bitmapType = "cairo")
# (https://github.com/tidyverse/ggplot2/issues/2655)
# Lo mapas se hacen mas rapido
```
```{r message=FALSE, eval=TRUE}
# install.packages("devtools")
# devtools::install_github("r4ss/r4ss", ref="development")
# install.packages("caTools")
# library("caTools")
# install.packages("r4ss")
library(r4ss)
library(here)
#remotes::install_github("PIFSCstockassessments/ss3diags")
library(ss3diags)
library(kableExtra)
library(doParallel) # facilita la ejecución paralela en R
detectCores()
registerDoParallel(8)
library(ggpubr)
library(tibble)
library(openxlsx)
library(ggthemes)
library(forecast)
library(tidyr)
library(mixR)
library(readxl)
```
```{r message=FALSE, warning=FALSE, echo=TRUE}
dir01 <- here("s01") # agreggate data (no spatial diferences)
dir1<-here("s1") # Data strata flishery
dir2<-here("s2") # Same 9 with areas (SubStrata) as fleet. Dif size comoposition and dif CPUE and dif survey length and biomass data by strata
dir3<-here("s3") # whitout S-R
dir4<-here("s4") #
dir5<-here("s5") #
dir6<-here("s6") #
dir7<-here("s7") # 2 set parametres EMM-2024/23 (Mardones)
dir8<-here("s8") # s1 platoons
dir9<-here("s9") # s1 w/ blocks
dirtest<-here("test")
Figs <- here("Figs")# S
```
# OVERVIEW
In a simple way, the core of Stock Synthesis is its population dynamics
model, which represents the dynamics of krill populations over time.
This model incorporates key biological, environmental and predator data
sources. The model is typically formulated using mathematical equations
that describe how these parameters interact to determine the abundance
and distribution of krill in the study area.
## Statistical model (SS3)
Stock Synthesis v.3.30.21 is a widely used software tool for assessing
fish and invertebrate populations, including krill (Euphausia superba)
in the Antarctic Peninsula region. The methodology employed by Stock
Synthesis involves a comprehensive and integrated approach, utilizing
various data sources and modeling techniques to estimate the main
population variables of krill in WAP.
The stock assesment model was configured using Stock Synthesis (SS3
hereafter)[SS3](https://vlab.noaa.gov/web/stock-synthesis) [@Methot2013;
@methot2020stock] with the most updated version (V.3.30.21). SS3 is a
structured age and size stock evaluation model, in the class of models
called *"Integrated stock evaluation analysis model"*. SS3 has a stock
population sub-model that simulates growth, maturity, fecundity,
recruitment, movement, and mortality processes, and observation
sub-models and expected values for different types of data. The model is
coded in `C++` with estimation parameters enabled by automatic
differentiation (ADMB) [@Fournier2012; @Methot2013]. The analysis of
results and outputs uses R tools and the graphical interface of the
*r4ss* and *ss3diags* library [@Taylor2019; @Winker2023].
By integrating data from multiple sources and considering spatial
heterogeneity, the assessment methodology using Stock Synthesis
v.3.30.21 provides a robust framework for evaluating the status of krill
populations in the Antarctic Peninsula region. This information is
essential for supporting management decisions aimed at ensuring the
sustainable use of krill resources in this ecologically sensitive area.
## Parametres
read files
```{r}
# leo archivos para plotear y hacer tablas
start1 <- SS_readstarter(file = file.path(dir1,
"starter.ss"),
verbose = FALSE)
# note the data and control file names can vary, so are determined from the
# starter file.
dat1 <- SS_readdat(file = file.path(dir1, start1$datfile),
verbose = FALSE)
# Read in ctl file. Note that the data fileR object is needed so that SS_readctl
# assumes the correct data structure
ctl1 <- r4ss::SS_readctl(file = file.path(dir1,
start1$ctlfil),
verbose = FALSE,
use_datlist = TRUE,
datlist = dat1)
fore1 <- r4ss::SS_readforecast(file = file.path(dir1,
"forecast.ss"),
verbose = FALSE)
# can also read in wtatage.ss for an empirical wt at age model using
# r4ss::SS_readwtatage()
```
```{r}
parbio<-ctl1$MG_parms[1:10,c(1:3,7)]
row.names( parbio)<-c("Nat M",
"Lmin",
"Lmax",
"VonBert K",
"CV young",
"CV old",
"Wt a",
"Wt b",
"L50%",
"Mat slope")
SRpar<-ctl1$SR_parms[1:5,c(1:3,7)]
Qpar<-ctl1$Q_parms[1:2,c(1:3,7)]
Selpar<-ctl1$size_selex_parms[1:22,c(1:3,7)]
parInit<-as.data.frame(rbind(parbio,SRpar,Qpar,Selpar))
```
```{r eval=FALSE}
wb <- createWorkbook()
addWorksheet(wb, "parameters")
writeData(wb, "parameters", parInit)
# Guardar el workbook
saveWorkbook(wb, "DataKrill.xlsx", overwrite = TRUE)
```
```{r}
parInit %>%
kbl(booktabs = T,
format = "html",
position="ht!",
caption = "Input parameters for the initial SS3 model of krill. Each parameter line contains a minimum value (LO), maximum value (HI), and initial value (INIT). If the phase (PHASE) for the parameter is negative, the parameter is fixed as input") %>%
kable_paper("hover",
full_width = F)%>%
kable_styling(latex_options = c("striped",
"condensed"),
full_width = FALSE,
font_size=10,
html_font = "arial")%>%
pack_rows(index = c("Mortalidad natural" = 1,
"Crecimiento"= 5,
"Relación longitud-peso" = 2,
"Ojiva de madurez"=2,
"Relación stock-recluta"=5,
"Capturabilidad"=2,
"Selectividad"=4))
```
## Scenarios
In Table 1 we have ten scenarios to test different option in modeling
about main consideration in assessment of krill population.
| Scenario | Description |
|:------------:|:---------------------------------------------------------|
| s01 | Fishery and Survey (AMLR) data, Predator, Environmental aggregate data in 48.1 |
| s1 | Fishery and Survey (AMLR) data Length, Index, Catch by strata. Predator and Env data |
| s2 | "s1" without S-R relation |
| s3 | "s1" BH S-R relation weak (0.9 steepness) |
| s4 | "s1" BH S-R relation strong (0.6 steepness) |
| s5 | "s1" BH S-R relation mid-strong estimated |
| s6 | "s1" Ricker S-R relation estimated |
| s7 | "s1" w/ set of parameters estimated in @EMM-204/32 |
| s8 | "s1" test data weighting |
| s9 | "s1" w/ selectivity blocks |
## Run Models
```{r eval=FALSE, message=F, include=FALSE, echo=TRUE}
# Lista de directorios para correro tordos juntos
directorios <- c("s01",
"s1",
"s2",
"s3",
"s4",
"s5",
"s6",
"s7",
"s8",
"s9") # Agrega aquí todos los nombres de las carpetas que deseas procesar
# Bucle para ejecutar el código en cada directorio
for (dir in directorios) {
r4ss::run(
dir = dir,
exe = "ss_osx",
skipfinished = FALSE,
show_in_console = TRUE
)
}
```
```{r eval=FALSE, message=F, include=FALSE}
#OR with rby separate
#shell(cmd="ss") # run SS to windows
# or
r4ss::run(
dir = dir8,
exe = "ss_osx",
skipfinished = FALSE, # TRUE will skip running if Report.sso present
show_in_console = TRUE # change to true to watch the output go past
)
```
Read outputs
```{r message=F, include=FALSE}
#s01
base.model01 <- SS_output(dir=dir01,
covar=T,
forecast=T)
#s1
base.model1 <- SS_output(dir=dir1,
covar=T,
forecast=T)
#s2
base.model2 <- SS_output(dir=dir2,
covar=T,
forecast=T)
#s3
base.model3 <- SS_output(dir=dir3,
covar=T,
forecast=T)
#s4
base.model4 <- SS_output(dir=dir4,
covar=T,
forecast=T)
#s5
base.model5 <- SS_output(dir=dir5,
covar=T,
forecast=T)
#s6
base.model6 <- SS_output(dir=dir6,
covar=T,
forecast=T)
#s7
base.model7 <- SS_output(dir=dir7,
covar=T,
forecast=T)
#s8
base.model8 <- SS_output(dir=dir8,
covar=T,
forecast=T)
#s9
base.model9 <- SS_output(dir=dir9,
covar=T,
forecast=T)
#stest
base.modeltest <- SS_output(dir=dirtest,
covar=T,
forecast=T)
```
Just some time series plots
```{r}
SSplotTimeseries(base.modeltest,
subplot = 1)
SSplotTimeseries(base.modeltest,
subplot = 9)
```
and fits
```{r}
SSplotComps(base.modeltest,
subplots = 1,
maxrows = 5,
maxcols = 5)
```
```{r eval= FALSE, message=F, include=FALSE}
# html
SS_plots(base.modeltest,
uncertainty=T,
datplot = T,
png=T,
aalresids = F,
btarg=0.75,
minbthresh=0.20,
forecast=T)
```
# RESULTS
### Main Variables poulation
Total biomass
```{r eval=FALSE}
total01 <- as.data.frame(base.model01$timeseries[1:50,c(2,5)]) %>%
mutate(Serie = "No Spatial")
total1 <- as.data.frame(base.model1$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial implicit")
total2 <- as.data.frame(base.model2$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial w/ without S-R relation")
total3 <- as.data.frame(base.model3$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial w/ S-R relation weak (0.9 steepness)")
total4 <- as.data.frame(base.model4$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial w/ S-R relation strong (0.6 steepness)")
total5 <- as.data.frame(base.model5$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial w/ S-R relation mid-strong estimated ")
total6 <- as.data.frame(base.model6$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial w/ Ricker S-R relation estimated")
total7 <- as.data.frame(base.model7$timeseries[,c(2,5)]) %>%
mutate(Serie = "Spatial w/ New set parameters Linf, k and M")
totalbio <- rbind(total01,
total1,
total2,
total3,
total4,
total5,
total6,
total7)
ggplot(totalbio, aes(x = Yr, y = Bio_all, color=Serie)) +
geom_point(size=0.7,
col="black") +
geom_smooth(method = "loess",
span=0.75,
se=TRUE)+
labs(title = "Compare variables between scenarios",
x = "",
y = "Total biomass (mt)") +
theme_few() +
scale_color_viridis_d(option="H",
name="Scenarios")+
theme(axis.text.x = element_text(angle = 90,
hjust = 1))
```
```{r eval=FALSE, message=F, include=FALSE}
SS_plots(base.model7,
uncertainty = TRUE,
datplot = T,
png=T,
aalresids = F,
btarg=0.75,
minbthresh=0.2,
forecast=T)
```
Data used en both (spatial and No spatial models)
```{r }
SSplotData(base.model01, subplot = 1,
fleetnames = c("Fishery", "Survey", "Predator"),
fleetcol = c("blue","green", "red"))
SSplotData(base.model1,
subplot = 1,
pheight = 15)
```
Respecto a los valores y parametros biologicos modelados, los siguientes
graficos identifican los estimadores puntuales del recurso
```{r fig.height=6}
SSplotSelex(base.model01,
subplots = 1)
SSplotSelex(base.model1,
subplots = 1)
SSplotSelex(base.model2,
subplots = 1)
SSplotSelex(base.model3,
subplots = 1)
SSplotSelex(base.model4,
subplots = 1)
SSplotSelex(base.model5,
subplots = 1)
SSplotSelex(base.model6,
subplots = 1)
SSplotSelex(base.modeltest,
subplots = 1)
```
```{r eval=FALSE}
SSplotComps(base.model01,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model1,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model2,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model3,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model4,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model5,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model6,
subplots = 1,
maxrows = 5,
maxcols = 5)
SSplotComps(base.model7,
subplots = 1,
maxrows = 5,
maxcols = 5)
```
Heatmap
```{r}
df <- base.modeltest$lendbase
# Filtra el dataframe
df1 <- df %>%
dplyr::filter(Pearson<5) %>%
dplyr::select(c(1, 6, 19, 16)) %>%
dplyr::mutate(Fleet = dplyr::case_when(
Fleet == 1 ~ "FISHERYBS",
Fleet == 2 ~ "FISHERYEI",
Fleet == 3 ~ "FISHERYGS",
Fleet == 4 ~ "FISHERYJOIN",
Fleet == 5 ~ "FISHERYSSIW",
Fleet == 6 ~ "SURVEYBS",
Fleet == 7 ~ "SURVEYEI",
Fleet == 8 ~ "SURVEYGS",
Fleet == 9 ~ "SURVEYJOIN",
Fleet == 10 ~ "SURVEYSSIW",
Fleet == 11 ~ "PREDATOR",
TRUE ~ NA_character_ # Para manejar cualquier valor que no coincida
))
# Crea el heatmap
ggplot(df1, aes(x = Yr, y = Bin, fill = Pearson)) +
geom_tile() +
scale_fill_gradient2(low = "blue",
mid = "white",
high = "red",
midpoint = 0) +
facet_wrap(Fleet~., ncol=5) +
labs(title = "",
x = "",
y = "Length",
fill = "Pearson") +
theme_bw()+
theme(axis.text.x = element_text(angle = 90,
hjust = 1))
```
hexagon
```{r eval=FALSE}
# Assuming your data is in a data frame called 'lendbase'
# Filter and select relevant columns
data <- base.model1$lendbase %>%
dplyr::filter(Pearson<5) %>%
dplyr::select(c(1, 6, 19, 16)) %>%
dplyr::mutate(Fleet = dplyr::case_when(
Fleet == 1 ~ "FISHERYBS",
Fleet == 2 ~ "FISHERYEI",
Fleet == 3 ~ "FISHERYGS",
Fleet == 4 ~ "FISHERYJOIN",
Fleet == 5 ~ "FISHERYSSIW",
Fleet == 6 ~ "SURVEYBS",
Fleet == 7 ~ "SURVEYEI",
Fleet == 8 ~ "SURVEYGS",
Fleet == 9 ~ "SURVEYJOIN",
Fleet == 10 ~ "SURVEYSSIW",
Fleet == 11 ~ "PREDATOR",
TRUE ~ NA_character_ # Para manejar cualquier valor que no coincida
)) %>%
dplyr::select(Yr, Bin, Pearson)
# Create the hexagonal heatmap
ggplot(data, aes(x = Yr, y = Bin)) +
geom_hex(bins=50) + # Hexagonal bins
scale_fill_gradient2(low = "blue",
mid = "white",
high = "red",
midpoint = 0) + # Color scale
theme_minimal() + # Minimal theme for cleaner look
labs(title = "Hexagonal Heatmap of Pearson Residuals",
x = "Year",
y = "Bin",
fill = "Pearson Residual") # Labels for plot and axes
ggplot(data, aes(x = Yr, y = Bin)) +
geom_hex(bins = 50) +
scale_fill_gradient2(low = "blue",
mid = "white",
high = "red", midpoint = median(data$Bin)) +
theme_minimal() +
labs(title = "Hexagonal Heatmap of Pearson Residuals",
x = "Year", y = "Bin", fill = "Pearson Residual")
```
## Diagnosis Base Model
Step to do a good practice in model diagnosis is;
- 1. Convergence. Final convergence criteria is 1.0e-04
- 2. Residual (visual and metrics)
- 3. Retrospective analysis (Mhon Parameter)
- 4. Likelihood profile
all this framework try to follow recommendations of @Carvalho2021b
## Residual consistency
```{r}
SSplotRunstest(base.modeltest,
subplots = "len",
add=T,
plot = TRUE,
plotdir = Figs)
```
```{r eval=FALSE, fig.width=4, fig.height=5}
SSplotRunstest(base.model01,
subplots = "len",
add=T)
SSplotRunstest(base.model1,
subplots = "len",
add=T)
SSplotRunstest(base.model2,
subplots = "len",
add=T)
SSplotRunstest(base.model3,
subplots = "len",
add=T)
SSplotRunstest(base.model4,
subplots = "len",
add=T)
SSplotRunstest(base.model5,
subplots = "len",
add=T)
SSplotRunstest(base.model6,
subplots = "len",
add=T)
SSplotRunstest(base.modeltest,
subplots = "len",
add=T)
```
```{r}
SSplotRunstest(base.modeltest,
subplots = "cpue",
add=T)
```
```{r eval=FALSE}
SSplotRunstest(base.model01,
subplots = "cpue",
add=T)
SSplotRunstest(base.model1,
subplots = "cpue",
add=T)
SSplotRunstest(base.model2,
subplots = "cpue",
add=T)
SSplotRunstest(base.model3,
subplots = "cpue",
add=T)
SSplotRunstest(base.model4,
subplots = "cpue",
add=T)
SSplotRunstest(base.model5,
subplots = "cpue",
add=T)
SSplotRunstest(base.model6,
subplots = "cpue",
add=T)
SSplotRunstest(base.modeltest,
subplots = "cpue",
add=T)
```
```{r eval=FALSE}
SSplotJABBAres(base.model01,
subplots = "len",
add=T)
SSplotJABBAres(base.model1,
subplots = "len",
add=T)
SSplotJABBAres(base.model2,
subplots = "len",
add=T)
SSplotJABBAres(base.model3,
subplots = "len",
add=T)
SSplotJABBAres(base.model4,
subplots = "len",
add=T)
SSplotJABBAres(base.model5,
subplots = "len",
add=T)
SSplotJABBAres(base.model6,
subplots = "len",
add=T)
SSplotJABBAres(base.modeltest,
subplots = "len",
add=T)
```
```{r}
SSplotJABBAres(base.model01,
subplots = "cpue",
add=T)
SSplotJABBAres(base.model1,
subplots = "cpue",
add=T)
SSplotJABBAres(base.model2,
subplots = "cpue",
add=T)
SSplotJABBAres(base.model3,
subplots = "cpue",
add=T)
SSplotJABBAres(base.model4,
subplots = "cpue",
add=T)
SSplotJABBAres(base.model5,
subplots = "cpue",
add=T)
SSplotJABBAres(base.model6,
subplots = "cpue",
add=T)
SSplotJABBAres(base.modeltest,
subplots = "cpue",
add=T)
```
## Relationship Stock-Recruit
```{r eval=FALSE}
l <- base.model1$recruit$SpawnBio
m <- base.model1$recruit$pred_recr
ggplot()+
aes(l,m)+
geom_point()+
geom_smooth(method = "loess",
se =F)+
theme_few()+
ylim(0, max(base.model1$recruit$pred_recr))
```
## Retrospective analysis
Los análisis retrospectivo, dan cuenta de diferencias de estimación
(sub - sobreestimación) en los patrones entre modelos evaluados.
```{r eval=FALSE}
#one by one
retro(
dir = dirtest,
oldsubdir = "",
newsubdir = "Retrospective",
years = 0:-4,
exe = "ss_osx",
extras = "-nox",
skipfinished = FALSE)
```
```{r eval=FALSE}
for (dir in directorios) {
retro(
dir = dir,
oldsubdir = "",
newsubdir = "Retrospective",
years = 0:-5,
exe = "ss_osx",
extras = "-nox",
skipfinished = FALSE
)
}
```
```{r echo=FALSE, message=FALSE, warning=FALSE}
#s01
retroModels01 <- SSgetoutput(dirvec=file.path(dir01,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary01 <- SSsummarize(retroModels01)
# s1
retroModels1 <- SSgetoutput(dirvec=file.path(dir1,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary1 <- SSsummarize(retroModels1)
#s2
retroModels2 <- SSgetoutput(dirvec=file.path(dir2,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary2 <- SSsummarize(retroModels2)
#s3
retroModels3 <- SSgetoutput(dirvec=file.path(dir3,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary3 <- SSsummarize(retroModels3)
#s4
retroModels4 <- SSgetoutput(dirvec=file.path(dir4,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary4 <- SSsummarize(retroModels4)
#s5
retroModels5 <- SSgetoutput(dirvec=file.path(dir5,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary5 <- SSsummarize(retroModels5)
#s6
retroModels6 <- SSgetoutput(dirvec=file.path(dir6,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary6 <- SSsummarize(retroModels6)
#s7
retroModels7 <- SSgetoutput(dirvec=file.path(dir7,
"Retrospective",
paste("retro",0:-5,
sep="")))
retroSummary7 <- SSsummarize(retroModels7)
```
```{r eval=FALSE, message=FALSE, warning=FALSE}
#stest
retroModelstest <- SSgetoutput(dirvec=file.path(dirtest,
"Retrospective",
paste("retro",0:-3,
sep="")))
retroSummarytest <- SSsummarize(retroModelstest)
```
```{r echo=FALSE}
#save(retroSummary, retroModels, file="retro5.Rdata")
retro01 <- SSplotRetro(retroSummary01,
add=T,
forecast = F,
legend = T,
verbose=F)
retro1 <- SSplotRetro(retroSummary1,
add=T,
forecast = F,
legend = T,
verbose=F)
retro2 <- SSplotRetro(retroSummary2,
add=T,
forecast = F,
legend = T,
verbose=F)
retro3 <- SSplotRetro(retroSummary3,
add=T,
forecast = F,
legend = T,
verbose=F)
retro4 <- SSplotRetro(retroSummary4,
add=T,
forecast = F,
legend = T,
verbose=F)
retro5 <- SSplotRetro(retroSummary5,
add=T,
forecast = F,
legend = T,
verbose=F)
retro6 <- SSplotRetro(retroSummary6,
add=T,
forecast = F,
legend = T,
verbose=F)
retro7 <- SSplotRetro(retroSummary7,
add=T,
forecast = F,
legend = T,
verbose=F)
retrotest <- SSplotRetro(retroSummarytest,
add=T,
forecast = F,
legend = T,
verbose=F)
```
```{r eval=FALSE}
retrotest <- SSplotRetro(retroSummarytest,
add=T,
forecast = F,
legend = T,
verbose=F)
```
## Hindcast Cross-Validation and prediction skill
Implementing the Hindcast Cross-Validation (HCxval) diagnostic in Stock
Synthesis requires the same model outputs generated by
`r4ss:SS_doRetro()`. As a robust measure of prediction skill, we
implemented the mean absolute scaled error (MASE). In brief, the MASE
score scales the mean absolute. Regarding (A MASE score \> 1 indicates
that the average model forecasts are worse than a random walk.
Conversely, a MASE score of 0.5 indicates that the model forecasts twice
as accurately as a naïve baseline prediction; thus, the model has
prediction skill.
```{r}
hci = SSplotHCxval(retroSummary1,
add = T,
verbose = F,
legendcex = 0.7)
```
```{r eval=FALSE}
hci = SSplotHCxval(retroSummary01,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary1,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary2,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary3,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary4,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary5,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary6,
add = T,
verbose = F,
legendcex = 0.7)
hci = SSplotHCxval(retroSummary7,
add = T,
verbose = F,
legendcex = 0.7)
```
## Kobe (status)
```{r}
mvln = SSdeltaMVLN(base.model1,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)
```
```{r eval=FALSE}
mvln = SSdeltaMVLN(base.model01,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)
mvln = SSdeltaMVLN(base.model1,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)
mvln = SSdeltaMVLN(base.model2,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)
mvln = SSdeltaMVLN(base.model3,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)
mvln = SSdeltaMVLN(base.model4,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)
mvln = SSdeltaMVLN(base.model5,
Fref = "Btgt",
plot = TRUE,
addprj=TRUE,
virgin = TRUE,
mc=100)