Package 'mpb'

Title: Management Procedures
Description: mpb is an R package for running and simulation testing biomass based stock assessment models.
Authors: Laurence Kell [aut, cre]
Maintainer: Laurence Kell <[email protected]>
License: GPL-2
Version: 3.5.0
Built: 2026-06-04 07:54:57 UTC
Source: https://github.com/lauriekell/mpb

Help Index


Returns length age data from Multifan-CL as a list with four data frames

Description

Returns length age data from Multifan-CL as a list with four data frames

Usage

alkMFCL(lfile, ffile, i = 1, df = TRUE)

Arguments

lfile

the length.fit file

ffile

the freq file

i

fleet to read in

df

return data as a data.frame logical default is TRUE

Value

a list with elements caa numbers by age, len, season and year, laa length by age season and year, obs observed length samples by season and year and hat fitted lengths by season and year,

lfile="/home/laurie/Desktop/gcode/mse4mfcl/ALB/papers/SCRS/SCRS2013-ALK/Inputs/length09.fit" rfile="/home/laurie/Desktop/gcode/mse4mfcl/ALB/papers/CSRS/SCRS2013-ALK/Inputs/plot-09.par.rep" ffile="/home/laurie/Desktop/Dropbox/collaboration/Shelton/ALBN/4B/2009/albN.frq"


as("biodyn", "FLStock")

Description

Coerces an FLStock into a biodyn object.

Usage

## S4 method for signature 'FLQuant'
rate(object)

aspic constructor

Description

Create an object of the aspic class representing a biomass dynamic stock assessment model.

Usage

aspic(object, value, ...)

Arguments

object

can be character or biodyn objects

...

named parameter being passed to slots

Value

aspic object

Examples

## Not run: 
asp=aspic()

## End(Not run)

ASPIC Biomass Dynamic Model Class

Description

A class that represents the ASPIC biomass dynamic stock assessment model.

Details

The Class is intended to be used as part of an MSE and includes methods for diagnostics, calculating reference points and other quantities used when providing management advice.

Value

aspics object

Slots

name

character with the name of the stock

conditioning

factor

options

numeric

index

data.frame

stopmess

character

rnd

numeric

model

factor

catch

FLQuant

stock

FLQuant

diags

data.frame

params

FLPar

control

FLPar

priors

array

vcov

FLPar

hessian

FLPar

objFn

FLPar

mng

FLPars

name

character

desc

character

range

numeric

Examples

## Not run: aspic()

aspics

Description

Create a list of aspic objects

features that give a little more structure to list objects. First the elements of aspics must all be of the same class biodyn. Second it implements lock mechanism that, when turned on, does not allow the user to increase or decrease the object length.

Usage

aspics(object, ...)

## S4 method for signature 'list'
aspics(object, ...)

Arguments

object

can be aspic object or a list of aspic objects

...

additional aspic objects

Value

aspics object

Slots

.Data

The data. list.

names

Names of the list elements. character.

desc

Description of the object. character.

lock

Lock mechanism, if turned on the length of the list can not be modified by adding or removing elements. logical.

Author(s)

The FLR Team

See Also

