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.4
Built: 2026-10-24 06:16:26 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)

Convert a biodyn to a cmpAssess

Description

Biomass, harvest rate and catch from the biodyn, reference points from mpb::refpts and the Pella-Tomlinson parameters, index fits and residuals from the diags slot. The fitted index is q(Bt+Bt+1)/2q(B_t+B_{t+1})/2 for every catch year, so a peel whose catch has been projected one year beyond the last index observation provides a one-step-ahead prediction for hindcasting. JABBA fits can be converted with jabba2cmp, or via jabba2biodyn.

Usage

biodyn2cmp(object, name = "biodyn", peels = NULL)

Arguments

object

a biodyn

name

method label

peels

optional named list of biodyn fitted to truncated data

Value

a cmpAssess


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)

Autocorrelation of residuals for one or more assessments

Description

Autocorrelation of residuals for one or more assessments

Usage

cmpACF(x, type = c("resid", "process"), lag.max = 15)

Arguments

x

a cmpAssess or a named list of them

type

"resid" (observation) or "process" residuals

lag.max

maximum lag

Value

a ggplot


Common assessment summary for comparing methods

Description

A cmpAssess is a list holding the outputs of an assessment in a method-agnostic form, so that the cmp* plotting functions can compare assessments from different methods. Converters are spict2cmp, flbrp2cmp, biodyn2cmp and jabba2cmp.

Usage

cmpAssess(
  name,
  ts,
  lower = NULL,
  upper = NULL,
  refpts = NULL,
  index = NULL,
  resid = NULL,
  process = NULL,
  curve = NULL,
  prior = NULL,
  peels = NULL
)

Arguments

name

label for the method, used in legends

ts

FLQuants of annual values with (some of) stock (biomass at the start of the year), harvest, catch, bbmsy and ffmsy; uncertainty can be held as iters

lower, upper

optional FLQuants of lower and upper confidence limits, with the same names as ts

refpts

FLPar or named numeric with (some of) bmsy, fmsy, msy, k, r and n (Pella-Tomlinson shape, with n=p+1n=p+1)

index

data.frame of observations and fits with columns series, year, obs, hat and optionally lower, upper. hat may extend beyond the last observation (one-step-ahead prediction) for hindcasting

resid

data.frame of observation (e.g. one-step-ahead) residuals with columns series, year, residual; by default log⁡(obs/hat)\log(obs/hat) from index

process

data.frame of process residuals, columns as resid; by default log⁡(Bt+1/(Bt+P(Bt)−Ct))\log(B_{t+1}/(B_t+P(B_t)-C_t)) with PP interpolated from curve

curve

data.frame with columns stock and yield, the production function (or equilibrium yield curve)

prior

data.frame of priors and posteriors, either densities (parameter, what, x, density, with density of log⁡(x)\log(x)) or draws (parameter, what, value); what is "Prior" or "Posterior"

peels

named list of cmpAssess for retrospective peels, names are the terminal years

Value

an object of class cmpAssess


Observed and fitted values of one or more assessments

Description

Observations (points) and fits (lines, with ribbons when available) for each series in the index element, coloured by method.

Usage

cmpFit(x, series = NULL)

Arguments

x

a cmpAssess or a named list of them

series

optional subset of series to plot

Value

a ggplot


Hindcast cross-validation of one or more assessments

Description

Observations, the fits of each retrospective peel, and the hh-year-ahead hindcast predictions with their confidence intervals, with the MASE (see cmpMASE) annotated per method and series.

Usage

cmpHindcast(x, h = 1, nyears = 10, series = NULL)

Arguments

x

a cmpAssess or a named list of them

h

prediction horizon in years

nyears

number of years shown before the first hindcast year

series

optional subset of series

Value

a ggplot


Hindcast predictions from retrospective peels

Description

For each peel with terminal year TT, takes the prediction of each series hh years ahead (T+hT+h) from the peel's index element, and the observation for that year and the naive prediction (the observation in year TT) from the full run.

Usage

cmpHindcastDF(x, h = 1)

Arguments

x

a cmpAssess or a named list of them

h

prediction horizon in years

Value

a data.frame with columns method, series, peel (terminal year), year, obs, pred, lower, upper and naive


Kobe phase plot for one or more assessments

Description

Trajectories of B/BMSYB/B_{MSY} against F/FMSYF/F_{MSY} by method on the red/yellow/green quadrants, with the terminal year and its 95% confidence intervals as crosshairs.

Usage

cmpKobe(x, xlim = NULL, ylim = NULL, path = TRUE)

Arguments

x

a cmpAssess or a named list of them

xlim, ylim

axis limits; default from the data

path

draw the trajectories

Value

a ggplot


