-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsam.R
More file actions
32 lines (25 loc) · 1018 Bytes
/
sam.R
File metadata and controls
32 lines (25 loc) · 1018 Bytes
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
load("input.RData")
library(TMB)
compile("sam.cpp")
dyn.load(dynlib("sam"))
obj <- MakeADFun(data,parameters,random=c("logN","logF"),DLL="sam")
opt<-nlminb(obj$par,obj$fn,obj$gr,control=list(trace=1,eval.max=1200,iter.max=900))
sdrep<-sdreport(obj)
pl <- as.list(sdrep,"Est")
plsd <- as.list(sdrep,"Std")
plotit <-function (what, x=data$years, ylab=what, xlab="Years", trans=function(x)x ,...){
idx<-names(sdrep$value)==what
y<-sdrep$value[idx]
ci<-y+sdrep$sd[idx]%o%c(-2,2)
plot(x,trans(y), xlab=xlab, ylab=ylab, type="l", lwd=3, ylim=range(c(trans(ci),0)), las=1,...)
polygon(c(x,rev(x)), y = c(trans(ci[,1]),rev(trans(ci[,2]))), border = gray(.5,alpha=.5), col = gray(.5,alpha=.5))
grid(col="black")
}
pdf("fig1.pdf", 10,10 )
par(mfrow=c(2,2))
options(scipen=-3)
plotit("logssb", ylab="SSB", trans=exp)
plotit("logfbar", ylab="Fbar", trans=exp)
plotit("logR", ylab="R", trans=exp)
plotit("logCatch", ylab="Catch", trans=exp, x=data$years[-length(data$years)])
dev.off()