[, [<-, [[<-, $<-, coerce, lapply, window, list

Examples

## Not run: 
aspics(aspic())

## End(Not run)
## Not run: 
asp <- aspics("1"=aspic(),"2"=aspic())
## End(Not run)

aspics a class that contains a list of ASPIC biomass dynamic stock assessment model classes

Description

aspics a class that contains a list of ASPIC biomass dynamic stock assessment model classes

Slots

object

biodyn constructor

Description

Creates an object of the biodyn class representing a biomass dynamic stock assessment model.

Usage

biodyn(object, params, ...)

Arguments

object

can be character object or a FLPar, FLStock, aspic objects

...

named parameter being passed to slots

Value

biodyn object

Examples

## Not run: 
bd=biodyn(params=FLPar(r=0.6,k=50000,p=1,b0=1))

## End(Not run)

biodyn class

Description

A class that implement a biomass dynamic stock assessment model.

Details

The Class is intended to be used as part of an MSE and includes methods for diagnostics, calculating reference points and other quantities used when providing management advice.

Slots

name

A character with the name of the stock

desc

A character providing a fuller description of the object

range

A numeric vector containing the quant and year ranges

model

A factor giving name of production function, for now this is only 'pellat'

obj

factor that determines the objective function type -LL or LAV

catch

An FLQuant with total catch by year

index

An FLQuants with indices year

stock

An FLQuant which will hold the estimated stock by year

control

An FLPar which sets initial guess (val) and bounds (min and max) for each parameter. The phase allows a parameter to be fixed if less <0 and for paramters to be estimated sequentially

hcr

A data.frame with harvest control rule options

priors

An array which sets penalties for parameters

params

An FLPar with parameter estmates

vcov

An FLPar with the covariance matrix of the parameter estimates

hessian

An FLPar with the hessian of the estimated parameters

ref

A numeric with parameters for estimating mng quantities

mng

FLPar with derived quatities of management interest

mngVcov

An FLPar with the variance matrix of management quanties

diags

A data.frame with residuals and covariates from fit of CPUE to stock

objFn

FLPar with objective function

ll

FLPar with negative log likelihood by data component

profile

data.frame not yet implemented

hst

data.frame not yet implemented

All slots in the class have accessor and replacement methods that provide validation and protection of their data.

Examples

## Not run: biodyn()

Create biodyn Object from FLPar Parameters

Description

Creates a biodyn object initialized with biomass at BMSY and catch at MSY

Usage

## S4 method for signature 'FLPar,missing'
biodyn(object, nyrs = 50)

Arguments

nyrs

Number of years for projection (default = 50)

params

An FLPar object containing parameters r, k, and p

Value

A biodyn object initialized for the specified number of years

Examples

params=FLPar(r=0.5, k=1000, p=1)
bd=biodyn(params)

biodyns creates a list of biodyn objects

Description

biodyns creates a list of biodyn objects

Usage

## S4 method for signature 'biodyn'
biodyns(object)

Slots

object

fit

Description

Fits the aspic model to catch and catch per unit effort data

Bootstraps the ASPIC biomass dynamic model.

Bootstraps the aspic model

Arguments

object;

an aspic object or a character string giving an aspic "inp" file

dir;

an optional dir where aspic text files used for fitting can be found

Value

An aspic object with fitted values and parameter estimates

An aspic object with fitted values and parameter estimates

See Also

aspic,biodyn,boot,jk

biodyn,boot,jk

Examples

## Not run: 
    data(asp)
    asp=boot(asp)
## End(Not run)

boot, Bootstraps biodyn.

Description

Bootstraps the aspic model

Usage

## S4 method for signature 'biodyn'
boot(object, run = TRUE)

Arguments

object;

a biodyn object

Details

boot

See Also

biodyn,boot,jk

Examples

## Not run: 
    data(asp)
    asp=boot(asp)
## End(Not run)

control

Description

sets initial guess and lower and upper bounds

Usage

## S4 method for signature 'biodyn'
control(object)

Arguments

object

biodyn object

Value

FLPar

Examples

## Not run: control(biodyn())

control<-

Description

sets in biodyn initial guess and lower and upper bounds

Usage

## S4 replacement method for signature 'biodyn,FLPar'
control(object) <- value

Value

biodyn with new control slot

Examples

## Not run: control(biodyn())

controlFn

Description

A utility function to help set up the control slot in biodyn

Usage

controlFn(object)

Arguments

r

a numeric value with best guess

k

a numeric value with best guess

p

a numeric value with best guess, default=1

b0

a numeric value with best guess default=1

phaseR

a numeric value for phase, default=1

phaseK

a numeric value for phase, default=1,

phaseP

a numeric value for phase, default=-1,

phaseB0

a numeric value for phase, default=-1,

min

a numeric a multipler for the best guess

max

numeric a multipler for the best guess

Value

a control object

See Also

biodyn control

Examples

## Not run: 
sim()
   
## End(Not run)

params

Description

Slot for estimates

Usage

diags(object)

Arguments

object

either biodyn or aspic class

value
...

any other parameter


fit

Description

Estimates parameters biodyn class by fitting catch and CPUE indices

Usage

diagsFn(res)

Arguments

object

an object of class biodyn

index

an FLQuant, FLQuants or data.frame object with CPUE indices

...

other arguments

Examples

## Not run: 
   #simulate an object with known properties
   bd=sim()
   bd=window(bd,end=49)
   
   #simulate a proxy for stock abundance
   cpue=(stock(bd)[,-dims(bd)$year]+stock(bd)[,-1])/2
   cpue=rlnorm(1,log(cpue),.2)
   
   #set parameters
   setParams(bd) =cpue
   setControl(bd)=params(bd)
   control(bd)[3:4,"phase"]=-1
   
   #fit
   bd=fit(bd,cpue)

## End(Not run)

mng

Description

calculates time series of quantities useful for management

Usage

fapexAge(object)

Arguments

object

either FLStock biodyn or aspic classes


feasible

Description

Checks that the parameters can be taken given the catch time series

Usage

## S4 method for signature 'FLPar,FLQuant'
feasible(object, catch, min = 0.01)

Arguments

object

an FLPar or data.frame object with parameters for the production function, r, k, p and b0.

catch

an FLQuant with a time series of catch, iters must be equal to 1

min

the minimum permissable population level, used to check that the catch can be taken.

...

any other parameters

Value

a FLPar a subset of params with parameter values that can explain the catch

Examples

## Not run: 
params=feasibleFn(catch,params)

## End(Not run)

fit

Description

A generic method for fitting catch and index of relative abundance for both biodyn and aspic.

Usage

fit(object, index, ...)

Arguments

object

either biodyn or aspic class

index

with relative abundance, FLQuant or FLQuants, if object is of type bodyn

...

any other parameter

See Also

aspic, biodyn, jk, boot


-mcmc 100000 -mcsave 100'

Description

-mcmc 100000 -mcsave 100'

Usage

fitPella(
  object,
  dir = tempdir(),
  cmdOps = paste("-maxfn 500 -iprint 0"),
  lav = FALSE,
  maxF = 2.5,
  silent = !TRUE
)

Class FLQuantJKs

Description

FLQuantJKs is a list of FLQuant objects. It is very similar to the standard list class. It implements a lock mechanism that, when turned on, does not allow the user to increase or decrease the object length. The elements of FLQuantJKs must all be of class FLQuant.

Slots

.Data

The data. list.

names

Names of the list elements. character.

desc

Description of the object. character.

lock

Lock mechanism, if turned on the length of the list can not be modified by adding or removing elements. logical.


fnProfile

Description

Outputs as a data.frame a summary of parameters and RSS etc by data component generated when doing a profile

Usage

fnProfile(x)

Arguments

x:

an aspic object

Value

a data frame with results by data component.

See Also

biodyn,profile fit

Examples

## Not run: 
data(asp)
dcK=profile(asp,which=c("k"),range=seq(0.2,2.0,length.out=21),fn=fnProfile)
ggplot(dcK)+geom_line(aes(k,value,group=variable,col=variable))+
 theme_ms(12,legend.position="bottom")+
 ylab("Residual Sum of Squares")+xlab("K")


## End(Not run)

fwd

Description

Projects a biodyn object (i.e. a biomass dynamic model) for a given future catch, harvest rate, or stock biomass. Only one of these has to be supplied as an argument.

Usage

## S4 method for signature 'biodyn,missing,missing'
fwd(
  object,
  fishery,
  control,
  catch = NULL,
  harvest = NULL,
  f = NULL,
  stock = NULL,
  hcr = NULL,
  pe = NULL,
  peMult = TRUE,
  minF = 0,
  maxF = 2,
  bounds = list(catch = c(Inf, Inf)),
  lag = 0,
  end = NULL,
  starvationRations = 0.75,
  ...
)

Arguments

object

an object of class biodyn or biodyns

control

missing

...

any other parameters

Examples

## Not run: 
bd=simBidyn()
harvest=rlnorm(100,log(harvest(bd))[,-dims(bd)$year],.1)

bdHat =fwd(bdHat,harvest=harvest)

plot(bdHat,worm=c(2,8))+
theme(legend.position="bottom")
 
## End(Not run)

harvest

Description

harvest rate

Usage

## S4 method for signature 'biodyn,missing'
harvest(object)

Arguments

object

either biodyn or aspic classes


hcr

Description

Harvest Control Rule, calculates F, or Total Allowable Catch (TAC) based on a hockey stock harvest control rule.

Harvest Control Rule, calculates F, or Total Allowable Catch (TAC) based on a hockey stock harvest control rule.

Usage

## S4 method for signature 'biodyn,FLPar'
hcr(
  object,
  refs = hcrParam(ftar = 0.7 * mpb:::fmsy(refs), btrig = 0.8 * mpb:::bmsy(refs), fmin =
    0.01 * mpb:::fmsy(refs), blim = 0.4 * mpb:::bmsy(refs)),
  params = refs,
  stkYrs = max(as.numeric(dimnames(stock(object))$year)),
  refYrs = max(as.numeric(dimnames(catch(object))$year)),
  hcrYrs = max(as.numeric(dimnames(stock(object))$year)),
  tac = TRUE,
  bndF = NULL,
  bndTac = NULL,
  maxF = 2,
  ...
)

## S4 method for signature 'FLStock,FLBRP'
hcr(
  object,
  refs,
  params = hcrParam(ftar = 0.7 * fmsy(refs), btrig = 0.8 * bmsy(refs), fmin = 0.01 *
    fmsy(refs), blim = 0.4 * bmsy(refs)),
  stkYrs = max(as.numeric(dimnames(stock(object))$year)),
  refYrs = max(as.numeric(dimnames(catch(object))$year)),
  hcrYrs = max(as.numeric(dimnames(stock(object))$year)),
  tac = TRUE,
  tacMn = TRUE,
  bndF = NULL,
  bndTac = NULL,
  maxF = 2,
  ...
)

Arguments

object

an object of class biodyn or

...

other parameters, i.e. refs FLPar or FLBRP object with reference points, can be missing if refpts are part of object params FLPar object with hockey stick HCR parameters, see hcrParam yr numeric vector with years used to values in HCR byr numeric vector with years used for bounds hyr numeric vector with years to use in projection tac logical should return value be TAC rather than F? bndF vector with bounds (i.e.min and max values) on iter-annual variability on F bndTac vector with bounds (i.e. min and max values) on iter-annual variability on TAC stkYrs numeric vector with years for calculating stock status, max(as.numeric(dimnames(stock(object))$year)), refYrs numeric vector with years for calculating reference points, max(as.numeric(dimnames(catch(object))$year)), hcrYrs numeric vector with years for setting management, max(as.numeric(dimnames(stock(object))$year)), tacMn logical should the TACs be the average of the values returned? maxF =2 numeric vector specifying maximum relative F

Value

FLPar object with value(s) for F or TAC if tac==TRUE

FLPar object with value(s) for F or TAC if tac==TRUE

Examples

## Not run: 
bd   =sim()

bd=window(bd,end=29)
for (i in seq(29,49,1))
bd=fwd(bd,harvest=hcr(bd,yr=i,yr=i+1)$hvt)

## End(Not run)
## Not run: 
bd   =sim()

bd=window(bd,end=29)
for (i in seq(29,49,1))
bd=fwd(bd,harvest=hcr(bd,yr=i,yr=i+1)$hvt)

## End(Not run)

hcrParam

Description

Combines reference points into the HCR breakpts

Usage

hcrParam(ftar, btrig, fmin, blim)

Arguments

ftar

an object of class FLPar

btrig

an object of class FLPar

fmin

an object of class FLPar

blim

an object of class FLPar

Examples

## Not run: 
tac('logistic',FLPar(msy=100,k=500))

## End(Not run)

hrate

Description

harvest rate

Usage

## S4 method for signature 'biodyn'
hrate(object)

Arguments

object

either biodyn or aspic classes


is.aspic

Description

Checks class type and returns TRUE if object is of type biodyn

Usage

is.aspic(x)

Arguments

x

biodyn class

Value

TRUE or FALSE

Examples

## Not run: 
 is.aspic(aspic()) 
 
## End(Not run)

is.biodyn

Description

Checks class type and returns TRUE if object is of type biodyn

Usage

is.biodyn(x)

Arguments

x

biodyn class

Value

TRUE or FALSE

Examples

## Not run: 
 is.biodyn(biodyn()) 
 
## End(Not run)

jk

Description

A generic method for jack knifing a fit to catch and index of relative abundance for both biodyn and aspic.

Fits the aspic model to catch and catch per unit effort data removing 1 cpue observation at a time

Usage

jk(object, index, ...)

chkIters(object)

Arguments

object

either biodyn or aspic class

index

with relative abundance of type FLQuantJK or FLQuantJKs, if object is of type biodyn

...

any other parameter

object;

a character string giving an aspic "inp" file

dir;

an optional dir where aspic text files used for fitting can be found

Value

An aspic object with fitted values and parameter estimates

See Also

aspic, biodyn, fit, boot

biodyn,boot,fit

Examples

## Not run: 
    data(asp)
    asp=jk(asp)
## End(Not run)

Carrying capacity

Description

Calculates $k$ given msy, r and K for a Pella-Tomlinson biomass dynamic model

Usage

K(msy, r = 0.6, p = 1, params = FLPar(r = r, p = p))

Arguments

msy

a guess for MSY

r

a guess for $r$ the population growth rate

p

a guess for $p$ the shape parameter

params

provide $r$ and $p$ as FLPar

Value

an FLPar object with an estimate for $k$

See Also

msy and bmsy

Examples

## Not run: 
 K(5000,r=.6,p=1.0)
 
## End(Not run)

kobe

Description

Creates time series of stock relative to BMSY and harvest rate relative to FMSY

Usage

## S4 method for signature 'biodyn,missing'
kobe(
  object,
  what = c("sims", "trks", "pts", "smry", "wrms")[1],
  probs = c(0.75, 0.5, 0.25),
  year = NULL,
  nwrms = 10,
  sim = NULL,
  drop = TRUE
)

Arguments

object

biodyn object

method

missing

...

other arguments

Value

data.frame or list of data.frames

Examples

## Not run: 
sim()

## End(Not run)

Returns von Bertalannfy growth parameters from Multifan-CL

Description

Returns von Bertalannfy growth parameters from Multifan-CL

Usage

mfclGrw(parfile = getoutputparfile("plot.rep"))

Arguments

parfile

the par file output from Multifan-cl

Value

a numeric vector


mixnorm

Description

Simulates a normal density function from an FLQuant

Usage

mixnorm(n, mn, sd, bin, left = T)

Arguments

mn

an FLQuant with means

sd

an FLQuant with standard deviation

Value

an FLPar with expected probability for lengths-at-age

Examples

## Not run: 
mn=FLQuant( 1:5,     dimnames=list(age=1:5,year=1991:2000,unit=1:2))
sd=FLQuant((1:5)/5,dimnames=list(age=1:5,year=1991:2000))
md=mixnorm(mn,sd,(1:20)/4)
ggplot(as.data.frame(md))+
   geom_line(aes(len,data,group=age))+
   facet_wrap(year~unit)
ggplot(as.data.frame(apply(md,1,sum)))+
   geom_line(aes(as.numeric(as.character(params)),data))     
 
## End(Not run)

mseBiodyn

Description

Runs a full MSE using an FLStock object as the Operating Model and biodyn as the Mangement Procedure

Usage

mseBiodyn(
  om,
  eql,
  srDev,
  uDev,
  mp,
  start = range(om)["maxyear"],
  end = start + 30,
  interval = 3,
  oem = oem,
  hcrPar = function(mp, ftar = 0.7, btrig = 0.6, fmin = 0 - 1, blim = 0.001) {
    
    hcrParam(ftar = ftar * fmsy(mp), btrig = btrig * bmsy(mp), fmin = fmin * fmsy(mp),
    blim = blim * bmsy(mp))
 },
  bndF = NULL,
  bndTac = NULL,
  maxF = 1,
  omega = 1,
  refB = 1,
  qTrend = 0
)

Arguments

om

an FLStock object

srDev

a FLQuant with recruitment deviates

uDev

an FLQuant or FLQuants with CPUE residuals

mp

an biodyn object that holds the options for the biomass dynamic assessment model

range

a vector the starting and end years for the projections, and the interval for running the MP

ftar

a numeric with target F in HCR

fmin

a numeric with minimum F in HCR

blim

a numeric with biomass limit for HCR

btrig

a numeric with biomass trigger (i.e. when to reduce F) in HCR

what

a character that specifies what is to be used for the reference point in the HCR, recycled as required

mult

a logical that specifies whether quantity in HCR options is a multiplier or probability, recycled as required

Value

a list of data.frames with performance measures from OM and summaries from MP, if con!=NULL will also write to a MYSQL database

See Also

biodyn

Examples

## Not run: 
library(mpb)
library(FLash)
library(FLBRP)

load(om)
load(eql)

om=mpb::fwdWindow(om,eql,end=2030)
om=propagate(om,100)

srDev=FLQuant(0,dimnames=list(year=2000:2030))
srDev=rlnorm(100,srDev,0.3)

om=mpb::fwd(om,catch=catch(om)[,ac(2000:2011)],sr=eql,sr.residuals=srDev)

library(popbio)

mp=mpb::FLBRP2biodyn(  eql,"biodyn")
mp=mpb::FLStock2biodyn(om, "biodyn")

## End(Not run)

mvn

Description

Takes a fitted biodyn object and uses the covariance matrix (in the vcov slot) and the parameter estimates (params slot) to use Monte Carlo simulation to generate new parameters

Usage

mvn(
  object,
  n,
  nms = dimnames(object@control[object@control[, "phase", ] > 0, ])$params,
  fwd = FALSE,
  params = TRUE
)

Arguments

object

a biodyn object

n

numeric with number of iter to create

nms

the parameters for Monte Carlo simulation

fwd

logical do you want to simuate historic time series of stock biomass?, default is FALSE

params

actual parameters

Value

biodyn with simuated time series

Examples

## Not run: 
x=1

## End(Not run)

nll

Description

Checks that the parameters can be taken given the catch time series

Usage

## S4 method for signature 'FLQuant,FLQuant,FLPar'
nll(object, index, params, min = 0.01)

Arguments

object

an FLQuant with a time series of catch, iters must be equal to 1

params

an FLPar object with parameters for the production function, r, k, p and b0.

min

the minimum permissable population level, used to check that the catch can be taken.

...

any other parameters

Value

a FLPar a subset of params with parameter values that can explain the catch

Examples

## Not run: 
params=nllFn(catch,params)

## End(Not run)

nmc

Usage

nmcFn(x, s, E = 5, z = 1.96)

Arguments

x

FLQuant

E

numeric The required percentage error of the mean

z

numeric Value of Z for a given confidence level for a normally distributed random variable, default is 1.96 for a 95

\item

...other arguments

FLQuant with number of iters required by number of iters

Calculates the number of iterations needed in Monte Carlo Simulation to achieve a given precision.

## Not run: data(ple4) ssb=rlnorm(2000,log(ssb(ple4)),0.5) nmc(ssb) ## End(Not run)

om

Description

An example Operating Model, based on North Atlantic Albacore

Reference points and expected dynamics, for Operating Model based on North Atlantic Albacore

Format

An FLStock object

stock.n

numbers-at.age, FLQuant

stock.wt

mass-at-age, FLQuant

...

An FLBRP object

stock.wt

mass-at-age, FLQuant

...

Details

A dataset containing the historic stock estimates, derived from the ICCAT multifan-CL assessment

A dataset containing the average estimates of biological parameters and selection patterns, derived from the ICCAT multifan-CL assessment

Author(s)

Laurence Kell [email protected]

References

http://http://iccat.int/Documents/CVSP/CV070_2014/n_4/CV070041365.pdf/

http://http://iccat.int/Documents/CVSP/CV070_2014/n_4/CV070041365.pdf/


plot

Description

Plots time series of biomass, harvest rate and catch for a biodyn object, using ggplot2.

Usage

## S4 method for signature 'biodyn,missing'
plot(
  x,
  y,
  probs = c(0.9, 0.75, 0.5, 0.25, 0.1),
  na.rm = FALSE,
  type = 7,
  worm = NULL,
  fn = list(Stock = function(x) stock(x), Harvest = function(x) harvest(x), Yield =
    function(x) catch(x)),
  facet = facet_wrap(~qname, scales = "free", ncol = 1),
  ...
)

## S4 method for signature 'FLQuants'
plotCcf(data, ...)

Arguments

x

an object of class biodyn

y

second argument

probs

numeric vector of probabilities with values in [0,1].

na.rm

a logical value indicating whether NA values should be stripped before computation.

type

an integer between 1 and 9 selecting one of the quantile algorithms to be used.

worm

iter(s) to plot as lines

fn

functions

facet

facet for panelling

Value

an ggplot2 object

an ggplot2 object

Examples

## Not run: 

bd =sim()
plot(bd)

## End(Not run) 
## Not run: 


## End(Not run)

plotEql

Description

Creates a ggplot2 object that plots time series of biomass, harvest rate and catch. The basic object can then be modified by adding ggpot2 layers.

Usage

## S4 method for signature 'biodyn,missing'
plotEql(data, biomass, ...)

Arguments

biomass

an object of holding biomass at beginning of year

...

other arguments

x

an object of class biodyn

Value

an ggplot2 object

Examples

## Not run: 
 refpts('logistic',FLPar(msy=100,k=500))

## End(Not run)

plotHcr

Description

Plots a hockey stick HCR with break pointts

Usage

## S4 method for signature 'biodyn'
plotHcr(
  object,
  params = FLPar(ftar = 0.7, btrig = 0.7, fmin = 0.01, blim = 0.2),
  maxB = 1,
  rel = TRUE
)

Arguments

object

an object of class biodyn or

params

FLPar object with hockey stock HCR parameters

maxB

=1

rel

=TRUE

Value

a FLPar object with value(s) for HCR

Examples

## Not run: 
simBiodyn()

## End(Not run)

plotIndex

Description

plotIndex

Usage

## S4 method for signature 'FLQuants'
plotIndex(data, ...)

Arguments

data

an object of class FLQuants biodyn aspic

Value

an ggplot2 object


plotIndexResidual

Description

plotIndexResidual

Usage

## S4 method for signature 'FLQuants'
plotIndexResidual(data, ...)

Arguments

data

an object of class FLQuants biodyn aspic

Value

an ggplot2 object


plotJack

Description

Create a ggplot2 plot based on a jack knifed biodyn and plots time series of biomass and harvest rate. The basic object can then be modified by adding ggpot2 layers.

Usage

plotJack(x, ncol = 1)

Arguments

x

an object of class biodyn that has been jack knifed, i.e. by providing a jack knifed CPUE series to fit

ncol

number of colums in plot panel

Details

plotJack

Value

an ggplot2 object

Examples

## Not run: 
#simulate an object with known properties
bd=sim()
bd=window(bd,end=49)

#simulate a proxy for stock abundance
cpue=(stock(bd)[,-dims(bd)$year]+stock(bd)[,-1])/2
cpue=rlnorm(1,log(cpue),.2)

#set parameters
setParams(bd) =cpue
setControl(bd)=params(bd)
control(bd)[3:4,"phase"]=-1

#fit
bd=fit(bd,cpue)

bdJK=fit(bd,jackknife(cpue))
plotJack(bdJK)
bd  =randJack(100,bd)

## End(Not run)

plotMSE

Description

Creates a ggplot2 object that plots absolute and relative to MSY benchmarks time series of ssb, biomass, harvest rate and catch for FLStock and biodyn objects The basic object can then be modified by adding ggpot2 layers.

Usage

plotMSEfn(mp, om, brp = "missing")

Arguments

x

an object of class biodyn

y

an object of class FLStock

z

an object of class FLBRP

...

other arguments

Value

an ggplot2 object


plot aspics,missing plotIndex aspic plotIndex aspics

Description

Creates a ggplot2 object that plots equilibrium values of biomass, harvest rate and catch against each other. The basic object can then be modified by adding ggpot2 layers.

Usage

plotProduction(data, biomass, ...)

## S4 method for signature 'biodyn,missing'
plotProduction(data, biomass, ...)

Arguments

biomass

optional argument, an FLQuant with biomass at beginning of year

...

other arguments

object

an object of class biodyn

Details

plotProduction

Value

an ggplot2 object

Examples

## Not run: 
 refpts('logistic',FLPar(msy=100,k=500))

## End(Not run)

production

Description

Estimates production for a given biomass

Usage

productionFn(
  object,
  biomass = "missing",
  slots = c("landings.sel", "discards.sel", "stock.wt", "landings.wt", "discards.wt",
    "m", "mat", "harvest.spwn", "m.spwn")
)

Arguments

object

either biodyn or FLBRP class

biomass

an FLQuant

...

any other parameter


profile

Description

Performs a profile using residual sum of squares, fixes some parameters for a range of values and then estimate the others

Usage

profileFn(r = 0.5, k = 1000, p = 0.001, b0 = 0.75, min = 0.1, max = 10)

Arguments

fitted:

an aspic object

which:

character giving the parameters to do the profile for, i.e. to fix.

range;

numeric relative values by which to vary parameter values, default seq(0.5,1.5,length.out=21).

fn:

function that gives values to be profiled.

run:

logical if TRUE then returns profile, otherwise it just sets the control object-

Value

a data frame with results turned by fn by values in which.

See Also

biodyn,fit


rand

Description

Simulates a biodyn object for a catch series, given the parameter estimates in the param slot and variance covariance matrix http://young.physics.ucsc.edu/jackboot.pdf

Usage

randFn(n, object, sim)

Arguments

n

numeric with number of simulations

object

biodyn

sim

a biodyn object

...

other arguments

Value

biodyn with estimates of stock based on catch time series

Examples

## Not run: 
#simulate an object with known properties
bd=sim()
bd=window(bd,end=49)

#simulate a proxy for stock abundance
cpue=(stock(bd)[,-dims(bd)$year]+stock(bd)[,-1])/2
cpue=rlnorm(1,log(cpue),.2)

#set parameters
setParams(bd) =cpue
setControl(bd)=params(bd)
control(bd)[3:4,"phase"]=-1

#fit
bd=fit(bd,cpue)

bdJK=fit(bd,jackknife(cpue))


bdRnd  =rand(100,bd,bdJK)

plot(rand(100,stock(bd)[,40:45],stock(bdJK)[,40:45]))

## End(Not run)

randJack

Description

Simulates a biodyn object for a catch series, given the parameter estimates in the param slot and variance covariance matrix http://young.physics.ucsc.edu/jackboot.pdf

Usage

randJackFn(n, object, sim)

Arguments

n

numeric with number of simulations

object

biodyn

sim

a biodyn object

...

other arguments

Value

biodyn with estimates of stock based on catch time series

Examples

## Not run: 
#simulate an object with known properties
bd=sim()
bd=window(bd,end=49)

#simulate a proxy for stock abundance
cpue=(stock(bd)[,-dims(bd)$year]+stock(bd)[,-1])/2
cpue=rlnorm(1,log(cpue),.2)

#set parameters
setParams(bd) =cpue
setControl(bd)=params(bd)
control(bd)[3:4,"phase"]=-1

#fit
bd=fit(bd,cpue)

bdJK=fit(bd,jackknife(cpue))


bdRnd  =randJack(100,bd,bdJK)

plot(randJack(100,stock(bd)[,40:45],stock(bdJK)[,40:45]))

## End(Not run)

readAspic

Description

Read ASPIC text files, either inp for inputs, or output files, produced by the executable version of ASPIC

Usage

readAspic(object, ...)

Arguments

object

an file path

...

any other parameter

See Also

readFLStock, writeAspic

Examples

## Not run: 
    readAspic("aspic.inp")
## End(Not run)

Calculate Rebuild Trajectories

Description

Projects stock rebuilding trajectories from different initial depletion levels

Usage

rebuild(
  object,
  target = NULL,
  nInitial = 100,
  growthRate = 0.25,
  minVal = 1e-06,
  maxVal = 1,
  burnin = 20,
  truncate = TRUE,
  ...
)

Arguments

object

A biodyn object

target

Target biomass (default = BMSY)

nInitial

Number of initial depletion levels (default = 100)

growthRate

Growth rate for depletion sequence (default = 0.3)

minVal

Minimum depletion value (default = 1e-6)

maxVal

Maximum depletion value (default = 1)

nx

Number of interpolation points (default = 101)

Value

A data frame with columns:

year

Projection year

initial

Initial depletion level relative to BMSY

Examples

bd=biodyn(FLPar(r=0.5, k=1000, p=1))
rebuild_data=rebuild(bd)

msy reference points

Description

Calculates maximum sustainable yield (MSY) reference points given the model parameters, for yield, biomass and harvest rate

Calculates msy based reference points

Usage

refptSD(object, params, ...)

## S4 method for signature 'biodyn'
msy(x, ...)

Arguments

object

an object of class biodyn or FLPar with Pella-Tomlinson production function parameters

...

any other parameters

object

a biodyn object

Value

an FLPar object with benchmark

an FLPar object with an estimate for $msy$

Examples

## Not run:  msy('logistic',FLPar(msy=100,k=500))
  
## Not run: 
 msy(bd)
 
## End(Not run)

resample

Description

Resamples from a distribution to generate a frequency table

Resamples from a distribution to generate a frequency table

Usage

## S4 method for signature 'FLQuant'
resample(x, dim = 2:6, size, replace = T, ...)

## S4 method for signature 'FLQuant'
resample(x, dim = 2:6, size, replace = T, ...)

Arguments

dim

dimensions of FLQuant to sample within, i.e. if equal to 2 then sampling is within year

size

sum of frequency disribution

replace

sample with replacement?, defaults to FALSE only useful if values in object are integers

...

any other parameters

object

an FLQuant

Value

a FLQuant with simulated frequency distribution

a FLQuant with simulated frequency distribution

Examples

## Not run: 
  library(FLCore)
  data(ple4sex)
  
  apply(resample(catch.n(ple4sex)[,1:4],2,  100),2,  sum)
  apply(resample(catch.n(ple4sex)[,1:4],2:3,100),2:3,sum)
  apply(resample(catch.n(ple4sex)[,1:4],1:2,100),1:2,sum)
  
## End(Not run)
## Not run: 
  library(FLCore)
  data(ple4sex)
  
  apply(resample(catch.n(ple4sex)[,1:4],2,  100),2,  sum)
  apply(resample(catch.n(ple4sex)[,1:4],2:3,100),2:3,sum)
  apply(resample(catch.n(ple4sex)[,1:4],1:2,100),1:2,sum)
  
## End(Not run)

setControl<-

Description

Sets the control slot in a biodyn object given the parameters in the params slot. The starting values val are set to those in params and the min and max bounds to .1 and 10 times these.

Usage

## S4 replacement method for signature 'biodyn,FLPar'
setControl(object, min = 0.1, max = 10) <- value

Arguments

object

an object of class biodyn

value

params object

...

any other parameter

See Also

controlFn

Examples

## Not run: 
bd=sim()
setControl(bd)=params(bd)

## End(Not run)

setParams<-

Description

Sets catchability q and CV sigma in the params FLPar slot for CPUE provided either an FLQuant or FLQuants

Usage

setParams(object) <- value

Arguments

object

biodyn

value

CPUE as FLQuant or FLQuants

Details

setParams<-

Examples

## Not run: 
setParams(bd)=cpue

## End(Not run)

sim

Description

Creates a biodyn object with known properties

Usage

## S4 method for signature 'missing,missing'
sim(
  params = FLPar(r = 0.5, k = 1000, p = 1, b0 = 1),
  harvest = FLQuant(c(seq(0, 1.5, length.out = 30), rev(seq(0.5, 1.5, length.out =
    15))[-1], rep(0.5, 5)) * (params["r"] * (1/(1 + params["p"])))),
  bounds = c(0.1, 10),
  p = NULL,
  b0 = NULL,
  ...
)

Arguments

params

surplus production parameters

harvest

FLQuant with harvest rate

bounds

on control

...

other arguments

model

character corresponding to model

Value

biodyn object with simulated time series

Examples

## Not run: 
 bd=sim() 
 
## End(Not run)

tac ,

Description

Calculates the Total Allowable Catch for a biodyn object and target harvest rate by projecting the last year.

Usage

## S4 method for signature 'biodyn'
tac(object, harvest, ...)

Arguments

object

an object of class biodyn or

harvest

an FLQuant object with harvest rate

...

other arguments

Value

FLQuant object with TAC value(s)

Examples

## Not run: 
tac(bd,FLQuant(0.1,dimnames=list(year=dims(bd)$maxyear)))

## End(Not run)

ts

Description

calculates time series of quantities useful for management

Usage

## S4 method for signature 'FLStock,FLPar'
timeSeries(object, params, df = TRUE)

Arguments

object

either FLStock biodyn or aspic classes


writeAspic

Description

Writes the ASPIC text input file inp to a file or connection. The executable version of ASPIC uses an input file, this method generates that file

Usage

writeAspic(object, ...)

Arguments

object

an apic object

...

any other parameter

See Also

writeFLStock, readAspic

Examples

## Not run: 
    writeAspic(albn,"aspic.inp")
## End(Not run)

xval

Description

Performs a cross-validation uisng a hindcast

Usage

## S4 method for signature 'biodyn,ANY'
xval(
  object,
  index,
  minyear = range(object)["maxyear"] - 4,
  maxyear = range(object)["maxyear"]
)

Arguments

object

an object of class biodyn

index

an FLQuant or FLQuants with index of relative stock abundance

minyear

last year to fit data to

maxyear

last year to project to, by default is the last year in the catch

Details

Returns a data.frame with index, year, obs and hat

Examples

## Not run: 
 data(bd)  

## End(Not run)

xval

Description

Performs a cross-validation uisng a hindcast

Usage

## S4 method for signature 'biodyn,missing'
xval(
  object,
  minyear = range(object)["maxyear"] - 4,
  maxyear = range(object)["maxyear"]
)

Arguments

object

an object of class biodyn

minyear

last year to fit data to

maxyear

last year to project to, by default is the last year in the catch

index

an FLQuant or FLQuants with index of relative stock abundance

Details

xval

Returns a data.frame with index, year, obs and hat

Examples

## Not run: 
 data(bd)  

## End(Not run)