Mean absolute scaled error

Description

MASE of hindcast predictions relative to a naive (random walk) prediction, on the log scale by default. MASE < 1 means the model predicts better than the naive prediction.

Usage

cmpMASE(obs, pred, naive, log = TRUE)

Arguments

obs

observations

pred

model predictions

naive

naive predictions (e.g. the last observation)

log

calculate errors on the log scale

Value

numeric


Prior and posterior densities for one or more assessments

Description

Plots the prior element of each assessment. Densities are of log⁡(θ)\log(\theta), plotted against θ\theta on a log axis; draws are converted to densities of log⁡(θ)\log(\theta). Priors are dashed and posteriors solid, coloured by method.

Usage

cmpPriors(x, parameters = NULL)

Arguments

x

a cmpAssess or a named list of them

parameters

optional subset of parameters

Value

a ggplot


Process residuals with runs tests for one or more assessments

Description

Process residuals with runs tests for one or more assessments

Usage

cmpProcess(x, ncol = NULL)

Arguments

x

a cmpAssess or a named list of them

ncol

number of panel columns

Value

a ggplot


Production functions of one or more assessments

Description

The production function (or equilibrium yield curve) of each method, with the realised surplus production SPt=Bt+1−Bt+CtSP_t=B_{t+1}-B_t+C_t computed from its biomass and catch, and the MSY point.

Usage

cmpProduction(x, points = TRUE)

Arguments

x

a cmpAssess or a named list of them

points

show realised surplus production

Value

a ggplot


Normal QQ plot of residuals for one or more assessments

Description

Normal QQ plot of residuals for one or more assessments

Usage

cmpQQ(x, type = c("resid", "process"))

Arguments

x

a cmpAssess or a named list of them

type

"resid" (observation) or "process" residuals

Value

a ggplot


Retrospective analysis of one or more assessments

Description

Peels of each method (peels element), with the confidence interval of the full run and Mohn's rho annotated per method.

Usage

cmpRetro(x, quants = c("bbmsy", "ffmsy"))

Arguments

x

a cmpAssess or a named list of them; methods without peels are dropped

quants

quantities to plot

Value

a ggplot


Observation residuals with runs tests for one or more assessments

Description

Residuals (e.g. one-step-ahead for SPiCT, log(obs/hat) otherwise) with the 3-sigma band shaded green if the runs test is passed and red if not; points outside the band are outlined in red. One panel per method and series.

Usage

cmpRuns(x, ncol = NULL)

Arguments

x

a cmpAssess or a named list of them

ncol

number of panel columns

Value

a ggplot


Stock status of one or more assessments

Description

B/BMSYB/B_{MSY} and F/FMSYF/F_{MSY} with confidence intervals.

Usage

cmpStatus(x, ci = TRUE)

Arguments

x

a cmpAssess or a named list of them

ci

show confidence intervals

Value

a ggplot


Time series of one or more assessments

Description

Annual estimates with 95% confidence intervals (ribbons), coloured by method. Dashed lines are the reference points (BMSYB_{MSY}, FMSYF_{MSY}, MSY, or 1 for the ratios) of each method.

Usage

cmpTS(x, quants = c("stock", "harvest", "catch"), refs = TRUE, ci = TRUE)

Arguments

x

a cmpAssess or a named list of them

quants

quantities to plot, from stock, harvest, catch, bbmsy, ffmsy

refs

show reference points

ci

show confidence intervals

Value

a ggplot


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
)

Convert an age-structured assessment (FLStock and FLBRP) to a cmpAssess

Description

Biomass is spawning stock or exploitable biomass, F is either the harvest rate (catch/biomass, comparable with biomass dynamic models) or Fˉ\bar F, and the reference points and equilibrium yield curve come from the FLBRP. rr and nn are the Pella-Tomlinson parameters with the same MSY, BMSYB_{MSY} and KK (if FLRebuild is available). Iters in the FLStock give CIs.

Usage

flbrp2cmp(
  stk,
  brp,
  name = "FLBRP",
  biomass = c("eb", "ssb"),
  harvest = c("hr", "fbar"),
  index = NULL
)

Arguments

stk

an FLStock

brp

an FLBRP for the same stock

name

method label

biomass

"eb" (exploitable biomass, needs FLRebuild) or "ssb"

harvest

"hr" for catch/biomass or "fbar"

index

optional FLQuant of observations; its fit is qBtqB_t with qq the geometric mean of index/biomass

Value

a cmpAssess


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,
  timing = 0,
  ...
)

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)

Coerce a JABBA fit to a biodyn

Description

Coerce a JABBA fit to a biodyn

Usage

