-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assessment_other.species_superseded.R
4630 lines (4090 loc) · 171 KB
/
Assessment_other.species_superseded.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
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
# ------ Script for running Stock assessment on other shark species---- ###################
#note: SPM, Catch-MSY (Martell & Froese 2012), aSPM(Haddon SimpleSA()), LBSPR (Hordyk et al 2015)
# Use Total catches (i.e. all sources of F), extracted from commercial and recreational catch reconstructions
# If catches have never been >1% carrying capacity, then it's in unexploited status so catch series have
# no information on productivity.
#missing:
# Include ALL species in final risk scoring
# review Smooth HH cpue and mako cpue...; SPM Tiger fit
# Milk shark SPM, hitting upper K boundary, no trend in cpue, crap Hessian, too uncertain....mention in text...
# aSPM: finish running for all species; issues with Tiger cpue fit...
# Try the LB-SPR extended to Dome-shaped selectivity (Hommik et al 2020)
#Future considerations: rather than standard SPM, try JABBA (can be
# run from R..see Winker et al 2018; it's what IUCN uses); but does not
# allow for multiple cpue series
rm(list=ls(all=TRUE))
source("C:/Matias/Analyses/SOURCE_SCRIPTS/Git_other/MS.Office.outputs.R")
source.hnld="C:/Matias/Analyses/SOURCE_SCRIPTS/Git_Population.dynamics/"
fn.source=function(script)source(paste(source.hnld,script,sep=""))
fn.source("fn.fig.R")
fn.source("Leslie.matrix.R")
fn.source("Steepness.R")
fn.source("Catch_MSY.R")
smart.par=function(n.plots,MAR,OMA,MGP) return(par(mfrow=n2mfrow(n.plots),mar=MAR,oma=OMA,las=1,mgp=MGP))
Do.jpeg="NO"
Do.tiff="YES"
source("C:/Matias/Analyses/SOURCE_SCRIPTS/Git_other/Plot.Map.R")
library(MASS)
library(plotrix)
library(PBSmapping)
library(tidyverse)
library(mvtnorm)
#if (!requireNamespace("BiocManager", quietly = TRUE))
#install.packages("BiocManager")
#BiocManager::install("Biobase")
library(Biobase)
library(numDeriv)
library(spatstat.utils)
library(Hmisc)
library(ggplot2)
library(ggrepel)
library(datalowSA)
library(zoo)
library(MCDA)
library(sfsmisc) # p values from rlm
Asses.year=2020 #enter year of assessment
Last.yr.ktch="2017-18"
hNdl=paste("C:/Matias/Analyses/Population dynamics/1.Other species/",Asses.year,sep="")
fnkr8t=function(x) if(!dir.exists(x))dir.create(x)
fnkr8t(hNdl)
fnkr8t(paste(hNdl,"Outputs",sep="/"))
#---DATA SECTION-----
source('C:/Matias/Analyses/Population dynamics/Git_Stock.assessments/Organise data.R')
#setwd("C:/Matias/Analyses/Data_outs")
#1. Total effort should be able to replace all this section with Organise data.R
# Effort.monthly=read.csv("Annual.total.eff.days.csv",stringsAsFactors=F)
# Effort.monthly.north=read.csv("Annual.total.eff_NSF.csv",stringsAsFactors=F)
#
# Effort.monthly_blocks=read.csv("Effort.monthly.csv",stringsAsFactors=F)
# Effort.daily_blocks=read.csv("Effort.daily.csv",stringsAsFactors=F)
# Effort.monthly.north_blocks=read.csv("Effort.monthly.NSF.csv",stringsAsFactors=F)
# Effort.daily.north_blocks=read.csv("Effort.daily.NSF.csv",stringsAsFactors=F)
#2. Commercial catch should be able to replace all this section with fn.import.catch.effort.data() from Organise data.R
fn.in=function(NM)
{
read.csv(paste('C:/Matias/Analyses/Data_outs/',NM,sep=""),stringsAsFactors = F)
}
#2.1 Catch_WA Fisheries
#Historic
Hist.expnd=fn.in(NM='recons_Hist.expnd.csv')
#Ammended reported catch including discards
Data.monthly=fn.in(NM='recons_Data.monthly.csv')
Data.monthly.north=fn.in(NM='recons_Data.monthly.north.csv')
#TEPS
Greynurse.ktch=fn.in(NM='recons_Greynurse.ktch.csv')
TEPS_dusky=fn.in(NM='recons_TEPS_dusky.csv')
#Droplines Western Rock Lobster
WRL.ktch=fn.in(NM='Wetline_rocklobster.csv')
#2.2. Catch of non WA Fisheries
#Taiwanese gillnet and longline
Taiwan.gillnet.ktch=fn.in(NM='recons_Taiwan.gillnet.ktch.csv')
Taiwan.longline.ktch=fn.in(NM='recons_Taiwan.longline.ktch.csv')
#Indonesian illegal fishing in Australia waters
Indo_total.annual.ktch=fn.in(NM='recons_Indo.IUU.csv')
#AFMA's GAB & SBT fisheries
GAB.trawl_catch=fn.in(NM='recons_GAB.trawl_catch.csv')
WTBF_catch=fn.in(NM='recons_WTBF_catch.csv')
#SA Marine Scalefish fishery
Whaler_SA=fn.in(NM='recons_Whaler_SA.csv')
#3. WA Recreational catch
Rec.ktch=fn.in(NM='recons_recreational.csv')
#4. Abundance data
WD='C:/Matias/Analyses/Data_outs'
fn.read=function(x) read.csv(paste(WD,x,sep='/'),stringsAsFactors = F)
#Naturalist abundance survey
Scal.hh.nat=fn.read('Scalloped hammerhead.Srvy.FixSt.csv')
Tiger.nat=fn.read('Tiger shark.Srvy.FixSt.csv')
Mil.nat=fn.read('Milk shark.Srvy.FixSt.csv')
#Standardised TDGDLF cpue
Smuz.hh.tdgdlf_mon=fn.read('Smooth hammerhead.annual.abundance.basecase.monthly_relative.csv')
Smuz.hh.tdgdlf_daily=fn.read('Smooth hammerhead.annual.abundance.basecase.daily_relative.csv')
Spinr.tdgdlf_mon=fn.read('Spinner Shark.annual.abundance.basecase.monthly_relative.csv')
Spinr.tdgdlf_daily=fn.read('Spinner Shark.annual.abundance.basecase.daily_relative.csv')
Tiger.tdgdlf_mon=fn.read('Tiger Shark.annual.abundance.basecase.monthly_relative.csv')
Tiger.tdgdlf_daily=fn.read('Tiger Shark.annual.abundance.basecase.daily_relative.csv')
Copper.tdgdlf_daily=fn.read('Bronze whaler.annual.abundance.basecase.daily_relative.csv')
#Standardised NSF cpue #not used, short time series and increasing with catch: not an abundance index
Lemon.NSF=fn.read('Lemon shark.annual.abundance.NSF_relative.csv')
Pigeye.NSF=fn.read('Pigeye shark.annual.abundance.NSF_relative.csv')
Tiger.NSF=fn.read('Tiger shark.annual.abundance.NSF_relative.csv')
#5. Mean catch weight data
#Standardised TDGDLF mean size
Smuz.hh.tdgdlf.mean.size=fn.read('Smooth hammerhead.annual.mean.size_relative.csv')
Spinr.tdgdlf.mean.size=fn.read('Spinner Shark.annual.mean.size_relative.csv')
Tiger.tdgdlf.mean.size=fn.read('Tiger Shark.annual.mean.size_relative.csv')
Copper.tdgdlf.mean.size=fn.read('Copper Shark.annual.mean.size_relative.csv')
Mn.weit.ktch=list("smooth hammerhead"=Smuz.hh.tdgdlf.mean.size,
"spinner shark"=Spinr.tdgdlf.mean.size,
"tiger shark"=Tiger.tdgdlf.mean.size,
"copper shark"=Copper.tdgdlf.mean.size)
for(m in 1:length(Mn.weit.ktch)) #keep used years
{
Mn.weit.ktch[[m]]=Mn.weit.ktch[[m]][1:match(Last.yr.ktch,Mn.weit.ktch[[m]]$Finyear),]
}
#6. Conventional tagging data
Tag=fn.read('Tagging_conventional.data.csv')
#7. Gillnet selectivity
All.sel.dat =list.files(WD,pattern="^gillnet.selectivity")
Sel.list <- lapply(All.sel.dat, read.csv)
names(Sel.list)= gsub(".*[_]([^.]+)[.].*", "\\1", All.sel.dat)
#Species codes
All.species.names=read.csv("C:/Matias/Data/Species_names_shark.only.csv",stringsAsFactors = F) #for catch
#b=read.csv("C:\\Matias\\Data\\Species.code.csv")
#Life history param for demography
LH.par=read.csv("C:/Matias/Data/Life history parameters/Life_History_other_sharks.csv",stringsAsFactors=F)
#PSA scores
PSA.list=read.csv('C:/Matias/Analyses/Population dynamics/PSA/PSA_scores_other.species.csv',stringsAsFactors=F)
#Temperature
#TEMP=read.csv("C:/Matias/Data/Oceanography/SST.csv")
#Species scientific names for assessed species
Shark.species=5001:24900
School.shark= 17008
Indicator.species=c(17001,17003,18003,18007)
Shar_other=22999
Scien.nm=All.species.names[,c('SPECIES','Scien.nm')]
#species list for exploring spatial dist of catch
SP.list=list(Angels=24900,Bignose=18012,BlacktipReef=18036,Blacktips=18014,
Blue=18004,Bull=18021,CommonSaw=23002,CreekWhaler=18035,Graceful=18033,
GreyNurse=8001,GreyReef=18030,Hammerheads=19000,Lemon=18029,Milk=18006,
Nervous=18034,OceanicWhitetip=18032,Pencil=17006,Pigeye=18026,Sawsharks=23900,
School=17008,SevenGill=5001,ShortfinMako=10001,Silky=18008,Silvertip=18027,
SixGill=5002,SouthernSawshark=23001,Spinner=18023,Spottail=18013,Spurdogs=20000,
TawnyNurse=13010,Threshers=12000,Tiger=18022,White=10003,Wobbegongs=13000)
non.sharks=c(
"Australian Salmon","Baldchin groper",
"Buffalo Bream", "Boxfish", "Blue Groper" ,
"Bonito","Boarfish (general)" ,"Dusky Morwong" ,"Flathead","Flounder (general)",
"John Dory (general)", "Knife Jaw" ,
"Leatherjacket (general)",
"Mackerels" , "Moonlighter", "Mulloway","North west blowfish" ,
"Parrotfish (general)","Pink snapper" , "Queen Snapper",
"Rankin cod","Red-lipped Morwong" , "Red Snapper, Redfish, Bight Redfish, Nannygai",
"Samson fish ","Southern Blue-fin Tuna","Sergeant Baker",
"Spotted sweetlips","Stripped marlin" ,"Spanish mackerel", "Skipjack trevally",
"WHALE",
"Unidentified","Yellow tailed kingfish", "Yellowfin tuna ","Gurnard Perch" )
non.commercial.sharks=c("Brown-banded catshark","Cobbler Wobbegong",
"Dwarf sawfish","Eagle ray","Fiddler ray","Freshwater sawfish",
"Green sawfish","Guitarfish & shovelnose ray","Narrow sawfish",
"Port Jackson","Spotted shovelnose","Stingrays","Tawny nurse shark",
"Whitespot shovelnose","Zebra shark")
#---PARAMETERS SECTION-----
Explor="NO"
Asses.Scalloped.HH=FALSE #2020 scalloped HH assessment
#Criteria for selecting species for quantitative analyses
Min.yrs=5
Min.ktch=5000 #in kg
#Reference points
B.threshold=0.5 #Bmys
Tar.prop=1.3 #target and limit proportions of Bmsy. source: Haddon et al 2014. Technical
Lim.prop=0.5 # Reviews of Formal Harvest Strategies.
B.target=Tar.prop*B.threshold
B.limit=Lim.prop*B.threshold
#Empirical reference points
Fmsy.emp=function(M) 0.41*M #Zhou et al 2012
SPR.thre=0.3 #Punt 2000 Extinction of marine renewable resources: a demographic analysis.
SPR.tar=0.4 # Population Ecology 42,
#Life history parameters for selected species
pup.sx.ratio=.5
Mn.conv.Fl.Tl=.85 #average convertion (over gummy, dusky, whiskery, sandbar) from FL to TL
#Gillnet selectivity from different nets
Estim.sel.exp='NO' #not enough observations from different mesh sizes
#Use conventional tagging data?
use.tags=F #too few recaptures...do not use
#... Surplus production arguments
#note: Only fitting species with species-specific abundance time series
# (e.g. wobbegongs comprise several species so not fitted)
# Assumption, negligible exploitation at start of time series
#Initial harvest rate
HR_o.sd=0.005 #SD of HR likelihood (fixed)
#Efficiency increase scenarios from 1995 on (done up to 1994 in cpue stand.)
Efficien.scens=c(0)
#Efficien.scens=c(.01)
#Proportional biomass (as proportion of K) at start of catch time series
B.init=1 #(fixed) Starting @ virgin level
#Estimate q
estim.q="NO" #use Haddon's q MLE calculation
#cpue likelihood
what.like='kernel'
#what.like='full'
#Initial estimated par value
Init.r=list("copper shark"=.05,"great hammerhead"=.1,
"grey nurse shark"=0.05,
"lemon shark"=.1,"milk shark"=.2,"pigeye shark"=0.1,"sawsharks"=.1,
"scalloped hammerhead"=.1,"smooth hammerhead"=.1,
"spinner shark"=.1,"shortfin mako"=.05,"spurdogs"=.05,
"tiger shark"=.1,"wobbegongs"=.1)
N.monte=1000
MAX.CV=0.5 #maximum acceptable CV for cpue series
#Define which optimisation method to use
#minimizer='nlminb'
minimizer='optim'
Remove.bounds=FALSE
usePen=TRUE
#K bounds
Low.bound.K=1 #times the maximum catch
Up.bound.K=100
#K init times max ktch
k.times.mx.ktch=mean(c(Low.bound.K,Up.bound.K))
#fix or estimate r
fix.r="NO"
r.weight=1 #weight given in the likelihood function
#what biomass percentiles to show
What.percentil="100%" #100% to make it comparable to CMSY
#What.percentil="60%" #60% as required for MSC
#... Catch-MSY arguments
#simulatins
SIMS=5e4
#Assumed process error
ERROR=0 #is default.
#depletion level at start of catch series
STARTBIO=c(B.init*.95,B.init) #low depletion because starting time series prior to any fishing
FINALBIO=c(.2,.9) #very uncertain
#... Demography
NsimSS=1000
r.prior="USER" #demography
r.prior2=NA #uniform
k.Linf.cor=-0.99 #assumed correlation between growth parameters
#... Scenarios
Modl.rn="standard" #for annual assessments
#Modl.rn='first' #for paper
if(Modl.rn=="first")
{
Nscen=2
SCENARIOS=vector('list',Nscen)
names(SCENARIOS)=c('BaseCase','WorstCase')
SCENARIOS$BaseCase=list(Error=ERROR,R.prior=r.prior,Initial.dep=STARTBIO)
SCENARIOS$WorstCase=list(Error=ERROR,R.prior=r.prior2,Initial.dep=STARTBIO)
}else
{
Nscen=1
SCENARIOS=vector('list',Nscen)
names(SCENARIOS)=c('BaseCase')
SCENARIOS$BaseCase=list(Error=ERROR,R.prior=r.prior,Initial.dep=STARTBIO)
}
#... Future projections
years.futures=5
#simulation test Catch-MSY for small and large catches
Do.sim.test="NO"
#... Control which assessment methods to implement
use.size.comp="YES" #is size catch comp used for anything?
do.mean.weight.based="NO" #not used due to logistic sel. assumption
do.length.based.SPR="NO" #not used due to logistic sel. assumption
Do.SPM="YES"
Do.Ktch.MSY="YES"
Do.aSPM="NO"
Min.len=25 #minimum length of sharks
Min.size.sample=50 #minimum number of observations (all years combined) to derive selectivities
Min.annual.size.samp=30 #minimum number of observations per year for LBSPR assessment
#---PROCEDURE SECTION-----
#Relevant catch years
Relevant.yrs=paste(seq(as.numeric(substr(min(Hist.expnd$FINYEAR),1,4)),
as.numeric(substr(Last.yr.ktch,1,4))),
substr(seq(as.numeric(substr(min(Hist.expnd$FINYEAR),1,4))+1,
as.numeric(substr(Last.yr.ktch,1,4))+1),3,4),sep='-')
#Select relevant effort vars
Effort.monthly_blocks=Effort.monthly_blocks%>%
filter(FINYEAR%in%Relevant.yrs)%>%
count(FINYEAR,BLOCKX)%>%
group_by(FINYEAR,BLOCKX)%>%
mutate(n=ifelse(n>0,1,0))
Effort.daily_blocks=Effort.daily_blocks%>%
rename(FINYEAR=finyear,
BLOCKX=blockx)%>%
filter(FINYEAR%in%Relevant.yrs)%>%
count(FINYEAR,BLOCKX)%>%
group_by(FINYEAR,BLOCKX)%>%
mutate(n=ifelse(n>0,1,0))
Effort_blocks=rbind(Effort.monthly_blocks,Effort.daily_blocks)%>%
count(FINYEAR,BLOCKX)%>%
group_by(FINYEAR,BLOCKX)%>%
mutate(n=ifelse(n>0,1,0))%>%
group_by(FINYEAR)%>%
summarise(Tot=sum(n))%>%
data.frame
#get GN equivalent of LL effort
do.GN.quiv='NO'
if(do.GN.quiv=="YES")
{
GN.ktch.north=Data.monthly.north%>%
filter(METHOD=="GN")%>%
group_by(FINYEAR,BLOCKX)%>%
summarise(Ktch.GN=sum(LIVEWT.c,na.rm=T))%>%
mutate(dummy=paste(FINYEAR,BLOCKX))
LL.effort.north=Effort.monthly.north_blocks%>%
filter(!METHOD=="GN")%>%
group_by(FINYEAR,BLOCKX)%>%
summarise(Effort=sum(hook.hours,na.rm=T))%>%
mutate(dummy=paste(FINYEAR,BLOCKX))%>%
dplyr::filter(dummy%in%GN.ktch.north$dummy)
LL.ktch.north=Data.monthly.north%>%
filter(!METHOD=="GN")%>%
group_by(FINYEAR,BLOCKX)%>%
summarise(Ktch.LL=sum(LIVEWT.c,na.rm=T))%>%
mutate(dummy=paste(FINYEAR,BLOCKX))%>%
dplyr::filter(dummy%in%LL.effort.north$dummy)
LL.cpue.north=left_join(LL.effort.north,LL.ktch.north,by=c('FINYEAR','BLOCKX'))%>%
mutate(cpue.LL=Ktch.LL/Effort)
GN.equiv.LL_effort.north=left_join(GN.ktch.north,LL.cpue.north,by=c('BLOCKX'))%>%
mutate(GN.equiv.eff=Ktch.GN/cpue.LL)
}
Effort.monthly.north_blocks=Effort.monthly.north_blocks%>%
filter(FINYEAR%in%Relevant.yrs)%>%
count(FINYEAR,BLOCKX)%>%
group_by(FINYEAR,BLOCKX)%>%
mutate(n=ifelse(n>0,1,0))
Effort.daily.north_blocks=Effort.daily.north_blocks%>%
rename(FINYEAR=finyear,
BLOCKX=blockx)%>%
filter(FINYEAR%in%Relevant.yrs)%>%
count(FINYEAR,BLOCKX)%>%
group_by(FINYEAR,BLOCKX)%>%
mutate(n=ifelse(n>0,1,0))
Effort.north_blocks=rbind(Effort.monthly.north_blocks,Effort.daily.north_blocks)%>%
count(FINYEAR,BLOCKX)%>%
group_by(FINYEAR,BLOCKX)%>%
mutate(n=ifelse(n>0,1,0))%>%
group_by(FINYEAR)%>%
summarise(Tot=sum(n))%>%
data.frame
Effort_blocks=rbind(Effort_blocks,Effort.north_blocks)%>%
group_by(FINYEAR)%>%
summarise(Tot=sum(Tot))%>%
data.frame
#Add Species names to catch data sets
All.species.names=All.species.names%>%
mutate(Name=tolower(Name))%>%
rename(SNAME=Name)
Hist.expnd=Hist.expnd%>%left_join(All.species.names,by='SPECIES')
Data.monthly=Data.monthly%>%left_join(All.species.names,by='SPECIES')
Data.monthly.north=Data.monthly.north%>%left_join(All.species.names,by='SPECIES')
Greynurse.ktch=Greynurse.ktch%>%left_join(All.species.names,by='SPECIES')
TEPS_dusky=TEPS_dusky%>%left_join(All.species.names,by='SPECIES')
WRL.ktch=WRL.ktch%>%left_join(All.species.names,by='SPECIES')
Taiwan.gillnet.ktch=Taiwan.gillnet.ktch%>%left_join(All.species.names,by='SPECIES')
Taiwan.longline.ktch=Taiwan.longline.ktch%>%left_join(All.species.names,by='SPECIES')
Indo_total.annual.ktch=Indo_total.annual.ktch%>%left_join(All.species.names,by='SPECIES')
GAB.trawl_catch=GAB.trawl_catch%>%left_join(All.species.names,by='SPECIES')
WTBF_catch=WTBF_catch%>%left_join(All.species.names,by='SPECIES')
Whaler_SA=Whaler_SA%>%left_join(All.species.names,by='SPECIES')
Average.Lat=rbind(subset(Data.monthly,select=c(SPECIES,LAT)),subset(Data.monthly.north,select=c(SPECIES,LAT)))
do.sp.table.WoE.paper="NO"
if(do.sp.table.WoE.paper=="YES")
{
a=subset(Data.monthly,SPECIES%in%Shark.species,select=c(SPECIES,SNAME,LIVEWT.c))
b=subset(Data.monthly.north,SPECIES%in%Shark.species,select=c(SPECIES,SNAME,LIVEWT.c))
d=rbind(a,b)
d=subset(d,!SPECIES==Shar_other)
Tab=aggregate(LIVEWT.c~SPECIES,d,sum)
Snm=d[!duplicated(d$SPECIES),-match('LIVEWT.c',names(d))]
Tab=merge(Tab,Snm,by="SPECIES")
Tab$prop=Tab$LIVEWT.c/sum(Tab$LIVEWT.c)
Tab=Tab[rev(order(Tab$prop)),]
Tab$CumSum=round(100*cumsum(Tab$prop),3)
write.csv(Tab[,c("SNAME","CumSum")],"C:\\Matias\\Scientific manuscripts\\Population dynamics\\Weight of evidence_main commercial sharks\\Table1.csv",row.names=F)
}
YEARS=sort(as.numeric(substr(unique(Data.monthly$FINYEAR),1,4)))
Current=YEARS[length(YEARS)]
#Explore spatial catch distribution to check species reporting issues
if(Explor=="YES")
{
fn.expl.sp.ktch=function(d1)
{
if(nrow(d1)>0)
{
aa=aggregate(LIVEWT.c~BLOCKX+LAT+LONG,d1,sum)
plot(aa$LONG,aa$LAT,pch=19,ylab="",ylim=c(-36,-9),xlim=c(111,129),
col="steelblue",xlab="",cex=((aa$LIVEWT.c/max(aa$LIVEWT.c))^0.5)*3)
}else
{
plot(1,axes=F,ann=F,col="white")
}
}
pdf(paste(hNdl,"/Outputs/reported.spatial.catch.pdf",sep=""))
for(l in 1:length(SP.list))
{
par(mfcol=c(2,1),mar=c(1.5,2.5,1,.5),las=1,mgp=c(1,.7,0))
fn.expl.sp.ktch(d1=subset(Data.monthly.north,SPECIES%in%SP.list[[l]]))
mtext(names(SP.list)[l],3)
fn.expl.sp.ktch(d1=subset(Data.monthly,SPECIES%in%SP.list[[l]]))
}
fn.prop.exp=function(d,nm)
{
d1=d%>%mutate(FINYEAR=as.numeric(substr(FINYEAR,1,4)))%>%
group_by(FINYEAR,BLOCKX)%>%
summarise(Sum=sum(LIVEWT.c))%>%
group_by(FINYEAR)%>%
mutate(Prop=Sum/sum(Sum))%>%
dplyr::select(FINYEAR,BLOCKX,Prop)%>%
spread(BLOCKX,Prop)%>%
data.frame
colnames(d1)[-1]= substr(colnames(d1)[-1],2,100)
CL=rainbow(ncol(d1)-1)
plot(d1$FINYEAR,d1[,2],type='b',ylim=c(0,1),col=CL[1],pch=19,ylab="Proportion",xlab="Year")
for(h in 3:ncol(d1)) points(jitter(d1$FINYEAR,1),d1[,h],type='b',col=CL[h-1],pch=19)
legend("bottomright",colnames(d1)[-1],bty='n',col=CL,lty=1,lwd=2,cex=.6)
mtext(nm,3)
}
these.ones.spt=c("Hammerheads","Spinner","Spurdogs","Tiger","Wobbegongs")
smart.par(n.plots=length(these.ones.spt),MAR=c(2,2,1,1),OMA=c(1.75,2,.5,.1),MGP=c(1,.5,0))
for(l in 1:length(these.ones.spt))
{
fn.prop.exp(d=subset(Data.monthly,SPECIES==SP.list[[match(these.ones.spt[l],
names(SP.list))]]),nm=these.ones.spt[l])
}
dev.off()
}
#1. Plot catch data as reported in logbooks
ThIs=subset(Shark.species,!Shark.species%in%c(Indicator.species))
Data.monthly$Region="South"
Data.monthly.north$Region="North"
Tot.ktch=rbind(subset(Data.monthly,SPECIES%in%ThIs,select=c(FishCubeCode,FINYEAR,LIVEWT.c,SPECIES,SNAME,Region)),
subset(Data.monthly.north,SPECIES%in%ThIs,select=c(FishCubeCode,FINYEAR,LIVEWT.c,SPECIES,SNAME,Region)))%>%
mutate(finyear=as.numeric(substr(FINYEAR,1,4)),
LIVEWT.c=LIVEWT.c/1000, #in tonnes
Name=ifelse(SPECIES%in%c(22999,31000),"unidentified sharks",SNAME))%>%
group_by(Name,FishCubeCode,finyear,Region)%>%
summarise(LIVEWT.c=sum(LIVEWT.c))
Agg.r=Tot.ktch%>%
group_by(Name,finyear,Region)%>%
summarise(LIVEWT.c=sum(LIVEWT.c))%>%
spread(finyear,LIVEWT.c)%>%
data.frame%>%
arrange(Name)
colnames(Agg.r)[3:ncol(Agg.r)]=substr(colnames(Agg.r)[3:ncol(Agg.r)],2,20)
PCH=rep(19,nrow(Agg.r))
COL=rep(1,nrow(Agg.r))
Sp.fig.1=unique(Agg.r$Name)
HnDL=paste(hNdl,"/Outputs/Catch_by.sector/",sep="")
fnkr8t(HnDL)
#Commercial
fn.fig(paste(HnDL,'commercial',sep=''),2400,2400)
smart.par(n.plots=length(Sp.fig.1),MAR=c(2,2,1,1),OMA=c(1.75,2,.5,.1),MGP=c(1,.5,0))
for(i in 1:length(Sp.fig.1))
{
d=subset(Agg.r,Name==Sp.fig.1[i])
d.N=subset(d,Region=="North")
d.S=subset(d,Region=="South")
plot(as.numeric(names(d)[3:length(d)]),d[1,3:length(d)],pch=PCH[i],
col='transparent',cex=.8,ann=F,ylim=c(0,max(d[,3:ncol(d)],na.rm=T)))
if(nrow(d.N)>0) points(as.numeric(names(d.N)[3:length(d.N)]),d.N[1,3:length(d.N)],pch=PCH[i],type='o',col="grey60",cex=.8)
if(nrow(d.S)>0) points(as.numeric(names(d.S)[3:length(d.S)]),d.S[1,3:length(d.S)],pch=PCH[i],type='o',col="grey25",cex=.8)
mtext(paste(Sp.fig.1[i]),3,line=0.2,cex=0.8)
}
plot(1:10,ann=F,axes=F,col='transparent')
legend('center',c("North","South"),lty=c(1,1),col=c("grey60","grey25"),lwd=2,bty='n',pch=19,cex=1.5)
mtext("Financial year",1,line=0.5,cex=1.5,outer=T)
mtext("Total catch (tonnes)",2,las=3,line=0.35,cex=1.5,outer=T)
dev.off()
#Recreational catch
Rec.ktch=Rec.ktch%>%mutate(Region=ifelse(zone%in%c('Gascoyne','North Coast'),'North','South'),
year=as.numeric(substr(FINYEAR,1,4)),
Common.Name=tolower(Common.Name))
Rec.sp=unique(Rec.ktch$Common.Name)
fn.fig(paste(HnDL,'recreational',sep=''),2400,2400)
smart.par(n.plots=length(Rec.sp)+1,MAR=c(2,2,1,1),OMA=c(1.75,2,.5,.1),MGP=c(1,.5,0))
for(i in 1:length(Rec.sp))
{
d=subset(Rec.ktch,Common.Name==Rec.sp[i])
d.N=d%>%
filter(Region=="North")%>%
group_by(year)%>%
summarise(LIVEWT.c=sum(LIVEWT.c/1000))
d.S=d%>%
filter(Region=="South")%>%
group_by(year)%>%
summarise(LIVEWT.c=sum(LIVEWT.c/1000))
plot(sort(unique(d$year)),sort(unique(d$year)),col='transparent',cex=.8,ann=F,ylim=c(0,max(c(d.N$LIVEWT.c,d.S$LIVEWT.c,na.rm=T))))
if(nrow(d.N)>0) points(d.N$year,d.N$LIVEWT.c,pch=PCH[i],type='o',col="grey60",cex=.8)
if(nrow(d.S)>0) points(d.S$year,d.S$LIVEWT.c,pch=PCH[i],type='o',col="grey25",cex=.8)
mtext(paste(Rec.sp[i]),3,line=0.2,cex=0.8)
}
plot(1:10,ann=F,axes=F,col='transparent')
legend('center',c("North","South"),lty=c(1,1),col=c("grey60","grey25"),lwd=2,bty='n',pch=19,cex=1.5)
mtext("Financial year",1,line=0.5,cex=1.5,outer=T)
mtext("Total catch (tonnes)",2,las=3,line=0.35,cex=1.5,outer=T)
dev.off()
#Taiwanese catch
Taiwan.gillnet.ktch$Method="Pelagic.gillnet"
Taiwan.longline.ktch$Method="Longline"
Taiwan=rbind(Taiwan.longline.ktch,Taiwan.gillnet.ktch)%>%
mutate(Region="North",
LIVEWT.c=LIVEWT.c/1000)%>%
mutate(year=as.numeric(substr(FINYEAR,1,4)))%>%
arrange(SNAME,year)
sp.taiwan=unique(Taiwan$SNAME)
sp.taiwan=sp.taiwan[!is.na(sp.taiwan)]
fn.fig(paste(HnDL,'taiwan',sep=''),2400,2400)
smart.par(n.plots=length(sp.taiwan),MAR=c(2,2,1,1),OMA=c(1.75,2,.5,.1),MGP=c(1,.5,0))
for(i in 1:length(sp.taiwan))
{
d=subset(Taiwan,SNAME==sp.taiwan[i])
d.N=d%>%
filter(Region=="North")%>%
group_by(year)%>%
summarise(LIVEWT.c=sum(LIVEWT.c))
d.S=d%>%
filter(Region=="South")%>%
group_by(year)%>%
summarise(LIVEWT.c=sum(LIVEWT.c))
plot(sort(unique(Taiwan$year)),sort(unique(Taiwan$year)),col='transparent',cex=.8,ann=F,ylim=c(0,max(c(d.N$LIVEWT.c,d.S$LIVEWT.c,na.rm=T))))
if(nrow(d.N)>0) points(d.N$year,d.N$LIVEWT.c,pch=PCH[i],type='o',col="grey60",cex=.8)
if(nrow(d.S)>0) points(d.S$year,d.S$LIVEWT.c,pch=PCH[i],type='o',col="grey25",cex=.8)
mtext(paste(sp.taiwan[i]),3,line=0.2,cex=0.8)
}
legend('center',c("North","South"),lty=c(1,1),col=c("grey60","grey25"),lwd=2,bty='n',pch=19,cex=1.5)
mtext("Calendar year",1,line=0.5,cex=1.5,outer=T)
mtext("Total catch (tonnes)",2,las=3,line=0.35,cex=1.5,outer=T)
dev.off()
#Indonesian fishing incursions catch
Indo_total.annual.ktch=Indo_total.annual.ktch%>%filter(!is.na(SPECIES))
sp.indo=unique(Indo_total.annual.ktch$SNAME)
fn.fig(paste(HnDL,'indo',sep=''),2400,2400)
smart.par(n.plots=length(sp.indo),MAR=c(2,2,1,1),OMA=c(1.75,2,.5,.1),MGP=c(1,.5,0))
for(i in 1:length(sp.indo))
{
d=subset(Indo_total.annual.ktch,SNAME==sp.indo[i])%>%
mutate(LIVEWT.c=LIVEWT.c/1000, #in tonnes
year=as.numeric(substr(FINYEAR,1,4)))%>%
arrange(year)
plot(d$year,d$LIVEWT.c,col="grey60",cex=.8,type='o',pch=PCH[i],ann=F,ylim=c(0,max(d$LIVEWT.c,na.rm=T)))
mtext(paste(sp.indo[i]),3,line=0.2,cex=0.8)
}
legend('center',c("North","South"),lty=c(1,1),col=c("grey60","grey25"),lwd=2,bty='n',pch=19,cex=1.5)
mtext("Calendar year",1,line=0.5,cex=1.5,outer=T)
mtext("Total catch (tonnes)",2,las=3,line=0.35,cex=1.5,outer=T)
dev.off()
#2. Remove species assessed elsewhere
#2.1 remove indicator species and 'shark, other' (after catch reapportion)
Shark.species=subset(Shark.species,!Shark.species%in%c(Indicator.species,Shar_other,31000))
#2.2 Remove blacktip sharks (blacktips and spot-tail) and school sharks (as per SAFS)
#note:
# . blacktips is a shared-stock with NT so NT assessment is used given their much higher catches (Grubert et al 2013)
# . school sharks are assumed to be a shared stock in the SESSF assessment (Thomson & Punt 2009)
blacktips=subset(Scien.nm,Scien.nm%in%c('C. limbatus & C. tilstoni','Carcharhinus sorrah'))$SPECIES
Shark.species=subset(Shark.species,!Shark.species%in%c(blacktips,School.shark))
Data.monthly=subset(Data.monthly,SPECIES%in%Shark.species,select=c(SPECIES,FishCubeCode,SNAME,FINYEAR,LIVEWT.c,BLOCKX,METHOD))
Data.monthly.north=subset(Data.monthly.north,SPECIES%in%Shark.species,select=c(SPECIES,FishCubeCode,SNAME,FINYEAR,LIVEWT.c,BLOCKX,METHOD))
Data.monthly$Region="South"
Data.monthly.north$Region="North"
#3. Combine north and south
Tot.ktch=rbind(Data.monthly,Data.monthly.north)
#4. Some manipulations
SNAMEs=Data.monthly[!duplicated(Data.monthly$SPECIES),match(c("SPECIES","SNAME"),names(Data.monthly))]
SNAMEs.north=Data.monthly.north[!duplicated(Data.monthly.north$SPECIES),match(c("SPECIES","SNAME"),names(Data.monthly.north))]
#combine sawsharks as reported by species and as 'sawsharks'
Tot.ktch=Tot.ktch%>%
mutate(finyear=as.numeric(substr(FINYEAR,1,4)),
SPECIES=ifelse(SPECIES%in%c(23002,23001,23900),23900,SPECIES),
SNAME=ifelse(SNAME%in%c("southern sawshark","common sawshark","sawsharks"),"sawsharks",SNAME),
Name=SNAME)
#5. Add recreational catch
Rec.ktch=Rec.ktch%>%
rename(finyear=year)%>%
mutate(BLOCKX=NA,
Common.Name=ifelse(Common.Name=="dogfishes","spurdogs",
ifelse(Common.Name=="greynurse shark","grey nurse shark",
ifelse(Common.Name=="thresher shark","thresher sharks",
ifelse(Common.Name=="bronze whaler","copper shark",
Common.Name)))))%>%
filter(Common.Name%in%unique(Tot.ktch$SNAME))%>%
left_join(All.species.names%>%dplyr::select(-Scien.nm),by=c('Common.Name'='SNAME'))%>%
mutate(SNAME=Common.Name,
Name=Common.Name,
METHOD='Rec.line',
FishCubeCode="Recreational")%>%
dplyr::select(names(Tot.ktch))
Rec.ktch$Type="Recreational"
Tot.ktch$Type="Commercial"
Tot.ktch=rbind(Tot.ktch,Rec.ktch)
#6. Add Taiwanese catch
Taiwan=Taiwan%>%
rename(finyear=year)%>%
mutate(BLOCKX=NA,
Name=SNAME,
Type="Taiwan",
METHOD=Method,
LIVEWT.c=LIVEWT.c*1000, #back in kg to match other fisheries
FishCubeCode="Taiwan")%>%
dplyr::select(names(Tot.ktch))%>%
filter(SPECIES%in%unique(Tot.ktch$SPECIES))
Tot.ktch=rbind(Tot.ktch,Taiwan)
#7. Add Indonesian fishing incursions
Indo=Indo_total.annual.ktch%>%
mutate(BLOCKX=NA,
Region="North",
finyear=as.numeric(substr(FINYEAR,1,4)),
Name=SNAME,
Type="Indonesia",
METHOD=NA,
FishCubeCode="Indo")%>%
dplyr::select(names(Tot.ktch))%>%
filter(SPECIES%in%unique(Tot.ktch$SPECIES))
Tot.ktch=rbind(Tot.ktch,Indo)
#Keep relevant years
Tot.ktch=Tot.ktch%>%
filter(FINYEAR%in%Relevant.yrs)
#8. Display Catch for each Species (in tonnes)
Plot.yrs=sort(unique(Tot.ktch$finyear))
fn.add=function(D)
{
id=Plot.yrs[which(!Plot.yrs%in%D$finyear)]
if(length(id)>0)
{
A=as.data.frame(matrix(nrow=length(id),ncol=ncol(D)))
colnames(A)=colnames(D)
A$finyear=id
D=rbind(D,A)
D=D[order(D$finyear),]
}
return(D)
}
Pt.ktch.sp=function(sp,SP,LWD)
{
d=subset(Tot.ktch,SPECIES%in%sp)
b.Tot=aggregate(LIVEWT.c/1000~finyear,d,sum)
uno=nrow(b.Tot)
b.Tot=fn.add(D=b.Tot)
if(uno>2)plot(1:length(b.Tot$finyear),b.Tot$"LIVEWT.c",type='l',lwd=LWD,ylab="",xlab="",xaxt='n',
ylim=c(0,max(b.Tot$"LIVEWT.c",na.rm=T)),cex.axis=1.25)
if(uno<=2)plot(1:length(b.Tot$finyear),b.Tot$"LIVEWT.c",pch=19,cex=2,ylab="",xlab="",xaxt='n',
ylim=c(0,max(b.Tot$"LIVEWT.c",na.rm=T)),cex.axis=1.25)
d1=subset(d,Region=="North")
if(nrow(d1)>0)
{
b.N=aggregate(LIVEWT.c/1000~finyear,d1,sum)
uno=nrow(b.N)
b.N=fn.add(D=b.N)
if(uno>2)lines(1:length(b.N$finyear),b.N$"LIVEWT.c",col="red",lwd=LWD)
if(uno<=2)points(1:length(b.N$finyear),b.N$"LIVEWT.c",pch=19,cex=2,col="red")
}
d1=subset(d,Region=="South")
if(nrow(d1)>0)
{
b.S=aggregate(LIVEWT.c/1000~finyear,d1,sum)
uno=nrow(b.S)
b.S=fn.add(D=b.S)
if(uno>2)lines(1:length(b.S$finyear),b.S$"LIVEWT.c",col="forestgreen",lty=4,lwd=LWD)
if(uno<=2)points(1:length(b.S$finyear),b.S$"LIVEWT.c",pch=19,cex=2,col="forestgreen")
}
mtext(SP,3,0,cex=1.5)
legend("topleft",c("Total",expression(paste("North of 26 ",degree,"S")),
expression(paste("South of 26 ",degree,"S"))),bty='n',lty=c(1,1,4),
lwd=LWD,col=c("black","red","forestgreen"),cex=1.5,pt.lwd=4)
mtext("Catch (tonnes)",2,3,cex=2,las=3)
mtext("Financial year",1,2.5,cex=2)
axis(1,1:length(b.Tot$finyear),F,tck=-0.0125)
axis(1,seq(1,length(b.Tot$finyear),10),Plot.yrs[seq(1,length(b.Tot$finyear),10)],cex.axis=1.25,tck=-0.025)
}
test=Tot.ktch[!duplicated(Tot.ktch$SPECIES),]
Uni.sp=test$SPECIES
names(Uni.sp)=test$Name
HnDl=paste(hNdl,"/Outputs/Catch_all_sp/",sep="")
fnkr8t(HnDl)
for(i in 1:length(Uni.sp))
{
fn.fig(paste(HnDl,names(Uni.sp)[i],sep=""),2400,2400)
par(las=1,mgp=c(1,.8,0),mai=c(.8,1,.3,.1))
Pt.ktch.sp(sp=Uni.sp[i],SP=names(Uni.sp)[i],LWD=3)
dev.off()
}
#9. add TEP interactions
Greynurse.ktch=Greynurse.ktch%>%
mutate(BLOCKX=NA,
Region="South",
finyear=as.numeric(substr(FINYEAR,1,4)),
Name=SNAME,
Type="TEP",
METHOD='GN',
FishCubeCode="TEP")%>%
dplyr::select(names(Tot.ktch))
Tot.ktch=rbind(Tot.ktch,Greynurse.ktch)
#10. add WRL
WRL.ktch=WRL.ktch%>%
mutate(BLOCKX=NA,
Region="South",
finyear=as.numeric(substr(FINYEAR,1,4)),
Name=SNAME,
Type="WRL",
METHOD='LL',
FishCubeCode="WRL")%>%
dplyr::select(names(Tot.ktch))
Tot.ktch=rbind(Tot.ktch,WRL.ktch)
#11. Add historic
a=Hist.expnd%>%
mutate(BLOCKX=NA,
Region="South",
finyear=as.numeric(substr(FINYEAR,1,4)),
Type="Commercial",
METHOD=NA,
FishCubeCode="Historic",
SNAME=ifelse(SNAME%in%c('southern sawshark','common sawshark'),'sawsharks',SNAME),
SPECIES=ifelse(SPECIES%in%c(23001,23002),23900,SPECIES),
Name=SNAME)%>%
dplyr::select(names(Tot.ktch))%>%
filter(SPECIES%in%unique(Tot.ktch$SPECIES))
Tot.ktch=rbind(Tot.ktch,a)
#12. Add GAB
GAB=GAB.trawl_catch%>%
mutate(BLOCKX=NA,
Region="South",
finyear=as.numeric(substr(FINYEAR,1,4)),
Name=SNAME,
Type="GAB",
METHOD="trawl",
FishCubeCode="GAB")%>%
dplyr::select(names(Tot.ktch))%>%
filter(SPECIES%in%unique(Tot.ktch$SPECIES))
Tot.ktch=rbind(Tot.ktch,GAB)
#13. Add WTBF
WTB=WTBF_catch%>%
mutate(BLOCKX=NA,
Region="South",
finyear=as.numeric(substr(FINYEAR,1,4)),
Name=SNAME,
Type="WTB",
METHOD="line",
FishCubeCode="WTB")%>%
dplyr::select(names(Tot.ktch))%>%
filter(SPECIES%in%unique(Tot.ktch$SPECIES))
Tot.ktch=rbind(Tot.ktch,WTB)
#14. Add Whaler_SA (SA Marine Scalefish Fishery)
Whaler_SA=Whaler_SA%>%
mutate(BLOCKX=NA,
Region="South",
finyear=as.numeric(substr(FINYEAR,1,4)),
Name=SNAME,
Type="SA MSF",
METHOD="line",
FishCubeCode="SA MSF")%>%
dplyr::select(names(Tot.ktch))%>%
filter(SPECIES%in%unique(Tot.ktch$SPECIES))
Tot.ktch=rbind(Tot.ktch,Whaler_SA)
#15. Remove blacktips & school shark because they are not assessed here. Ditto white sharks
Tot.ktch=subset(Tot.ktch,!Name%in%c('Blacktips','blacktips','spot tail shark',
'Spot tail shark',"spot-tail shark","School shark",
"white shark","dusky shark"))
#16. Change bull to pigeye shark as bull not likely to be taken (Heupel & McAuley 2007 page 84)
Tot.ktch=Tot.ktch%>%
mutate(SPECIES=ifelse(SPECIES==18021,18026,SPECIES),
SNAME=ifelse(SNAME=='bull shark','pigeye shark',SNAME),
Name=ifelse(Name=='bull shark','pigeye shark',Name))
#17. Select species with enough data
Agg=Tot.ktch%>%
mutate(Gear=ifelse(METHOD%in%c("BS","BH","GN","HN","Pelagic.gillnet"),"net",
ifelse(METHOD%in%c("DL","DV","EL","GL","HL","HR","HY",
"LL","Longline","Rec.line","TL"),'line',
ifelse(METHOD%in%c("FG","TW"),'trawl',
ifelse(METHOD%in%c("FT","PT"),'trap',
NA)))))
#replace missing gear info with most common value
Mode <- function(x)
{
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
Agg=Agg%>%
group_by(FishCubeCode) %>%
arrange(FishCubeCode, is.na(Gear)) %>% # in case to keep non- NA elements for a tie
mutate(Gear = ifelse(is.na(Gear),Mode(Gear),Gear),
Gear=ifelse(is.na(Gear) & FishCubeCode %in% c('Historic','Indo','WTB','SA MSF'),'line',
ifelse(is.na(Gear) & FishCubeCode %in% c('GAB','PFT','SBSC'),'trawl',
Gear)))
Agg.r=Agg%>%
group_by(Name,FINYEAR)%>%
summarise(LIVEWT.c=sum(LIVEWT.c,na.rm=T))%>%
spread(FINYEAR,LIVEWT.c,fill=0)%>%
data.frame
names(Agg.r)[-1]=substr(names(Agg.r)[-1],2,5)
PCH=rep(19,length(unique(Agg.r$Name)))
COL=rep(1,length(unique(Agg.r$Name)))
id=rowSums(Agg.r[,2:ncol(Agg.r)],na.rm=T)
names(id)=Agg.r$Name
id=rev(sort(id))
Agg.r=Agg.r[match(names(id),Agg.r$Name),]
#---PSA to determine which species to assess ------------------------------------------------------
#note: PSA aggregating the susceptibilities of multiple fleets (Micheli et al 2014)
Agg.PSA=Agg%>%
filter(!is.na(Gear))%>%
group_by(Name,Gear,FINYEAR)%>%
summarise(LIVEWT.c=sum(LIVEWT.c,na.rm=T))%>%
spread(FINYEAR,LIVEWT.c,fill=0)%>%
data.frame
names(Agg.PSA)[-(1:2)]=substr(names(Agg.PSA)[-(1:2)],2,5)
Agg.sp=unique(Agg.PSA$Name)
KIP=vector('list',length(Agg.sp))
for(s in 1:length(Agg.sp))
{
d=Agg.PSA%>%filter(Name==Agg.sp[s])
d1=d[,-c(1:2)]
d1[d1<Min.ktch]=0
d1[d1>=Min.ktch]=1
kip=data.frame(Gear=d$Gear)%>%
mutate(