[1] "cpue"
# survey
setGeneric("survey", function(object, ...) standardGeneric("survey"))
[1] "survey"
setMethod("survey", signature(object="FLStock"),
function(object, sel=stock.n(object) %=% 1, wt=stock.wt(object), timing = 0.5, mass = FALSE) {
timing <- pmax(pmin(timing, 1.0), 0.0)
#
stock.n <- stock.n(object) * exp(-(harvest(object) * timing - m(object) * timing))
cpue <- stock.n %*% sel
if (mass)
cpue <- cpue %*% wt
return(cpue)})
In Management Strategy Evaluation (MSE) an Operating Model (OM) is used to simulate resource dynamics in trials in order to evaluate the performance of a Management Procedure (MP). Where the MP is the combination of pre-defined data, together with an algorithm to which such data are input to provide a value for a management control measure.
The link between the OM and the MP is the Observation Error Model (OEM), which generates fishery-dependent or independent resource monitoring data. The OEM reflects the uncertainties, between the actual dynamics of the resource and perceptions arising from observations and assumptions by modelling the differences between the measured value of a resource index and the actual value in the OM.
The simplest way to obtain mpb is to install it from CRAN by using the following command in the R console:
The repos options can be changed depending on personal preferences and includes options such as choosing the directories in which to install the packages see help(install.packages) for more details.
So that users may have a better idea of what functions are available, which one to choose, or where to seek help, this section provides a general overview of the package. In particular it highlights the various elements, what they do, and provides some examples of usage. More details are given in later sections.
First, load the kobe
package:
library(ggplot2)
library(FLCore)
library(ggplotFL)
Warning: replacing previous import 'ggplot2::%+%' by 'FLCore::%+%' when
loading 'ggplotFL'
library(mpb)
Warning: replacing previous import 'FLCore::desc' by 'plyr::desc' when
loading 'mpb'
library(FLife)
library(plyr)
Example dataset for North Sea plaice.
data(ple4)
Plotting is done using ggplot2
which provides a powerful alternative paradigm for creating both simple and complex plots in R using the ideas the Grammar of Graphics1 The idea of the grammar is to specify the individual building blocks of a plot and then to combine them to create the graphic desired2.
The ggplot
functions expects a data.frame
for its first argument, data
; then a geometric object geom
that specifies the actual marks put on to a plot and an aesthetic that is “something you can see” have to be provided. Examples of geometic Objects (geom) include points (geom_point, for scatter plots, dot plots, etc), lines (geom_line, for time series, trend lines, etc) and boxplot (geom_boxplot, for, well, boxplots!). Aesthetic mappings are set with the aes() function and, examples include, position (i.e., on the x and y axes), color (“outside” color), fill (“inside” color), shape (of points), linetype and size.
The phase plot plots stock status against fishing mortality relative to target reference points as a two-dimensional phase plot.
Create an index aggregated over ages
apply(oem(ple4),2,sum)
, , unit = unique, season = all, area = unique
year
age 1957 1958 1959 1960 1961
all 324230 318619 338392 363575 367603
[ ... 51 years]
year
age 2013 2014 2015 2016 2017
all 672609 680496 683821 660096 628667
plot(FLQuants(ple4,"Stock"=stock,
"Survey"=function(x) apply(survey(x,timing=0,mass=TRUE),2,sum),
"CPUE" =function(x) apply( cpue(x),2,sum)))
The age structure can be shaped by sel
, e.g. for a survey of mature individuals
ggplot(apply(survey(ple4,sel=mat(ple4)),2,sum))
Trends in q and hyperstability can be specified
ggplot(apply(survey(ple4,sel=mat(ple4)),2,sum))
cv=rlnorm(100,log(stock(ple4)),0.3)
ggplot(cv)+
geom_boxplot(aes(factor(year),data))
sel =apply(harvest(ple4),1,mean)
ggplot(sel)+
geom_line(aes(age,data))
q =FLQuant(cumprod(1+rep(.02,dim(fbar(ple4))[2])),dimnames=dimnames(fbar(ple4)))
plot(q)
cpue =stock(ple4)/mean(stock(ple4))
stable =cpue^0.1
deplete=cpue^2
plot(FLQuants("CPUE" =cpue,
`Hyper_Stable` =stable,
`Hyper_Depleted`=deplete))
trend=FLQuant(seq(1,2,length.out=dim(stock(ple4))[2]),dimnames=dimnames(stock(ple4)))
var =trend*abs(cv)*sign(cv)
ggplot(FLQuants("Log Normal" =cv,
"Trend in CV"=var))+
geom_boxplot(aes(factor(year),data))+
facet_grid(qname~.)
bias=FLPar(omega=1,ref=mean(stock(ple4)),q=0)
hyperstability<-function(object,omega=1,ref=apply(object,c(1,3:6),mean))
ref%*%((object%/%ref)^omega)
bias<-function(object,bias=0.02)
FLQuant(cumprod(1+rep(bias,dim(object)[2])),dimnames=dimnames(object))
set.seed(1234)
u =FLQuants("Unbiased" =rlnorm(100,log(apply(oem(ple4),2:6,sum)),.3),
"Hyperstability"=rlnorm(100,log(apply(oem(ple4),2:6,sum)%*%
hyperstability(stock(ple4),0.52)),.3),
"Trend" =rlnorm(100,log(apply(oem(ple4),2:6,sum)%*%bias(stock(ple4),0.02)),.3),
"AR" =apply(oem(ple4),2:6,sum)%*%
exp(rnoise(100,apply(oem(ple4),2:6,sum)*0,.3,b=.7)),
"Variable" =var,
"Juvenile" =rlnorm(100,log(apply(oem(ple4,sel=mat(ple4)),2:6,sum)),.3),
"Mature" =rlnorm(100,log(apply(oem(ple4,sel=1-mat(ple4)),2:6,sum)),.3),
"Numbers" =rlnorm(100,log(apply(oem(ple4,mass=FALSE),2:6,sum)),.3))
u=FLQuants(llply(u,function(x) x/mean(x)))
u=ldply(u,as.data.frame)
u.=ddply(u,.(year,.id), with, quantile(data))
ggplot()+
geom_line(aes(year,data,col=factor(iter)),
data=subset(u,iter%in%c(2,11)))+
geom_ribbon(aes(year,ymin=`25%`,ymax=`75%`),data=u.,col="grey",alpha=.5)+
facet_wrap(~.id,ncol=2)+
theme_bw()+theme(legend.position="none")
library(FLCore)
library(ggplotFL)
library(tmvtnorm)
library(plyr)
library(reshape)
data(ple4)
n =survey(ple4)
n =round(1000*n%/%apply(n,2:6,sum))
l =stock.wt(ple4)^0.3
sigma=FLPar(0,dimnames=dimnames(n)[c(1,1:6)])
sigma=apply(sigma,3:7,function(x) {diag(x)=0.2;x})
sigma=FLPar(c(sigma),dimnames=dimnames(n)[c(1,1:6)])
sigma=FLPar(aperm(maply(dimnames(l)$year, function(year) cor2cov(sigma@.Data[,,year,,,,,drop=T],l[,year])),3:1))
names(dimnames(sigma)[3])="year"
upper=n%=%20
x=rtmvnorm(n=max(n[,1]), mean=c(l[,1]), sigma=matrix(c(sigma[,,1,drop=T]),10,10), upper=c(upper[,1]))
x=melt(x)
names(x)[1:2]=c("iter","age")
n=as.data.frame(n,drop=TRUE)
x =subset(merge(n,x),iter<=data)
ggplot(x)+
geom_histogram(aes(value,fill=factor(age)))+
xlab("Year")+ylab("Count")
library(FLCore)
library(tmvtnorm)
library(reshape2)
lem2<-function(n,l,sd){
se=sd/n^0.5
se=(apply(se%*%se%*%n,c(2:6),sum)%/%apply(n,2:6,sum))^0.5
ln=apply(l%*%n,2:6,sum)%/%apply(n,2:6,sum)
FLQuants(len=ln,se=se)}
data(ple4)
n =survey(ple4)
n =round(1000*n%/%apply(n,2:6,sum))
l =stock.wt(ple4)^0.3
sd=l*0.2
lengths=lem2(n,l,sd)
ggplot()+
geom_line(aes(year,data),data=as.data.frame(lengths[[1]]))+
geom_errorbar(aes(year,ymin=min,ymax=max),
data=model.frame(FLQuants(
min=lengths[[1]]-lengths[[2]],
max=lengths[[1]]+lengths[[2]])))+
xlab("Year")+ylab("Mean Length")
source('~/Desktop/sea++/mydas/pkg/R/oemLn.R')
library(reshape)
lh=lhPar(FLPar(linf=89))
ak=alk(lh)
source('~/Desktop/sea++/mydas/pkg/R/genTime.R')
library(FLBRP)
library(FLasher)
lh=FLPar(c(linf= 59.1, k=0.28, t0=-0.4, a=0.01111,b=3.15,a50=4.0, l50=43.25),units="NA")
lh=lhPar(lh)
eq=lhEql(lh)
gTime=c(round(gt(eq)))
fbar(eq)=refpts(eq)["msy","harvest"]%*%FLQuant(c(rep(.1,19),
seq(.1,2,length.out=30),
seq(2,1.0,length.out=gTime)[-1],
rep(1.0,61)))[,1:105]
om=as(eq,"FLStock")
om=fwd(om,f=fbar(om)[,-1], sr=eq)
ggplot(melt(lfd[,seq(1,45,10)]))+
geom_histogram(aes(length,weight=value),binwidth=1)+
facet_grid(year~iter,scale="free")+
xlab("Length (cm)")+ylab("Frequency")+
coord_cartesian(xlim=c(0,mean(lh["linf"])))
Figure 1 Observation error model for turbot.
FLPKG
at the FLPKG
issue page,3 or on the FLR mailing list.FLPKG
can always be installed using the devtools
package, by calling library(devtools)
install_github('flr/FLPKG')
This vignette and many of the methods documented in it were developed under the MyDas project funded by the Irish exchequer and EMFF 2014-2020. The overall aim of MyDas is to develop and test a range of assessment models and methods to establish Maximum Sustainable Yield (MSY) reference points (or proxy MSY reference points) across the spectrum of data-limited stocks.
Wilkinson, L. 1999. The Grammar of Graphics, Springer. doi 10.1007/978-3-642-21551-3_13.↩