jabba2biodyn(
  object,
  phase = c(b0 = -1, r = 4, k = 3, p = -2, q = 2, sigma = 1),
  min = 0.1,
  max = 10
)

Arguments

object

a JABBA fit (list returned by JABBA::fit_jabba).

phase

named vector of estimation phases.

min, max

multipliers for the parameter bounds.

Value

a biodyn.


Convert a JABBA fit to a cmpAssess

Description

Uses the timeseries (posterior median and 95% CIs of B, F, B/BMSYB/B_{MSY} and F/FMSYF/F_{MSY}), estimates, diags (index fits and residuals), pfunc (production function), timeseries[, , "procB"] (process deviations) and pars_posterior elements of a JABBA::fit_jabba result. Priors for rr, KK and ψ\psi are taken from the JABBA input when available (log-normal, as c(mean, log sd)).

Usage

jabba2cmp(object, name = "JABBA")

Arguments

object

a JABBA fit, or a list with elements fit and input as returned by FLRebuild::runJABBA

name

method label

Value

a cmpAssess


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)

Mohn's rho

Description

Mean relative difference between the terminal-year estimate of each retrospective peel and the estimate for the same year in the reference (full) run.

Usage

mohnsRho(ref, peels)

Arguments

ref

FLQuant from the full run

peels

list of FLQuant, one per peel

Value

numeric


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)

Plots of a SPiCT fit

Description

Wrappers that convert a SPiCT fit with spict2cmp and call the generic comparison plots: plotSpictTS (cmpTS), plotSpictStatus (cmpStatus), plotSpictKobe (cmpKobe), plotSpictProduction (cmpProduction), plotSpictFit (cmpFit), plotSpictRuns (cmpRuns, one-step-ahead residuals), plotSpictProcess (cmpProcess), plotSpictACF (cmpACF), plotSpictQQ (cmpQQ), plotSpictRetro (cmpRetro), plotSpictHindcast (cmpHindcast) and plotSpictPriors (cmpPriors). The retrospective and hindcast use spict::retro, run if fit$retro is missing. OSA and process residuals are calculated if missing.

Usage

plotSpictTS(fit, scale = 1, ...)

plotSpictStatus(fit, ...)

plotSpictKobe(fit, ...)

plotSpictProduction(fit, scale = 1, ...)

plotSpictFit(fit, scale = 1, ...)

plotSpictRuns(fit, ...)

plotSpictProcess(fit, ...)

plotSpictACF(fit, type = c("resid", "process"), ...)

plotSpictQQ(fit, type = c("resid", "process"), ...)

plotSpictRetro(fit, nretroyear = 5, ...)

plotSpictHindcast(fit, nretroyear = 5, ...)

plotSpictPriors(fit, ...)

Arguments

fit

a fitted SPiCT object

scale

multiplier for biomass and catch

...

passed to the generic plot

type

"resid" (one-step-ahead) or "process"

nretroyear

number of peels if spict::retro has to be run

Value

a ggplot


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

rebuildTime(
  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)

Runs test on residuals

Description

Runs test for randomness and 3-sigma limits, as in ss3diags::ssruns_sig3, implemented here so that it does not depend on any assessment package.

Usage

runsTest(x, mixing = "less")

Arguments

x

residuals

mixing

alternative hypothesis, "less" tests for too few runs (positive autocorrelation)

Value

a list with p (runs test p-value) and lim (3-sigma limits)


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)

SPiCT helpers: priors from an FLBRP, input from an FLStock, coercion to biodyn, process-error diagnostics and recovery at zero catch

Description

Functions used by the spict vignette to fit SPiCT to an FLStock with priors from the equilibrium reference points of an FLBRP, and to compare the fit with the age-structured model. spict, FLRebuild, ggplot2 and patchwork are suggested packages and are checked when needed.

Usage

spictPar(fit, nm, i = 1)

spictPriors(
  stk,
  brp,
  quant = c("eb", "ssb"),
  cv = c(r = 0.3, K = 0.5, n = 0.3, psi = 0.3),
  scale = 1
)

spictInp(
  stk,
  brp,
  quant = c("eb", "ssb"),
  scale = 1000,
  dteuler = 1/4,
  cv = c(r = 0.3, K = 0.5, n = 0.3, psi = 0.3),
  sdi = c(0.1, 0.5)
)

spict2biodyn(fit, scale = 1)

spictPrd(fit, xMax = 1.3, nX = 200)

prdResid(B, C, year, pFn)

plotPE(dat, cols = NULL)

recoverBD(par, nyr = 50, b0 = 0.3)

Arguments

fit

a fitted SPiCT object (class spictcls).

nm

parameter name, e.g. "logr", "logBBmsy".

i

row (time step) to return.

stk

