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)
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.
plot(FLQuants(ple4,"Stock"=stock,"Index"=function(x) apply(oem(x),2,sum)))
Create an index aggregated over ages
apply(oem(ple4),2,sum)
An object of class "FLQuant"
, , unit = unique, season = all, area = unique
year
age 1957 1958 1959 1960 1961 1962 1963 1964 1965
all 291997 274840 297378 318346 340461 321109 350486 314340 360402
year
age 1966 1967 1968 1969 1970 1971 1972 1973 1974
all 418044 380165 414926 414709 333627 358404 346217 309087 321579
year
age 1975 1976 1977 1978 1979 1980 1981 1982 1983
all 347790 401259 346407 340846 317064 308224 321516 340979 370627
year
age 1984 1985 1986 1987 1988 1989 1990 1991 1992
all 390189 419258 454036 492821 461474 448725 385328 322507 263935
year
age 1993 1994 1995 1996 1997 1998 1999 2000 2001
all 235115 210839 178395 185056 205459 207760 196350 226080 208501
year
age 2002 2003 2004 2005 2006 2007 2008
all 180446 189812 183865 178143 221323 194610 269540
units: t
The age structure can be shaped by sel, and trends in q and hyperstability can be specified.The type of the index e.g. the form of the index (mass), whether it is fishery dependent (fish.dependendent) and how the effort is derived in which case how the effort is derived (effort`)
ggplot(model.frame(mcf(FLQuants(ple4,"Stock"=stock,"Index"=function(x) apply(oem(x),2,sum)))))+
geom_point( aes(Stock,Index))+
geom_smooth(aes(Stock,Index),method="lm")+
facet_null()
timing=0.5
fish.dependent=FALSE
effort =c("f","h")
mass =TRUE
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")
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')
Wilkinson, L. 1999. The Grammar of Graphics, Springer. doi 10.1007/978-3-642-21551-3_13.↩