forked from laurieKell/aspic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.Rhistory
512 lines (512 loc) · 22.5 KB
/
.Rhistory
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
iter=iterators:::iter
albMSY <- aspics(foreach(i=names(albs[c(1,3)]), .combine=list,
.multicombine=T,.maxcombine=4,.packages=c("aspic","FLCore")) %dopar% {
wkdir=tempfile('file', tempdir())
dir.create(wkdir, showWarnings = FALSE)
fit(albMSY[[i]],dir=wkdir)})
names(albMSY)=c("run2","run7")
names(albMSY)=c("run2","run7")
save(albMSY,file="/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/albs-ll-comp/data/albMSY.RData")
model.frame(params(albMSY))
llc=transform(ldply(albMSY, function(x) as.data.frame(x@ll)),
Series=factor(nms[as.numeric(params)],labels=nms,levels=lvl),
run =.id)[,-1]
msy=ldply(albMSY, function(x) model.frame(params(x)["msy"]))
names(msy)[1]="run"
llc=merge(llc,msy)
llc=merge(llc,wts)
llc=transform(llc,data.=data*wt)
ggplot(data=llc, aes(msy,data.,col=run,group=run))+
# geom_rect(data=data.frame(Series=nms,data.=NA,run="run2",msy=NA),
# aes(fill=Series), xmin =-Inf, xmax=Inf,
# ymin =-Inf, ymax=Inf,
# alpha=0.3) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[1]])),col="pink",size=1.2) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[3]])),col="cyan",size=1.2) +
geom_point() +
stat_smooth(se=F,span=.2) +
facet_wrap(~Series,scale="free_y") +
# scale_fill_manual(values
# =c("Taiwan LL" ="yellow",
# "Japan LL I" ="yellow",
# "Japan LL II" ="yellow",
# "Japan LL III" ="yellow",
# "Brazil LL" ="yellow",
# "South Africa BB I" ="green",
# "South Africa BB II"="green",
# "Uruguay LL" ="yellow"))+
theme_ms(legend.position="none") + xlab("MSY") + ylab("Log Likelihood")
ggplot(data=llc, aes(msy,data.,col=run,group=run))+
# geom_rect(data=data.frame(Series=nms,data.=NA,run="run2",msy=NA),
# aes(fill=Series), xmin =-Inf, xmax=Inf,
# ymin =-Inf, ymax=Inf,
# alpha=0.3) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[1]])),col="pink",size=1.2) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[3]])),col="cyan",size=1.2) +
geom_point() +
stat_smooth(se=F,span=.3) +
facet_wrap(~Series,scale="free_y") +
# scale_fill_manual(values
# =c("Taiwan LL" ="yellow",
# "Japan LL I" ="yellow",
# "Japan LL II" ="yellow",
# "Japan LL III" ="yellow",
# "Brazil LL" ="yellow",
# "South Africa BB I" ="green",
# "South Africa BB II"="green",
# "Uruguay LL" ="yellow"))+
theme_ms(legend.position="none") + xlab("MSY") + ylab("Log Likelihood")
ggplot(data=llc, aes(msy,data.,col=run,group=run))+
# geom_rect(data=data.frame(Series=nms,data.=NA,run="run2",msy=NA),
# aes(fill=Series), xmin =-Inf, xmax=Inf,
# ymin =-Inf, ymax=Inf,
# alpha=0.3) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[1]])),col="pink",size=1.2) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[3]])),col="cyan",size=1.2) +
geom_point() +
stat_smooth(se=F,span=.25) +
facet_wrap(~Series,scale="free_y") +
# scale_fill_manual(values
# =c("Taiwan LL" ="yellow",
# "Japan LL I" ="yellow",
# "Japan LL II" ="yellow",
# "Japan LL III" ="yellow",
# "Brazil LL" ="yellow",
# "South Africa BB I" ="green",
# "South Africa BB II"="green",
# "Uruguay LL" ="yellow"))+
theme_ms(legend.position="none") + xlab("MSY") + ylab("Log Likelihood")
library(ggplot2)
par =read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/mn_sd.csv")
cas2009=read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/caaALBN7507tot_v1_db.csv")
ggplot(par)+geom_line(aes(age,mean,group=qtr,col=factor(qtr)))
?geom_errorbar
head(par)
p=ggplot(par)+geom_line(aes(age,mean,group=qtr,col=factor(qtr)))
limits=aes(ymax=mean+2*sigma, ymin=mean - 2*sigma)
p + geom_bar(position="dodge", stat="identity")
p=ggplot(aes(age,mean,group=qtr,col=factor(qtr),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean - 2*sigma)
p + geom_bar(position="dodge", stat="identity")
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean - 2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean - 2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean - 2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr),data=par)+geom_line()
)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean-2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean-2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.25)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean-2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)
head(cas2009)
source('~/Desktop/ICCAT/SCRS/2013/ALB/ALK/R/alk.R', echo=TRUE)
print(ggplot(cas2009) +
geom_histogram(aes(Age,weight=Pa),colour = "darkgreen", fill = "grey", binwidth=binwidth)
)
ggplot(cas2009) +
geom_histogram(aes(Age,weight=Pa),colour = "darkgreen", fill = "grey", binwidth=binwidth)
ggplot(cas2009) +
geom_histogram(aes(Age,weight=Pa),colour = "darkgreen", fill = "grey")
source('~/Desktop/gcode/wcsam-alb/R/ageThem.R', echo=TRUE)
ggplot(data=llc, aes(msy,data.,col=run,group=run))+
# geom_rect(data=data.frame(Series=nms,data.=NA,run="run2",msy=NA),
# aes(fill=Series), xmin =-Inf, xmax=Inf,
# ymin =-Inf, ymax=Inf,
# alpha=0.3) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[1]])),col="pink",size=1.2) +
geom_vline(aes(xintercept=data),data=as.data.frame(msy(albs[[3]])),col="cyan",size=1.2) +
geom_point() +
stat_smooth(se=F,span=.25) +
facet_wrap(~Series,scale="free_y") +
# scale_fill_manual(values
# =c("Taiwan LL" ="yellow",
# "Japan LL I" ="yellow",
# "Japan LL II" ="yellow",
# "Japan LL III" ="yellow",
# "Brazil LL" ="yellow",
# "South Africa BB I" ="green",
# "South Africa BB II"="green",
# "Uruguay LL" ="yellow"))+
theme_ms(legend.position="none") + xlab("MSY") + ylab("Log Likelihood")
cf=subset(merge(as.data.frame(params(albMSY[[1]])),model.frame(params(albMSY[[2]]))[,c("msy","iter")]),!(params %in% c("b0","msy")))
ggplot(aes(msy,data),data=cf)+
geom_point()+
geom_smooth(span=.1)+
facet_wrap(~params,scale="free")
ggplot(merge(ddply(llc,.(run,iter), with, mean(data.)),msy))+
geom_line(aes(msy,V1,group=run,col=run))+
theme_ms()+xlab("MSY")+ylab("Log Likelihood")
albs =fit(albs)
par=read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/mn_sd.csv")
cas=read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN2009.csv")
head(cas)
table(cas$StockID)
cas$len <-cas$Li1CM+0.5
cas$yr <-cas$YearC %% 10
cas$decade<-cas$YearC-cas$yr
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade)
library(ggplotFL) #plotting library
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade)
p
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_x_continuous(breaks=2000000)
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
p
cas$decade<-paste(cas$YearC-cas$yr-1900,"´s",sep="")
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
p
cas$decade<-factor(paste(cas$YearC-cas$yr-1900,"´s",sep=""),levels=c("70´s","80´s","90´s","100´s")
)
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
p
vonBert=function(age,Linf, K, t0) Linf*(1.0-exp(-K*(age-t0)))
ageIt=function(len=NULL,n=NULL,Linf=NULL,K=NULL,t0=0.0,timing=0.5,plusGroup=30){
## expected age at length adjust to beginning of year
age=pmax(pmin(floor(t0-log(1-pmin(len/Linf,.9999999))/K+timing),plusGroup),0)
## calculate frequencies
res=aggregate(n, list(age=age), sum)
return(res)}
cas2caa<-function(x,grwPar,constr,ages){
## aggregate frequencies by bins
tst =with(x,aggregate(n,list(len=len),sum))
lnDist=mix(tst,grwPar,"norm",constr=constr,emsteps=3,print.level=1)
plot(lnDist,xlim=c(50,250))
abline(v=vonBert(ages,vB["Linf"],vB["K"],vB["t0"]),col="green",lty=5)
mtext(unique(x$year))
return(data.frame(age=ages,lnDist$parameters))}
caa=ddply(cas, .(year), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
caa=ddply(cas, .(Yearc), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
head(cas)
caa=ddply(cas, .(YearC), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
vB =c(Linf=238.6,K=0.185,t0=-1.404)
caa=ddply(cas, .(YearC), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
plusGroup=10
caa=ddply(cas, .(YearC), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
names(cas)
names(cas)
names(cas)[10]
names(cas)[10]="n"
names(cas)[10]="n"
caa=ddply(cas, .(YearC), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
names(caa)[3]="data"
caaSlice =as.FLQuant(caa)
head(caa)
names(cas)
names(cas)[c(2,10)]=c("year","n")
caa=ddply(cas, .(year), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
names(caa)[3]="data"
caaSlice =as.FLQuant(caa)
## constraints
constr<-mixconstr(conmu ="MFX", fixmu=c(rep(FALSE,3),rep(TRUE,8)), consigma ="CCV")
library(mixdis)
library(mixdist)
constr<-mixconstr(conmu ="MFX", fixmu=c(rep(FALSE,3),rep(TRUE,8)), consigma ="CCV")
ages<-0:10
grwPar=mixparam(pi =c(apply(sweep(caaSlice,2,apply(caaSlice,2,sum),"/"),1,mean)),
mu =vonBert(ages+0.5,vB["Linf"],vB["K"],vB["t0"]),
sigma =0.05) #ageCV)
grwPar$sigma=grwPar$sigma*grwPar$mu
grwPar
par(mfrow=c(5,5), mar=c(1,1,1,1))
ageThem =ddply(cas,.(year),cas2caa,grwPar=grwPar,constr=constr,ages=ages)
## process so you get an FLQuant
caaStat =merge(ageThem,with(cas,aggregate(n,by=list(year=year),sum)))
caaStat$data=caaStat$x*caaStat$pi
caaStat =as.FLQuant(caaStat[,c("age","year","data")])
ageThem =ddply(cas,.(year),cas2caa,grwPar=grwPar,constr=constr,ages=ages)
?readSS
library(R4MFCL)
?read.frq
read.frq
cas=read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
head(cas)
source('~/Desktop/flr/git/diags/R/ICCAT.io.R', echo=TRUE)
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
library(FLCore)
source('~/Desktop/flr/git/diags/R/ICCAT.io.R', echo=TRUE)
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
head(cas)
x="/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv"
require(LaF)
require(reshape)
nms=names(read.csv(x,nrows=1))
fld=nms[1:18]
ln =nms[-(1:18)]
fld
ln
x
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean-2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
library(FLCore) #FLR
library(FLAdvice) #Biological Reference Points
library(mixdist) #used for fitting mixture distributions
library(ggplotFL) #plotting library
library(ALKr) #Age Length Keys
library(mixdist)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean-2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
par=read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/mn_sd.csv")
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
p=ggplot(aes(x=age,y=mean,group=qtr,col=factor(qtr)),data=par)+geom_line()
limits=aes(ymax=mean+2*sigma, ymin=mean-2*sigma)
dodge =position_dodge(width=0.9)
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)+
theme_mx(legend.position="bottom")
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)+
theme_ms(legend.position="bottom")
p + geom_bar(position="dodge", stat="identity")
p + geom_errorbar(limits, position=dodge, width=0.1)+
theme_ms(legend.position="bottom")
ggplot(cas) +
geom_histogram(aes(Age,weight=Pa), colour = "darkgreen", fill = "grey") +
geom_line(data=modes, aes(len,freq,group=i), colour="red", size=1.25)+
geom_line(data=fit, aes(len,x), colour="green", size=2))}
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
head(cas)
ggplot(cas) +
geom_histogram(aes(Age,weight=Pa), colour = "darkgreen", fill = "grey") +
geom_line(data=modes, aes(len,freq,group=i), colour="red", size=1.25)+
geom_line(data=fit, aes(len,x), colour="green", size=2))}
head(cas)
ggplot(cas) +
geom_histogram(aes(len,weight=n), colour = "darkgreen", fill = "grey") +
geom_line(data=modes, aes(len,freq,group=i), colour="red", size=1.25)+
geom_line(data=fit, aes(len,x), colour="green", size=2))}
ggplot(cas) +
geom_histogram(aes(len,weight=n), colour = "darkgreen", fill = "grey")
ggplot(cas) +
geom_histogram(aes(len,weight=n), colour = "darkgreen", fill = "grey") +
geom_line(data=modes, aes(len,freq,group=i), colour="red", size=1.25)
cas$len <-cas$len+0.5
names(cas)[c(2,10)]=c("year","n")
## Plot CAS by decade
cas$yr <-cas$year %% 10
cas$decade<-factor(paste(cas$year-cas$yr-1900,"´s",sep=""),levels=c("70´s","80´s","90´s","100´s")
p=ggplot(cas) +
geom_histogram(aes(len,weight=Num),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
p
cas$len <-cas$len+0.5
names(cas)[c(2,10)]=c("year","n")
## Plot CAS by decade
cas$yr <-cas$year %% 10
cas$decade<-factor(paste(cas$year-cas$yr-1900,"´s",sep=""),levels=c("70´s","80´s","90´s","100´s")
p=ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
p=ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5)
p
head(cas)
cas$len <-cas$len+0.5
names(cas)[c(2,10)]=c("year","n")
## Plot CAS by decade
cas$yr <-cas$YearC %% 10
cas$decade<-factor(paste(cas$year-cas$yr-1900,"´s",sep=""),levels=c("70´s","80´s","90´s","100´s")
)
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
cas$len <-cas$len+0.5
cas$yr <-cas$YearC %% 10
cas$decade<-factor(paste(cas$year-cas$yr-1900,"´s",sep=""),levels=c("70´s","80´s","90´s","100´s")
)
p=ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency")
head(cas)
cas$decade<-factor(paste(cas$YearC-cas$yr-1900,"´s",sep=""),levels=c("70´s","80´s","90´s","100´s"))
p=ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency")
head(cas)
ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade)
ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") + scale_y_continuous(name ="Frequency") +
facet_grid(yr~decade) + scale_y_continuous(breaks=2000000)
ggplot(cas) +
geom_histogram(aes(len,weight=n),colour="darkgreen",fill="white",binwidth=5) +
scale_x_continuous(name="Length") +
facet_grid(yr~decade) + scale_y_continuous(name="Frequency", breaks=2000000)
ageIt=function(len=NULL,n=NULL,Linf=NULL,K=NULL,t0=0.0,timing=0.5,plusGroup=30){
## expected age at length adjust to beginning of year
age=pmax(pmin(floor(t0-log(1-pmin(len/Linf,.9999999))/K+timing),plusGroup),0)
## calculate frequencies
res=aggregate(n, list(age=age), sum)
return(res)}
#### Wrapper function for statistical ageing with a plot
cas2caa<-function(x,grwPar,constr,ages){
## aggregate frequencies by bins
tst =with(x,aggregate(n,list(len=len),sum))
lnDist=mix(tst,grwPar,"norm",constr=constr,emsteps=3,print.level=1)
plot(lnDist,xlim=c(50,250))
abline(v=vonBert(ages,vB["Linf"],vB["K"],vB["t0"]),col="green",lty=5)
mtext(unique(x$year))
return(data.frame(age=ages,lnDist$parameters))}
caa=ddply(cas, .(year), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
#### Create an FLQuant for FLR to take advantage of fisheries stuff
names(caa)[3]="data"
caaSlice =as.FLQuant(caa)
constr<-mixconstr(conmu ="MFX", fixmu=c(rep(FALSE,3),rep(TRUE,8)), consigma ="CCV")
constr=mixconstr(conmu ="MFX", fixmu=c(rep(FALSE,3),rep(TRUE,8)), consigma ="CCV")
constr
par
ages<-0:plusGroup
grwPar=mixparam(pi =c(apply(sweep(caaSlice,2,apply(caaSlice,2,sum),"/"),1,mean)),
mu =vonBert(ages+0.5,vB["Linf"],vB["K"],vB["t0"]),
sigma =0.05) #ageCV)
vB =c(Linf=238.6,K=0.185,t0=-1.404)
vonBert=function(age,Linf, K, t0) Linf*(1.0-exp(-K*(age-t0)))
grwPar=mixparam(pi =c(apply(sweep(caaSlice,2,apply(caaSlice,2,sum),"/"),1,mean)),
mu =vonBert(ages+0.5,vB["Linf"],vB["K"],vB["t0"]),
sigma =0.05) #ageCV)
ages<-0:plusGroup
plusGroup
plusGroup=15
ages<-0:plusGroup
grwPar=mixparam(pi =c(apply(sweep(caaSlice,2,apply(caaSlice,2,sum),"/"),1,mean)),
mu =vonBert(ages+0.5,vB["Linf"],vB["K"],vB["t0"]),
sigma =0.05) #ageCV)
c(apply(sweep(caaSlice,2,apply(caaSlice,2,sum),"/"),1,mean))
caa=ddply(cas, .(year), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
#### Create an FLQuant for FLR to take advantage of fisheries stuff
names(caa)[3]="data"
caaSlice =as.FLQuant(caa)
caa=ddply(cas, .(year), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
caa=ddply(cas, .(YearC), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
names(caa)[3]="data"
caaSlice =as.FLQuant(caa)
names(caa)[3]="data"
head(cas)
caa=ddply(cas[,c("YearC","len","n")], .(YearC), function(x,vB,plusGroup,timing)
ageIt(x$len,x$n,vB["Linf"],vB["K"],vB["t0"],timing,plusGroup), vB, plusGroup, 0.5)
head(caa)
names(caa)[3]="data"
caaSlice =as.FLQuant(caa)
head(caa)
names(caa)[c(1,3)]=c("year","data")
names(caa)[c(1,3)]
names(caa)[c(1,3)]=c("year","data")
caaSlice =as.FLQuant(caa)
library(doParallel)
library(foreach)
library(aspic)
library(gam)
cl=makeCluster(4)
registerDoParallel(cl)
dirData="/home/laurie/Desktop/ICCAT/SCRS/kobe/Inputs/albs/2011/aspic"
dirData="http://www.iccat.int/stocka/Models/ASPIC/albs/2011"
runs =c("run2","run6","run7","run8")
files=c(paste(dirData,runs,"aspic.inp",sep="/"))
albs =aspics(files)
names(albs)=runs
rm(iter)
albs =aspics(files)
dirData="/home/laurie/Desktop/ICCAT/SCRS/kobe/Inputs/albs/2011/aspic"
runs =c("run2","run6","run7","run8")
files=c(paste(dirData,runs,"aspic.inp",sep="/"))
albs =aspics(files)
names(albs)=runs
iter=iterators:::iter
albs =fit(albs)
rm(iter)
library("devtools")
install_github("diags","laurieKell")
install_github("kobe","laurieKell")
install_github("kobe","laurieKell")
library(diags)
library(doParallel)
library(foreach)
library(aspic)
library(gam)
## set parallel stuff
cl=makeCluster(4)
registerDoParallel(cl)
library(FLCore) #FLR
library(FLAdvice) #Biological Reference Points
library(mixdist) #used for fitting mixture distributions
library(ggplotFL) #plotting library
library(ALKr) #Age Length Keys
library(mixdist)
plusGroup=15
vB =c(Linf=238.6,K=0.185,t0=-1.404)
par=read.csv("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/mn_sd.csv")
cas=read.cas("/home/laurie/Desktop/ICCAT/SCRS/2013/ALB/ALK/inputs/casALBN-7511_v1.csv")
source('~/Desktop/flr/git/diags/R/ICCAT.io.R', echo=TRUE)