an FLStock.

brp

an FLBRP for stk, e.g. from FLRebuild::eql.

quant

biomass the biomass dynamic model represents, exploitable ("eb") or spawning ("ssb") biomass.

cv

CVs of the log-normal priors on r, K, n and initial depletion.

scale

divisor for biomass and catch (e.g. 1000 for thousand tonnes).

dteuler

Euler time step.

sdi

mean and log-scale SD of the prior on the index observation SD; NULL for none. An assessment-derived index has almost no observation error, so without a prior sdi collapses towards zero.

xMax, nX

range (relative to K) and number of points for the curve.

B, C, year

biomass, catch and year vectors.

pFn

production function of biomass, pFn(B).

dat

data.frame with year, b, rsdl and source.

cols

optional named vector of colours by source.

par

FLPar with r, k and p.

nyr

number of years to project.

b0

starting biomass relative to BMSY.

Value

spictPar: numeric vector of estimate and CV.

spictPriors: list with the Pella-Tomlinson parameters (pars), initial depletion (psi), a summary table (table) and SPiCT prior vectors (priors).

spictInp: a checked SPiCT input list.

spict2biodyn: a biodyn with r, K, p=n-1 and b0 from the fit, and the catch, index and annual SPiCT biomass, rescaled by scale.

spictPrd: list with the production curve (pf) and the annual trajectory (traj: year, b, bRel, sp, rsdl). Residuals are SPiCT process residuals rescaled to annual log deviations.

prdResid: data.frame with year, b, sp and rsdl, the log deviation of B[t+1] from a one-year step B[t]+pFn(B[t])-C[t].

plotPE: a patchwork of four ggplots.

recoverBD: data.frame of year and B/BMSY.

Functions

  • spictPar(): Estimate and CV of a SPiCT parameter

  • spictPriors(): Pella-Tomlinson priors for SPiCT from an FLBRP

  • spictInp(): SPiCT input from an FLStock, with priors from an FLBRP

  • spict2biodyn(): Coerce a SPiCT fit to a biodyn

  • spictPrd(): Production curve, realised surplus production and process residuals from a SPiCT fit

  • prdResid(): Realised surplus production and process residuals for a biomass and catch series and a production function

  • plotPE(): Four-panel process-error diagnostic (over time, against biomass, autocorrelation and distribution), as used at WKBMSYSPiCT4

  • recoverBD(): Recovery at zero catch from a fraction of BMSY


Convert a SPiCT fit to a cmpAssess

Description

Uses only the exported SPiCT API (spict::get.par) and the inp, osar, process.resid and retro elements of the fit. Biomass and F are at the start of each year; B/BMSYB/B_{MSY} and F/FMSYF/F_{MSY} are the SPiCT estimates (with their own CIs); the reference points are the deterministic ones. The index fit is qBtqB_t, extended one year past the last observation for hindcasting. Retrospective peels are taken from fit$retro (see spict::retro).

Usage

spict2cmp(
  fit,
  name = "SPiCT",
  scale = 1,
  process = c("spict", "generic"),
  peels = TRUE
)

Arguments

fit

a fitted SPiCT object (class spictcls)

name

method label

scale

multiplier for biomass, catch and index (e.g. 1000 if the fit is in thousand tonnes)

process

"spict" to use fit$process.resid (B and F), "generic" for residuals from the production function

peels

convert retrospective peels if present

Value

a cmpAssess


Coerce a SPiCT fit to FLQuants

Description

Returns annual estimates of biomass, F, catch, B/BMSYB/B_{MSY} and F/FMSYF/F_{MSY} as FLQuants. If iter is given the uncertainty is represented by independent log-normal draws in each year (using the SPiCT standard errors on the log scale), so that ggplotFL::plot() shows median and ribbons.

Usage

spict2FLQuants(
  fit,
  quants = c("B", "F", "Catch", "BBmsy", "FFmsy"),
  iter = NULL,
  seed = 1234
)

Arguments

fit

a fitted SPiCT object

quants

quantities to return, see spictTS

iter

number of iterations; NULL returns the point estimates

seed

random seed used when iter is set

Value

FLQuants


Time series of a SPiCT fit as a data.frame

Description

Extracts annual (start of year) estimates and 95% confidence intervals of biomass, fishing mortality, catch and the MSY ratios from a SPiCT fit.

Usage

spictTS(fit, quants = c("B", "F", "Catch", "BBmsy", "FFmsy"))

Arguments

fit

a fitted SPiCT object (class spictcls)

quants

which quantities, any of "B", "F", "Catch", "BBmsy", "FFmsy"

Value

a data.frame with columns qname, year, data (estimate), lower, upper and sd (log scale)


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)