Title: | Core Package of FLR, Fisheries Modelling in R |
---|---|
Description: | Core classes and methods for FLR, a framework for fisheries modelling and management strategy simulation in R. Developed by a team of fisheries scientists in various countries. More information can be found at <http://flr-project.org/>. |
Authors: | Iago Mosqueira [cre] , Laurence T. Kell [aut], Philippe Grosjean [aut] |
Maintainer: | Iago Mosqueira <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.6.20.9308 |
Built: | 2024-11-14 23:23:03 UTC |
Source: | https://github.com/flr/FLCore |
Arithmetic operations between two FLQuant objects using the
standars operators (+
, -
, *
, /
, ^
, see Arith) need all
dimensions in both objects to match. This requirement is relaxed by using
the percent version of those five operators: %+%
, %-%
, %*%
, %/%
and
%^%
.
e1 %+% e2 x %-% y x %^% y ## S4 method for signature 'FLQuant,FLQuant' x %*% y ## S4 method for signature 'FLQuant,FLQuant' e1 %/% e2 ## S4 method for signature 'FLQuant,FLQuant' e1 %+% e2 ## S4 method for signature 'FLQuant,FLQuant' x %-% y ## S4 method for signature 'FLQuant,FLQuant' x %^% y ## S4 method for signature 'FLPar,FLQuant' x %*% y ## S4 method for signature 'FLPar,FLQuant' e1 %/% e2 ## S4 method for signature 'FLPar,FLQuant' e1 %+% e2 ## S4 method for signature 'FLPar,FLQuant' x %-% y ## S4 method for signature 'FLPar,FLQuant' x %^% y ## S4 method for signature 'FLQuant,FLPar' x %*% y ## S4 method for signature 'FLQuant,FLPar' e1 %/% e2 ## S4 method for signature 'FLQuant,FLPar' e1 %+% e2 ## S4 method for signature 'FLQuant,FLPar' x %-% y ## S4 method for signature 'FLQuant,FLPar' x %^% y ## S4 method for signature 'FLPar,FLPar' x %*% y ## S4 method for signature 'FLPar,FLPar' e1 %+% e2 ## S4 method for signature 'FLPar,FLPar' x %-% y ## S4 method for signature 'FLPar,FLPar' e1 %/% e2 ## S4 method for signature 'FLPar,FLPar' x %^% y ## S4 method for signature 'FLQuants,FLPar' e1 / e2 ## S4 method for signature 'FLQuants,FLPar' e1 * e2 ## S4 method for signature 'FLQuants,FLPars' e1 / e2 ## S4 method for signature 'FLQuants,FLPars' e1 * e2 ## S4 method for signature 'FLQuants,FLQuants' e1 / e2 ## S4 method for signature 'FLQuants,FLQuants' e1 * e2 ## S4 method for signature 'FLQuants,FLQuants' e1 + e2 ## S4 method for signature 'FLQuants,FLQuants' e1 - e2
e1 %+% e2 x %-% y x %^% y ## S4 method for signature 'FLQuant,FLQuant' x %*% y ## S4 method for signature 'FLQuant,FLQuant' e1 %/% e2 ## S4 method for signature 'FLQuant,FLQuant' e1 %+% e2 ## S4 method for signature 'FLQuant,FLQuant' x %-% y ## S4 method for signature 'FLQuant,FLQuant' x %^% y ## S4 method for signature 'FLPar,FLQuant' x %*% y ## S4 method for signature 'FLPar,FLQuant' e1 %/% e2 ## S4 method for signature 'FLPar,FLQuant' e1 %+% e2 ## S4 method for signature 'FLPar,FLQuant' x %-% y ## S4 method for signature 'FLPar,FLQuant' x %^% y ## S4 method for signature 'FLQuant,FLPar' x %*% y ## S4 method for signature 'FLQuant,FLPar' e1 %/% e2 ## S4 method for signature 'FLQuant,FLPar' e1 %+% e2 ## S4 method for signature 'FLQuant,FLPar' x %-% y ## S4 method for signature 'FLQuant,FLPar' x %^% y ## S4 method for signature 'FLPar,FLPar' x %*% y ## S4 method for signature 'FLPar,FLPar' e1 %+% e2 ## S4 method for signature 'FLPar,FLPar' x %-% y ## S4 method for signature 'FLPar,FLPar' e1 %/% e2 ## S4 method for signature 'FLPar,FLPar' x %^% y ## S4 method for signature 'FLQuants,FLPar' e1 / e2 ## S4 method for signature 'FLQuants,FLPar' e1 * e2 ## S4 method for signature 'FLQuants,FLPars' e1 / e2 ## S4 method for signature 'FLQuants,FLPars' e1 * e2 ## S4 method for signature 'FLQuants,FLQuants' e1 / e2 ## S4 method for signature 'FLQuants,FLQuants' e1 * e2 ## S4 method for signature 'FLQuants,FLQuants' e1 + e2 ## S4 method for signature 'FLQuants,FLQuants' e1 - e2
If any of the objects is of length one in a dimensions where the other is longer, the dimensions will be extended and the element-by-element operation then conducted. Dimensions and dimnames of the output will be those of the larger object. See the examples to observe their behaviour.
Please note that this behaviour is already present on the Arith
methods for FLArray-derived classes but only on the 6th,
iter
, dimension.
The original use of the %*%
operator, as vector product, is not available
for FLQuant objects, but can be applied to the array
inside them, as in the example below.
Methods for operations between an FLQuant and an FLPar object will match dimensions by names of dimnames, regardless of position.
x %+% y, x %-% y, x %*% y, e1 %/% e2, x %^% y
The FLR Team
a <- FLQuant(2, dim=c(3,3,2)) b <- FLQuant(3, dim=c(3,3,1)) # This should fail ## Not run: a * b a %*% b a %+% b # To use base's %*% vector product, apply it to a matrix from @.Data [email protected][,,,,,] %*% 1:3 # or b[,,drop=TRUE] %*% 1:3 # FLPar vs. FLQuant works by dimnames' names flp <- FLPar(2, dimnames=list(params='a', year=2000:2005, iter=1)) flq <- FLQuant(3, dimnames=list(year=2000:2005)) flp %*% flq # Divide each FLQuants element by a 'param' in FLPar, e.g. time series # divide by reference points FLQuants(SSB=FLQuant(2303), F=FLQuant(0.8)) / FLPar(SSB=1560, F=0.4) # Product of each FLQuants element by a 'param' in FLPar FLQuants(SSB=FLQuant(2303), F=FLQuant(0.8)) * FLPar(SSB=1560, F=0.4) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(2303), B=FLQuant(1287)) / FLPars(A=FLPar(SBMSY=1560), B=FLPar(SBMSY=1000)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(2303), B=FLQuant(1287)) * FLPars(A=FLPar(SBMSY=1560), B=FLPar(SBMSY=1000)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(300), B=FLQuant(200)) / FLQuants(A=FLQuant(3), B=FLQuant(2)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(100), B=FLQuant(200)) * FLQuants(A=FLQuant(3), B=FLQuant(2)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(100), B=FLQuant(200)) * FLQuants(A=FLQuant(3), B=FLQuant(2)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(100), B=FLQuant(200)) * FLQuants(A=FLQuant(3), B=FLQuant(2))
a <- FLQuant(2, dim=c(3,3,2)) b <- FLQuant(3, dim=c(3,3,1)) # This should fail ## Not run: a * b a %*% b a %+% b # To use base's %*% vector product, apply it to a matrix from @.Data b@.Data[,,,,,] %*% 1:3 # or b[,,drop=TRUE] %*% 1:3 # FLPar vs. FLQuant works by dimnames' names flp <- FLPar(2, dimnames=list(params='a', year=2000:2005, iter=1)) flq <- FLQuant(3, dimnames=list(year=2000:2005)) flp %*% flq # Divide each FLQuants element by a 'param' in FLPar, e.g. time series # divide by reference points FLQuants(SSB=FLQuant(2303), F=FLQuant(0.8)) / FLPar(SSB=1560, F=0.4) # Product of each FLQuants element by a 'param' in FLPar FLQuants(SSB=FLQuant(2303), F=FLQuant(0.8)) * FLPar(SSB=1560, F=0.4) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(2303), B=FLQuant(1287)) / FLPars(A=FLPar(SBMSY=1560), B=FLPar(SBMSY=1000)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(2303), B=FLQuant(1287)) * FLPars(A=FLPar(SBMSY=1560), B=FLPar(SBMSY=1000)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(300), B=FLQuant(200)) / FLQuants(A=FLQuant(3), B=FLQuant(2)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(100), B=FLQuant(200)) * FLQuants(A=FLQuant(3), B=FLQuant(2)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(100), B=FLQuant(200)) * FLQuants(A=FLQuant(3), B=FLQuant(2)) # Divide each FLQuants element by each in FLPars FLQuants(A=FLQuant(100), B=FLQuant(200)) * FLQuants(A=FLQuant(3), B=FLQuant(2))
Catch curve estimates of total mortality at age (Z)
acc(object, ...)
acc(object, ...)
data(ple4)
data(ple4)
All S4 classes defined in FLCore have methods for accessing and replacing any of their slots. These methods are named as the slot, and will return the content of the slot, for the accessor method, or modify it with the provided value.
name(object, ...) desc(object, ...) range(x, i) <- value catch(object, ...) catch.n(object, ...) <- value catch.wt(object, ...) discards(object, ...) discards.n(object, ...) discards.wt(object, ...) landings(object, ...) landings.n(object, ...) landings.wt(object, ...) m(object, ...) stock(object, ...) stock.n(object, ...) stock.wt(object, ...) m.spwn(object, ...) harvest(object, catch, ...) harvest.spwn(object, ...) mat(object, ...) n(object, ...) m(object, ...) wt(object, ...) fec(object, ...) spwn(object, ...) effort(object, metier, ...) type(object, ...) distr(object, ...) distribution(object, ...) index(object, ...) index.var(object, ...) catch.n(object, ...) catch.wt(object, ...) sel.pattern(object, ...) index.q(object, ...) model(object, ...) logl(object, ...) gr(object, ...) initial(object, ...) logLik(object, ...) vcov(object, ...) <- value hessian(object, ...) logerror(object, ...) details(object, ...) residuals(object, ...) <- value fitted(object, ...) rec(object, ...) rec.obs(object, ...) catch.q(object, ...) discards.sel(object, ...) landings.sel(object, ...) params(object, ...) ## S4 replacement method for signature 'FLS,FLQuants' catch(object) <- value
name(object, ...) desc(object, ...) range(x, i) <- value catch(object, ...) catch.n(object, ...) <- value catch.wt(object, ...) discards(object, ...) discards.n(object, ...) discards.wt(object, ...) landings(object, ...) landings.n(object, ...) landings.wt(object, ...) m(object, ...) stock(object, ...) stock.n(object, ...) stock.wt(object, ...) m.spwn(object, ...) harvest(object, catch, ...) harvest.spwn(object, ...) mat(object, ...) n(object, ...) m(object, ...) wt(object, ...) fec(object, ...) spwn(object, ...) effort(object, metier, ...) type(object, ...) distr(object, ...) distribution(object, ...) index(object, ...) index.var(object, ...) catch.n(object, ...) catch.wt(object, ...) sel.pattern(object, ...) index.q(object, ...) model(object, ...) logl(object, ...) gr(object, ...) initial(object, ...) logLik(object, ...) vcov(object, ...) <- value hessian(object, ...) logerror(object, ...) details(object, ...) residuals(object, ...) <- value fitted(object, ...) rec(object, ...) rec.obs(object, ...) catch.q(object, ...) discards.sel(object, ...) landings.sel(object, ...) params(object, ...) ## S4 replacement method for signature 'FLS,FLQuants' catch(object) <- value
object |
The object from which a slot is to be extracted or replaced |
value |
Object to be inserted into the relevant slot |
Accessors and replacement methods, with some exception, are created at build
time by calls to the createFLAccessors
function. An accessor method is
created for each slot, with simply calls slot()
on the relevant slot
name. For slots of class FLQuant
, or FLArray
-based, two
methods are created: one if value
is of class FLQuant
, and
another for value
being a numeric vector. The later would insert the
vector into the slot structure, using R's recycling rules.
Users are encouraged to use the accessor methods, rather than the '@' operator
or the slot()
method, to isolate code from the internal structure of
the class. If a slot was to be altered or deleted in the future, a method
would be provided to return the same value, computed from other slots.
Some of these methods might already not access directly an slot, and instead carry out a calculation to return the requested value, depending on the class being called with. Please refer to the particular method implementation to see if this is the case.
Accessor methods for slots of class predictModel
behave
differently depending on the compute
argument. Please refer to the
relevant help page for further clarification.
An object of class FLQuants, containing three elements named
catch, catch.n and catch.wt, as returned by computeCatch
, can be
assigned directly to an object using catch<-.
The required slot, for an accessor method, or invisible modifies the object, for the replacement one.
The FLR Team
FLQuant
, FLStock
, FLIndex
,
FLBiol
, predictModel
data(ple4) # To access the catch slot in an FLStock, use catch(ple4) # while to modify it, do catch(ple4) <- catch(ple4) * 2 # A number can be used as input, to be recycled m(ple4) <- 0.3 # same as a longer vector, by age m(ple4) <- 0.4^(seq(1, 2, length=10)) # To see the methods defined by createFLAccessors, run, for example getMethod('catch', 'FLS') # Assign the 3 catch slots catch(ple4) <- computeCatch(ple4, slot="all")
data(ple4) # To access the catch slot in an FLStock, use catch(ple4) # while to modify it, do catch(ple4) <- catch(ple4) * 2 # A number can be used as input, to be recycled m(ple4) <- 0.3 # same as a longer vector, by age m(ple4) <- 0.4^(seq(1, 2, length=10)) # To see the methods defined by createFLAccessors, run, for example getMethod('catch', 'FLS') # Assign the 3 catch slots catch(ple4) <- computeCatch(ple4, slot="all")
An FLStock object is projected forward using the initial abundances and the total mortality-at-age per timestep. New values for the stock.n and catch.n slots are calculated, assuming that harvest and m are correct. This calculation provides a test of the internal consistency of the object.
## S4 method for signature 'FLStock' adjust(object)
## S4 method for signature 'FLStock' adjust(object)
object |
an |
FLStock
object
data(ple4) test <- adjust(ple4) # Difference in catch due to estimation error plot(FLStocks(PLE=ple4, TEST=test))
data(ple4) test <- adjust(ple4) # Difference in catch due to estimation error plot(FLStocks(PLE=ple4, TEST=test))
The optimal (or critical) age is the transition point when a cohort achieves its maximum biomass in the absemce of fishing, i.e. losses due to natural mortality are now greater than gains due to increase in individual biomass.
## S4 method for signature 'FLStock' ageopt(object)
## S4 method for signature 'FLStock' ageopt(object)
object |
An object of class 'FLStock' |
The age at which maximum biomass is reached, an 'FLQuant'.
The FLR Team
data(ple4) ageopt(ple4)
data(ple4) ageopt(ple4)
Akaike's information criterion (AIC) method
A method to calculate Akaike's 'An Information Criterion' (AIC) of an
FLModel object from the value of the obtained log-likelihood stored
in its logLik
slot.
## S4 method for signature 'FLModel,numeric' AIC(object, k = 2)
## S4 method for signature 'FLModel,numeric' AIC(object, k = 2)
object |
an FLModel object |
k |
the penalty per parameter to be used; the default 'k = 2' is the classical AIC. |
AIC(object, k)
The FLR Team
data(nsher) AIC(nsher)
data(nsher) AIC(nsher)
Method to append objects along the year dimensions, by extending, combining and substituting sections of them.
## S4 method for signature 'FLQuant,FLQuant' append(x, values, after = dims(values)$minyear - 1) ## S4 method for signature 'FLStock,FLStock' append(x, values, after = dims(values)$minyear - 1)
## S4 method for signature 'FLQuant,FLQuant' append(x, values, after = dims(values)$minyear - 1) ## S4 method for signature 'FLStock,FLStock' append(x, values, after = dims(values)$minyear - 1)
x |
the object to which the values are to be appended to. |
values |
to be included in the modified object. |
after |
a year dimname after with the values are to be appended. |
FLR objects are commonly manipulated along the year dimension, and the append method offers a simple interface for substituting parts of an object with another, or combine them into one, extending them when necessary. The object to be included or added to the first will be placed as defined by the year dimnames, unless the after input argument specifies otherwise.
Attributes like dimnames and units will always be taken from the first argument, unless the necessary chnages to dimnames$year
An object of the same class as x with values appended.
The FLR Team
# append(FLQuant, FLQuant) fq1 <- FLQuant(1, dimnames=list(age=1:3, year=2000:2010)) fq2 <- FLQuant(2, dimnames=list(age=1:3, year=2011:2012)) fq3 <- FLQuant(2, dimnames=list(age=1:3, year=2014:2016)) # Appends by dimnames$year append(fq1, fq2) # Appends by dimnames$year with gap (2011:2013) append(fq1, fq3) # Appends inside x append(fq1, fq2, after=2009) # Appends after end of x append(fq1, fq2, after=2013) # append(FLStock, FLStock) data(ple4) fs1 <- window(ple4, end=2001) fs2 <- window(ple4, start=2002) fs3 <- window(ple4, start=2005) # Appends by dimnames$year stock.n(append(fs1, fs2)) # Appends by dimnames$year with gap (2011:2013) stock.n(append(fs1, fs3)) # Appends inside x stock.n(append(fs1, fs3, after=2000)) # Appends after end of x stock.n(append(fs1, fs3, after=2005))
# append(FLQuant, FLQuant) fq1 <- FLQuant(1, dimnames=list(age=1:3, year=2000:2010)) fq2 <- FLQuant(2, dimnames=list(age=1:3, year=2011:2012)) fq3 <- FLQuant(2, dimnames=list(age=1:3, year=2014:2016)) # Appends by dimnames$year append(fq1, fq2) # Appends by dimnames$year with gap (2011:2013) append(fq1, fq3) # Appends inside x append(fq1, fq2, after=2009) # Appends after end of x append(fq1, fq2, after=2013) # append(FLStock, FLStock) data(ple4) fs1 <- window(ple4, end=2001) fs2 <- window(ple4, start=2002) fs3 <- window(ple4, start=2005) # Appends by dimnames$year stock.n(append(fs1, fs2)) # Appends by dimnames$year with gap (2011:2013) stock.n(append(fs1, fs3)) # Appends inside x stock.n(append(fs1, fs3, after=2000)) # Appends after end of x stock.n(append(fs1, fs3, after=2005))
Applies a function over the margins of an array-based FLCore class
## S4 method for signature 'FLArray,numeric,function' apply(X, MARGIN, FUN, ..., simplify = TRUE) ## S4 method for signature 'FLPar,ANY,ANY' apply(X, MARGIN, FUN, ..., simplify = TRUE) ## S4 method for signature 'FLQuantJK,numeric,function' apply(X, MARGIN, FUN, ..., simplify = TRUE) ## S4 method for signature 'FLParJK,numeric,function' apply(X, MARGIN, FUN, ..., simplify = TRUE)
## S4 method for signature 'FLArray,numeric,function' apply(X, MARGIN, FUN, ..., simplify = TRUE) ## S4 method for signature 'FLPar,ANY,ANY' apply(X, MARGIN, FUN, ..., simplify = TRUE) ## S4 method for signature 'FLQuantJK,numeric,function' apply(X, MARGIN, FUN, ..., simplify = TRUE) ## S4 method for signature 'FLParJK,numeric,function' apply(X, MARGIN, FUN, ..., simplify = TRUE)
These methods call R's base::apply on an FLArray the standard arithmetic operators included in the
Arith
group ("+", "-", "*", '"^", "%%", "%/%", and
"/"), so that they return an object of the appropriate class.
When the operation involves objects of two classes (e.g. FLPar
and FLQuant
),
the class is the returned object is that of the more complexs object, in this
case FLQuant
.
The FLR Team
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') flp <- FLPar(a=99) # FLQuant and numeric flq * 25 # Two FLQuant objects flq + flq
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') flp <- FLPar(a=99) # FLQuant and numeric flq * 25 # Two FLQuant objects flq + flq
Thorston, 2020.
ar1rlnorm( rho, years, iters = 1, meanlog = 0, sdlog = 1, bias.correct = TRUE, ... )
ar1rlnorm( rho, years, iters = 1, meanlog = 0, sdlog = 1, bias.correct = TRUE, ... )
rho |
Autocorrelation coefficient. |
years |
Vector of year names. |
iters |
Number of iterations. |
meanlog |
Mean of the series in log space. |
sdlog |
Marginal standard deviation in log space. |
bias.correct |
Should bias-correction be applied? Defaults to TRUE. |
An FLQuant object
Iago Mosqueira (WMR), Henning Winker (JRC).
Thorson, J. T. Predicting recruitment density dependence and intrinsic growth rate for all fishes worldwide using a data-integrated life-history model. Fish Fish. 2020; 21: 237– 251. https://doi-org.ezproxy.library.wur.nl/10.1111/faf.12427
devs <- ar1rlnorm(rho=0.6, years=2000:2030, iter=500, meanlog=0, sdlog=1) plot(devs)
devs <- ar1rlnorm(rho=0.6, years=2000:2030, iter=500, meanlog=0, sdlog=1) plot(devs)
Overloaded arithmetic operators for FLCore classes
## S4 method for signature 'numeric,FLArray' Arith(e1, e2) ## S4 method for signature 'FLArray,numeric' Arith(e1, e2) ## S4 method for signature 'FLArray,FLArray' Arith(e1, e2) ## S4 method for signature 'FLPar,FLPar' Arith(e1, e2) ## S4 method for signature 'FLArray,FLPar' Arith(e1, e2) ## S4 method for signature 'FLPar,FLArray' Arith(e1, e2)
## S4 method for signature 'numeric,FLArray' Arith(e1, e2) ## S4 method for signature 'FLArray,numeric' Arith(e1, e2) ## S4 method for signature 'FLArray,FLArray' Arith(e1, e2) ## S4 method for signature 'FLPar,FLPar' Arith(e1, e2) ## S4 method for signature 'FLArray,FLPar' Arith(e1, e2) ## S4 method for signature 'FLPar,FLArray' Arith(e1, e2)
These methods apply the standard arithmetic operators included in the
Arith
group ("+", "-", "*", "^", "%%", "%/%", and
"/"), so that they return an object of the appropriate class.
When the operation involves objects of two classes (e.g. FLPar
and FLQuant
),
the class is the returned object is that of the more complexs object, in this
case FLQuant
.
The FLR Team
methods::Arith base::Arithmetic
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') flp <- FLPar(a=99) # FLQuant and numeric flq * 25 # Two FLQuant objects flq + flq # FLQuant and FLPar flq / flp
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') flp <- FLPar(a=99) # FLQuant and numeric flq * 25 # Two FLQuant objects flq + flq # FLQuant and FLPar flq / flp
A single FLStock
can be coerced into a list with one or more objects of
class FLSR
, each of them typically set to a diefferemt stock-recruit model.
as.FLSRs(x, models = NULL, ...)
as.FLSRs(x, models = NULL, ...)
x |
An estimated FLStock object to coerce. |
models |
Name(s) of model(s) to fit. |
... |
Any extra arguments to be passed to as.FLSR. |
An objecdt of class FLSRs
FLR Team, 2023.
data(ple4) as.FLSRs(ple4, model=c("bevholt", "segreg"))
data(ple4) as.FLSRs(ple4, model=c("bevholt", "segreg"))
Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend odio ac rutrum luctus. Aenean placerat porttitor commodo. Pellentesque eget porta libero. Pellentesque molestie mi sed orci feugiat, non mollis enim tristique.
## S4 method for signature 'FLQuantJK' bias(x) ## S4 method for signature 'FLParJK' bias(x)
## S4 method for signature 'FLQuantJK' bias(x) ## S4 method for signature 'FLParJK' bias(x)
x |
An object holding estimates obtained through jackknife |
Details: Aliquam sagittis feugiat felis eget consequat. Praesent eleifend dolor massa, vitae faucibus justo lacinia a. Cras sed erat et magna pharetra bibendum quis in mi. Sed sodales mollis arcu, sit amet venenatis lorem fringilla vel. Vivamus vitae ipsum sem. Donec malesuada purus at libero bibendum accumsan. Donec ipsum sapien, feugiat blandit arcu in, dapibus dictum felis.
A value for the mean bias
The FLR Team
flq <- FLQuant(1:8) flj <- jackknife(flq) bias(flj)
flq <- FLQuant(1:8) flj <- jackknife(flq) bias(flj)
A method to calculate the Bayesian information criterion (BIC), also known
as Schwarz's Bayesian criterion of an FLModel object from the value
of the obtained log-likelihood stored in its logLik
slot.
## S4 method for signature 'FLModel' BIC(object)
## S4 method for signature 'FLModel' BIC(object)
object |
a fitted FLModel object for which there exists a 'logLik' method to extract the corresponding log-likelihood. |
BIC(object)
The FLR Team
data(nsher) BIC(nsher)
data(nsher) BIC(nsher)
This method plots three dimensional data such as matrices by age and year or
age-class, very common in fisheries. The area of each bubble is proportional
to the corresponding value in the matrix. Note that bubbles
accepts
an argument bub.scale
to control the relative size of the bubbles.
Positive and negative values have separate colours.
## S4 method for signature 'formula,FLQuant' bubbles(x, data, bub.scale = 2.5, col = c("blue", "red"), ...) ## S4 method for signature 'formula,data.frame' bubbles(x, data, bub.scale = 2.5, col = c("blue", "red"), ...) ## S4 method for signature 'formula,FLCohort' bubbles(x, data, bub.scale = 2.5, ...) ## S4 method for signature 'formula,FLQuants' bubbles(x, data, bub.scale = 2.5, bub.col = gray(c(0.1, 0.1)), ...)
## S4 method for signature 'formula,FLQuant' bubbles(x, data, bub.scale = 2.5, col = c("blue", "red"), ...) ## S4 method for signature 'formula,data.frame' bubbles(x, data, bub.scale = 2.5, col = c("blue", "red"), ...) ## S4 method for signature 'formula,FLCohort' bubbles(x, data, bub.scale = 2.5, ...) ## S4 method for signature 'formula,FLQuants' bubbles(x, data, bub.scale = 2.5, bub.col = gray(c(0.1, 0.1)), ...)
bubbles(x, data)
The FLR Team
lattice, FLQuant
,
FLQuants
,FLCohort
data(ple4) bubbles(age~year, data=catch.n(ple4)) bubbles(age~year, data=catch.n(ple4), bub.scale=5) bubbles(age~cohort, data=FLCohort(catch.n(ple4)), bub.scale=5) qt01 <- log(catch.n(ple4)+1) qt02 <- qt01+rnorm(length(qt01)) flqs <- FLQuants(qt01=qt01, qt02=qt02) bubbles(age~year|qname, data=flqs, bub.scale=1) qt03 <- FLQuant(rnorm(100),dimnames=list(age=as.character(1:10), year=as.character(1:10))) bubbles(age~year, data=qt03, bub.scale=7, col=c("black","red"), pch=16)
data(ple4) bubbles(age~year, data=catch.n(ple4)) bubbles(age~year, data=catch.n(ple4), bub.scale=5) bubbles(age~cohort, data=FLCohort(catch.n(ple4)), bub.scale=5) qt01 <- log(catch.n(ple4)+1) qt02 <- qt01+rnorm(length(qt01)) flqs <- FLQuants(qt01=qt01, qt02=qt02) bubbles(age~year|qname, data=flqs, bub.scale=1) qt03 <- FLQuant(rnorm(100),dimnames=list(age=as.character(1:10), year=as.character(1:10))) bubbles(age~year, data=qt03, bub.scale=7, col=c("black","red"), pch=16)
Calculate catch.n (catch-at-age/length) from abundances, F and M using the catch equation
## S4 method for signature 'FLQuant' catch.n(object, harvest, m)
## S4 method for signature 'FLQuant' catch.n(object, harvest, m)
The catch-at-age/length, commonly found in the catch.n slot of an
FLStock
object, can be simply calculated from abundances-at-age/length,
and natural and fishing mortalities-at-age/length by applying the catch
equation
The FLR Team
data(ple4) res <- catch.n(stock.n(ple4), harvest(ple4), m(ple4)) catch.n(ple4) / res
data(ple4) res <- catch.n(stock.n(ple4), harvest(ple4), m(ple4)) catch.n(ple4) / res
The proportion in weight of mature and inmature fish in the catch can be computed using catchMature and catchInmature.
catchInmature(object) catchMature(object)
catchInmature(object) catchMature(object)
object |
An age-structured FLStock object |
An FLQuant object
The FLR Team
data(ple4) catchInmature(ple4) catchMature(ple4)
data(ple4) catchInmature(ple4) catchMature(ple4)
Objects of various FLCore classes can be converted into other classes,
both basic R ones, like data.frame
, and others defined in the package. For
the specifics of the precise calculations carried out for each pair of
classes, see below.
object |
Object to be converted. |
Class |
Name of the class to convert the object to, |
An object of the requested class.
The six dimensions of an FLArray
are converted into seven columns, named
quant
(or any other name given to the first dimension in the object),
year
, unit
, season
, area
, iter
and data
. The last one contains
the actual numbers stored in the array. units
are stored as an attribute
to the data.frame
. The year
and data
columns are of type numeric
,
while all others are factor
.
The two or more dimensions of an FLPar objects are converted into three or
more columns. For a 2D objects, they are named params, iter and data.
The last one contains the actual numbers stored in the array, in a column
type numeric
, while all others are factor
.
The FLR Team
# from FLQuant to data.frame as(FLQuant(rnorm(100), dim=c(5, 20)), "data.frame") # from FLPar to data.frame as(FLPar(phi=rnorm(10), rho=rlnorm(10)), "data.frame")
# from FLQuant to data.frame as(FLQuant(rnorm(100), dim=c(5, 20)), "data.frame") # from FLPar to data.frame as(FLPar(phi=rnorm(10), rho=rlnorm(10)), "data.frame")
Comparisons of complete objects of FLR classes can be carried out and a report table is generated to better identify differences. Comparisons do not substitute but complement those provided by R's all.equal and identical.
compare(result, target, ...)
compare(result, target, ...)
result |
First element in comparison, result of method or operation. |
target |
Second element, desired output. |
A table of comparisons, of class data.frame.
Iago Mosqueira (WMR)
Methods to compute total quant-aggregated catch, landings, discards and stock biomass from age or length-structured numbers and mean weights.
Methods to compute total quant-aggregated catch, landings, discards and stock biomass from age or length-structured numbers and mean weights.
computeLandings(object, ...) computeDiscards(object, ...) computeCatch(object, ...) computeStock(object, ...) computeHarvest(object, catch, ...) computeLandings(object, ...) computeDiscards(object, ...) computeCatch(object, ...) computeStock(object, ...) ## S4 method for signature 'FLS' computeLandings(object, na.rm = TRUE) ## S4 method for signature 'FLS' computeDiscards(object, na.rm = TRUE) ## S4 method for signature 'FLS' computeCatch(object, slot = "catch", na.rm = TRUE) ## S4 method for signature 'FLS' computeStock(object, na.rm = TRUE)
computeLandings(object, ...) computeDiscards(object, ...) computeCatch(object, ...) computeStock(object, ...) computeHarvest(object, catch, ...) computeLandings(object, ...) computeDiscards(object, ...) computeCatch(object, ...) computeStock(object, ...) ## S4 method for signature 'FLS' computeLandings(object, na.rm = TRUE) ## S4 method for signature 'FLS' computeDiscards(object, na.rm = TRUE) ## S4 method for signature 'FLS' computeCatch(object, slot = "catch", na.rm = TRUE) ## S4 method for signature 'FLS' computeStock(object, na.rm = TRUE)
These methods compute the total catch, landings, discards and stock biomass
from the quant-structured values in numbers and weight per individual. The
calculation for landings, discards and stock involves the product of the
landings/discards/stock in numbers (landings.n
, discards.n
or
stock.n
) by the individual weight-at-quant (landings.wt
,
discards.wt
or stock.wt
), as in
By selecting slot="catch"
, computeCatch
can calculate in the
same way the total catch from the catch-at-quant and weight in the catch.
Those two values (in slots catch.n
and catch.wt
) can also be
calculated (from landings and discards) by specifying slot="n"
and
slot="wt"
respectively. Calling computeCatch
with option
slot="all"
will carry out the three calculations. In this case, the
returned object will be of class FLQuants
, with element names
catch
, catch.n
and catch.wt
, which can then be passed
directly to the catch<-
replacement method.
These methods compute the total catch, landings, discards and stock biomass
from the quant-structured values in numbers and weight per individual. The
calculation for landings, discards and stock involves the product of the
landings/discards/stock in numbers (landings.n
, discards.n
or
stock.n
) by the individual weight-at-quant (landings.wt
,
discards.wt
or stock.wt
), as in
By selecting slot="catch"
, computeCatch
can calculate in the
same way the total catch from the catch-at-quant and weight in the catch.
Those two values (in slots catch.n
and catch.wt
) can also be
calculated (from landings and discards) by specifying slot="n"
and
slot="wt"
respectively. Calling computeCatch
with option
slot="all"
will carry out the three calculations. In this case, the
returned object will be of class FLQuants
, with element names
catch
, catch.n
and catch.wt
, which can then be passed
directly to the catch<-
replacement method.
computeCatch(object, ...)
computeLandings(object, ...)
computeDiscards(object, ...)
computeStock(object, ...)
computeCatch(object, ...)
computeLandings(object, ...)
computeDiscards(object, ...)
computeStock(object, ...)
The FLR Team
data(ple4) summary(computeLandings(ple4)) summary(computeCatch(ple4, slot="all")) stock(ple4) <- computeStock(ple4) landings(ple4) <- computeLandings(ple4) catch.n(ple4) <- computeCatch(ple4, slot="n") catch(ple4) <- computeCatch(ple4, slot="all") data(ple4) summary(computeLandings(ple4)) summary(computeCatch(ple4, slot="all")) stock(ple4) <- computeStock(ple4) landings(ple4) <- computeLandings(ple4) catch.n(ple4) <- computeCatch(ple4, slot="n") catch(ple4) <- computeCatch(ple4, slot="all")
data(ple4) summary(computeLandings(ple4)) summary(computeCatch(ple4, slot="all")) stock(ple4) <- computeStock(ple4) landings(ple4) <- computeLandings(ple4) catch.n(ple4) <- computeCatch(ple4, slot="n") catch(ple4) <- computeCatch(ple4, slot="all") data(ple4) summary(computeLandings(ple4)) summary(computeCatch(ple4, slot="all")) stock(ple4) <- computeStock(ple4) landings(ple4) <- computeLandings(ple4) catch.n(ple4) <- computeCatch(ple4, slot="n") catch(ple4) <- computeCatch(ple4, slot="all")
Objects or class 'FLStock' already contain a 'harvest' slot to store estimates of fishing mortality at age, for example those obtained from a stock assessment method. Fishing mortality at age can be recalculated using two methods:
## S4 method for signature 'FLStock,missing' computeHarvest(object, units = NULL)
## S4 method for signature 'FLStock,missing' computeHarvest(object, units = NULL)
units |
Harvest to be computed as 'f' or 'hr', 'character'. |
x |
An object of class 'FLStock'. |
An 'FLQuant' with the calculated fishing mortalities at age.
The FLR Team
data(ple4) # Compute 'f' from stock.n and Baranov computeHarvest(ple4) # Recomputes all F at age by solving catch Baranov recomputeHarvest(ple4)
data(ple4) # Compute 'f' from stock.n and Baranov computeHarvest(ple4) # Recomputes all F at age by solving catch Baranov recomputeHarvest(ple4)
The observation of stock abundance by CPUE series from commercial fleets is an important step in the generation of management advice that needs to replicated on an Operating Model during any simulation exercise. This method gemnerates an observation of biomass or numbers-at-age from an FLstock being used as OM.
cpue(object, index, ...) ## S4 method for signature 'FLStock,missing' cpue( object, sel.pattern = harvest(object), effort = units(harvest(object)), biomass = TRUE )
cpue(object, index, ...) ## S4 method for signature 'FLStock,missing' cpue( object, sel.pattern = harvest(object), effort = units(harvest(object)), biomass = TRUE )
object |
The object from which to generate the observation. |
effort |
Units of index to use to mimic effort series in the fishery, "f" or "hr" |
sel |
The selectivity of the survey, defaults to be 1 for all ages. |
mass |
Is the index to be in weight at age? |
An FLQuant for the index of abundance, age-disaggregated
Laurie Kell & Iago Mosqueira, FLR Team.
data(ple4) cpue(ple4) # Am aggregated biomass CPUE quantSums(cpue(ple4)) ## Not run: plot(FLQuants(om=stock(ple4), cpue=quantSums(cpue(ple4)), hr=quantSums(cpue(ple4, effort="hr")))) ## End(Not run)
data(ple4) cpue(ple4) # Am aggregated biomass CPUE quantSums(cpue(ple4)) ## Not run: plot(FLQuants(om=stock(ple4), cpue=quantSums(cpue(ple4)), hr=quantSums(cpue(ple4, effort="hr")))) ## End(Not run)
This function creates a complete set of standard S4 class accessors and replacers. Not intended for direct use.
createFLAccesors(class, exclude = character(1), include = missing)
createFLAccesors(class, exclude = character(1), include = missing)
class |
name of the class |
exclude |
Slot names to exclude |
include |
Slot names to include |
The FLR Team
Example datasets for the classes defined in FLCore.
ple4
, FLStock
A dataset for North Sea (ICES Area IV)
plaice. Catch, landings, discards, natural mortality, weight-at-age and maturity,
together with the VPA estimated abundances and fishing mortalities.
ple4sex
, FLStock
A dataset of North Sea (ICES
Area IV) plaice disaggregated by sex. Catch, yield, landings, discards,
natural mortality, weight-at-age and maturity, together with the VPA
estimated abundances and fishing mortalities.
ple4.index, FLIndex
A dataset of North Sea (ICES Area IV) plaice
survey catch per unit effort, index and index variance.
ple4.indices, FLIndices
A dataset of three North Sea (ICES Area IV)
plaice survey catch per unit effort series. Index and index variance.
ple4.biol, FLBiol
A dataset of the North Sea plaice population.
Numbers, natural mortality, mass and fecundity-at-age.
nsher , FLSR
Stock and recruit data and fitted relationship for
autumn spawning North Sea herring.
Datasets can be loaded by issuing the data
command, like in
data(ple4)
.
ICES.
FLStock, FLSR, FLIndex, FLStock, FLIndex, FLBiol
data(ple4) summary(ple4) data(nsher) is(nsher)
data(ple4) summary(ple4) data(nsher) is(nsher)
These methods can bind two or more objects of array-based classes (e.g. FLQuant), along the specified dimension.
dbind(x, y, ...) ## S4 method for signature 'FLArray,FLArray' dbind(x, y, ..., dim = 1) qbind(...) ybind(...) ubind(...) sbind(...) abind(...) ibind(...)
dbind(x, y, ...) ## S4 method for signature 'FLArray,FLArray' dbind(x, y, ..., dim = 1) qbind(...) ybind(...) ubind(...) sbind(...) abind(...) ibind(...)
x |
First object to bind |
y |
Second object to bind |
... |
Other objects to bind |
dim |
Dimension to bind on, numeric or character. |
The objects to bind must contain the same dimmames in all dimensions other than that used to bind, while dimnames in the selected one must differ. See the examples below for correct and incorrect uses.
Object are bound in the order they are provided, with no attempt to sort according to the dimnames of the chosen dimension.
The implementation is based around a single method (dbind), that operates along the dimension position or name indicated by the dim argument. A series of shortcut functions call the method for specific dimensions, with names related to the dimensions name they operate on (e.g. ybind for year).
An object of the same class as the inputs
Iago Mosqueira (EC JRC)
# By iter x <- FLQuant(rnorm(80000), dim=c(4,20,1,1,1,1000)) y <- FLQuant(rnorm(80000), dim=c(4,20,1,1,1,1000)) dimnames(y) <- list(iter=1001:2000) ibind(x,y) # By quant (age) x <- FLQuant(1, dimnames=list(age=1:3, year=1:10)) y <- FLQuant(2, dimnames=list(age=4:12, year=1:10)) qbind(x, y) # By year x <- FLQuant(1, dimnames=list(age=1:3, year=1:10)) y <- FLQuant(2, dimnames=list(age=1:3, year=11:20)) z <- FLQuant(3, dimnames=list(age=1:3, year=21:30)) ybind(x, y, z) # By season x <- FLQuant(1, dimnames=list(year=1:10, season=1:2)) y <- FLQuant(2, dimnames=list(year=1:10, season=3:4)) sbind(x, y)
# By iter x <- FLQuant(rnorm(80000), dim=c(4,20,1,1,1,1000)) y <- FLQuant(rnorm(80000), dim=c(4,20,1,1,1,1000)) dimnames(y) <- list(iter=1001:2000) ibind(x,y) # By quant (age) x <- FLQuant(1, dimnames=list(age=1:3, year=1:10)) y <- FLQuant(2, dimnames=list(age=4:12, year=1:10)) qbind(x, y) # By year x <- FLQuant(1, dimnames=list(age=1:3, year=1:10)) y <- FLQuant(2, dimnames=list(age=1:3, year=11:20)) z <- FLQuant(3, dimnames=list(age=1:3, year=21:30)) ybind(x, y, z) # By season x <- FLQuant(1, dimnames=list(year=1:10, season=1:2)) y <- FLQuant(2, dimnames=list(year=1:10, season=3:4)) sbind(x, y)
List with information on object dimensions
List with information on object dimensions
dims(obj, ...) dims(obj, ...) ## S4 method for signature 'FLQuant' dims(obj, element, ...)
dims(obj, ...) dims(obj, ...) ## S4 method for signature 'FLQuant' dims(obj, element, ...)
Method dims
returns a named list with information on the dimensions
and dimension names of a given object. The list returned could be
extended in the future and currently contains, depending on the class of the
object, some of the following:
Length of the first dimension
First quant
Last quant
Number of years
First year in series
Last year in series
Number of cohorts
First cohort in series
Last cohort in series
Length of the third (unit
) dimension
Length of the fourth (season
) dimension
Length of the fifth (area
) dimension
Length of the sixth (iter
) dimension
Values in the returned list are of class numeric
, unless dimnames are
strings with no numeric translation, in which case the result is NA
.
Please note that the name of the first element in the returned list changes
with the name of the first dimension in the input object. Use
quant
to obtain the name and extract the relevant element from
the result list.
Method dims
returns a named list with information on the dimensions
and dimension names of a given object. The list returned could be
extended in the future and currently contains, depending on the class of the
object, some of the following:
Length of the first dimension
First quant
Last quant
Number of years
First year in series
Last year in series
Number of cohorts
First cohort in series
Last cohort in series
Length of the third (unit
) dimension
Length of the fourth (season
) dimension
Length of the fifth (area
) dimension
Length of the sixth (iter
) dimension
Values in the returned list are of class numeric
, unless dimnames are
strings with no numeric translation, in which case the result is NA
.
Please note that the name of the first element in the returned list changes
with the name of the first dimension in the input object. Use
quant
to obtain the name and extract the relevant element from
the result list.
dims(obj)
dims(obj)
The FLR Team
flq <- FLQuant(rnorm(96), dim=c(3,8,1,4), quant='age') dims(flq) # Number of seasons dims(flq)$season # Length of first dimension dims(flq)[[quant(flq)]]
flq <- FLQuant(rnorm(96), dim=c(3,8,1,4), quant='age') dims(flq) # Number of seasons dims(flq)$season # Length of first dimension dims(flq)[[quant(flq)]]
Methods to compute various summary calculations (sum, mean, variance) over
selected dimensions of objects from any array-based classes
(e.g. FLQuant
). These methods return an object of the
same dimensions as the input but with length one in the dimension chosen
to operate along.
quantSums(x, ...) yearSums(x, ...) unitSums(x, ...) seasonSums(x, ...) areaSums(x, ...) iterSums(x, ...) dimSums(x, ...) quantMeans(x, ...) yearMedians(x, ...) yearMeans(x, ...) unitMeans(x, ...) seasonMeans(x, ...) areaMeans(x, ...) iterMeans(x, ...) dimMeans(x, ...) quantVars(x, ...) yearVars(x, ...) unitVars(x, ...) seasonVars(x, ...) areaVars(x, ...) iterVars(x, ...) dimVars(x, ...) iterMedians(x, ...) iterCVs(x, ...) iterProb(x, ...) ## S4 method for signature 'FLQuant' quantSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' unitSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' seasonSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' areaSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' quantMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' unitMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' seasonMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' areaMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearMedians(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterMedians(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' quantVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' unitVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' seasonVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' areaVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterCVs(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterProb(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' yearSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' unitSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' seasonSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' areaSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' yearMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' unitMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' seasonMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' areaMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' iterMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' iterMedians(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' quantVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' yearVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' unitVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' seasonVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' areaVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' iterVars(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterMeans(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterMedians(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterVars(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterSums(x, na.rm = TRUE)
quantSums(x, ...) yearSums(x, ...) unitSums(x, ...) seasonSums(x, ...) areaSums(x, ...) iterSums(x, ...) dimSums(x, ...) quantMeans(x, ...) yearMedians(x, ...) yearMeans(x, ...) unitMeans(x, ...) seasonMeans(x, ...) areaMeans(x, ...) iterMeans(x, ...) dimMeans(x, ...) quantVars(x, ...) yearVars(x, ...) unitVars(x, ...) seasonVars(x, ...) areaVars(x, ...) iterVars(x, ...) dimVars(x, ...) iterMedians(x, ...) iterCVs(x, ...) iterProb(x, ...) ## S4 method for signature 'FLQuant' quantSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' unitSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' seasonSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' areaSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' quantMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' unitMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' seasonMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' areaMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearMedians(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterMedians(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' quantVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' yearVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' unitVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' seasonVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' areaVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterCVs(x, na.rm = TRUE) ## S4 method for signature 'FLQuant' iterProb(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' yearSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' unitSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' seasonSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' areaSums(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' yearMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' unitMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' seasonMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' areaMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' iterMeans(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' iterMedians(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' quantVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' yearVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' unitVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' seasonVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' areaVars(x, na.rm = TRUE) ## S4 method for signature 'FLQuantDistr' iterVars(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterMeans(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterMedians(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterVars(x, na.rm = TRUE) ## S4 method for signature 'FLPar' iterSums(x, na.rm = TRUE)
x |
An object. |
na.rm |
Should NAs be removed before calculation? Defaults to TRUE. |
This set of methods computes three different summaries (sum, mean and
variance) of an FLQuant
object along each of the six dimensions
(quant, year, unit, season, area, or iter). Medians and CVs can also be
computed along the sixth dimension, iter
.
These methods encapsulate a call to apply
with
the corresponding dimensions and function: mean
,
median
, var
, and
sum
, while iterCVs
are computed as
sqrt(iterVars) / iterMeans
.
In contrast with R standard behaviour, the sum of a dimension where all
elements are NA
will be NA
and not 0. See example below.
Methods working along the iter dimension are also defined for objects of class
FLPar
.
Methods to operate over the first dimension refer to it as the quant
dimension, regardless of the actual name used in the object.
quantSums(x), quantMeans(x), quantVars(x) yearSums(x), yearMeans(x), yearVars(x) unitSums(x), unitMeans(x), unitVars(x) seasonSums(x), seasonMeans(x), seasonVars(x) areaSums(x), areaMeans(x), areaVars(x) iterMeans(x), iterVars(x), iterMedians(x), iterSums(x) dimSums(x), dimMeans(x), dimVars(x)
The FLR Team
flq <- FLQuant(rnorm(4000), dim=c(5,10,2,2,2,10), quant='age') quantSums(flq) quantMeans(flq) yearSums(flq) iterMeans(flq) dim(quantSums(flq)) # NA dims stay as NA when summed along x <- FLQuant(c(NA, NA, NA, rnorm(6)), dim=c(3, 3)) quantSums(x) # although in fact a sum of no elements (as na.rm=TRUE) is zero apply(x, 2:6, sum, na.rm=TRUE)
flq <- FLQuant(rnorm(4000), dim=c(5,10,2,2,2,10), quant='age') quantSums(flq) quantMeans(flq) yearSums(flq) iterMeans(flq) dim(quantSums(flq)) # NA dims stay as NA when summed along x <- FLQuant(c(NA, NA, NA, rnorm(6)), dim=c(3, 3)) quantSums(x) # although in fact a sum of no elements (as na.rm=TRUE) is zero apply(x, 2:6, sum, na.rm=TRUE)
A calculation is made of the proportion of discards over total catch at age, either as numbers (value = 'numbers') or weight (value = 'weight'), or for the total discards and catch in biomass (value = 'total').
discardsRatio(object, value = c("numbers", "weight", "total"))
discardsRatio(object, value = c("numbers", "weight", "total"))
object |
An object of class 'FLStock' |
value |
One of 'numbers' (default), 'weight' or 'total'. |
The discards ratio (between 0 and 1), 'FLQuant'
The FLR Team
data(ple4) # Discards ratio at age in numbers discardsRatio(ple4) # Total proportion of discards by year discardsRatio(ple4, value="total")
data(ple4) # Discards ratio at age in numbers discardsRatio(ple4) # Total proportion of discards by year discardsRatio(ple4, value="total")
Delete the dimensions of an array which have only one level.
## S4 method for signature 'FLArray' drop(x)
## S4 method for signature 'FLArray' drop(x)
This method calls R's base::drop on the @.Data
slot of an FLArray.
Dimensions of length one are thus dropped, as is the class attribute and the
units
slot, and an array of equal or less
dimensions, a matrix or a vector is returned.
On an FLQuant object with
The FLR Team
x <- FLQuant(1:3, dim=c(3,3)) drop(x) is(drop(x)) dim(drop(x)) # Result of drop can be used for matrix algebra # for example to calculate aging error data(ple4) aging.error <- diag(0.8, 10) diag(aging.error[-1,]) <- c(rep(0.1, 8), 0.2) diag(aging.error[, -1]) <- c(0.2, rep(0.1, 8)) t(aging.error) %*% drop(catch.n(ple4))
x <- FLQuant(1:3, dim=c(3,3)) drop(x) is(drop(x)) dim(drop(x)) # Result of drop can be used for matrix algebra # for example to calculate aging error data(ple4) aging.error <- diag(0.8, 10) diag(aging.error[-1,]) <- c(rep(0.1, 8), 0.2) diag(aging.error[, -1]) <- c(0.2, rep(0.1, 8)) t(aging.error) %*% drop(catch.n(ple4))
Models in objects of the predictModel class can make use of slots and
methods of the FLR class in which it is contained as a slot. This function can
be used by methods wishing to evaluate a single predictModel
slot in the
context of the class it is part of.
evalPredictModel(object, slot, ...)
evalPredictModel(object, slot, ...)
object |
The FLR S4 over whicvh the predictModel evaluation should take place |
slot |
The predictModel object to be evaluated |
The result of evaluating the model, usually an FLQuant
The FLR Team
Compute the exponential and logarithmic functions
## S4 method for signature 'FLQuant' exp(x) ## S4 method for signature 'FLQuant' log(x, ...)
## S4 method for signature 'FLQuant' exp(x) ## S4 method for signature 'FLQuant' log(x, ...)
This method simply calls R's base::exp and base::drop, but take care of returning the right units of measurement, that is "" or character(1).
The FLR Team
x <- FLQuant(c(4,2,7,4,2,9), units="1000") log(x) units(log(x))
x <- FLQuant(c(4,2,7,4,2,9), units="1000") log(x) units(log(x))
Extract or replace parts of an FLR Object
## S4 method for signature 'FLArray,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 method for signature 'FLArray,array,missing,missing' x[i] ## S4 replacement method for signature 'FLArray,ANY,ANY,ANY' x[i, j, k, l, m, n, ...] <- value ## S4 replacement method for signature 'FLArray,ANY,ANY,FLArray' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLQuant' x$name ## S4 method for signature 'FLQuantDistr,ANY,ANY,ANY' x[i, j, k, l, m, n] ## S4 method for signature 'FLQuantDistr,array,missing,missing' x[i] ## S4 method for signature 'FLPar,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 method for signature 'FLPar,array,missing,missing' x[i] ## S4 replacement method for signature 'FLPar,ANY,ANY,ANY' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLPar' x$name ## S4 replacement method for signature 'FLPar' x$name <- value ## S4 method for signature 'FLComp,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 replacement method for signature 'FLComp,ANY,ANY,ANY' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLStock,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 replacement method for signature 'FLStock,ANY,ANY,FLStock' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLI,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 method for signature 'predictModel,ANY,missing,ANY' x[i, k, l, m, n, ..., drop = FALSE] ## S4 replacement method for signature 'FLlst,ANY,missing' x[[i, j]] <- value ## S4 replacement method for signature 'FLlst' x$name <- value ## S4 replacement method for signature 'FLlst,ANY,missing,ANY' x[i, j] <- value ## S4 method for signature 'FLlst,ANY,missing,ANY' x[i, drop]
## S4 method for signature 'FLArray,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 method for signature 'FLArray,array,missing,missing' x[i] ## S4 replacement method for signature 'FLArray,ANY,ANY,ANY' x[i, j, k, l, m, n, ...] <- value ## S4 replacement method for signature 'FLArray,ANY,ANY,FLArray' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLQuant' x$name ## S4 method for signature 'FLQuantDistr,ANY,ANY,ANY' x[i, j, k, l, m, n] ## S4 method for signature 'FLQuantDistr,array,missing,missing' x[i] ## S4 method for signature 'FLPar,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 method for signature 'FLPar,array,missing,missing' x[i] ## S4 replacement method for signature 'FLPar,ANY,ANY,ANY' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLPar' x$name ## S4 replacement method for signature 'FLPar' x$name <- value ## S4 method for signature 'FLComp,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 replacement method for signature 'FLComp,ANY,ANY,ANY' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLStock,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 replacement method for signature 'FLStock,ANY,ANY,FLStock' x[i, j, k, l, m, n, ...] <- value ## S4 method for signature 'FLI,ANY,ANY,ANY' x[i, j, k, l, m, n, ..., drop = FALSE] ## S4 method for signature 'predictModel,ANY,missing,ANY' x[i, k, l, m, n, ..., drop = FALSE] ## S4 replacement method for signature 'FLlst,ANY,missing' x[[i, j]] <- value ## S4 replacement method for signature 'FLlst' x$name <- value ## S4 replacement method for signature 'FLlst,ANY,missing,ANY' x[i, j] <- value ## S4 method for signature 'FLlst,ANY,missing,ANY' x[i, drop]
x |
object from which to extract or replace element(s) |
i , j , k , l , m , n
|
indices specifying elements to extract or replace on any of the six dimensions. |
... |
indices specifying elements to extract or replace by dimension name. |
drop |
If 'TRUE' the result is coerced to the lowest possible dimension, and so
might change class (e.g. drop='TRUE' on an |
value |
An object of the same class, or simpler if |
name |
See Extract for further details. |
Operators acting on FLQuant, FLCohort, FLPar, FLComp, and derived classes to extract or replace sections of an object.
Please note the differences between referencing sections of an object by
position using values of class numeric
, or by using dimnames of class
character
. See examples below.
All classes that are derived from FLComp
(for example, FLStock
and FLBiol
) can be subset along the six dimensions of their
FLQuant
slots.
Classes that are derived from FLlst
(for example, FLStocks
and
FLBiols
) can be subset in a similar way to ordinary list objects.
'$' for the FLPar
and FLQuant
classes operate only along the first
dimension ('params' or 'quant'), and are provided to be used specially in
formulas.
x,i,j,drop
[<-(x,i,j,value)
[[<-(x,i,j,value)
\$<-(x,name,value)
The FLR Team
flq <- FLQuant(rnorm(200), dimnames=list(age=0:4, year=1991:2000, season=1:4)) # Extracting by position... flq[1,] flq[,1:5] flq[1:2,,,c(1,3)] # ...by dimnames flq['0',] flq[,'1991'] flq[,as.character(1991:1995),,'1'] # Dimensions of length one can be drop flq[1, drop=TRUE] # Replacing part of the object flq['0',,,1]<-0
flq <- FLQuant(rnorm(200), dimnames=list(age=0:4, year=1991:2000, season=1:4)) # Extracting by position... flq[1,] flq[,1:5] flq[1:2,,,c(1,3)] # ...by dimnames flq['0',] flq[,'1991'] flq[,as.character(1991:1995),,'1'] # Dimensions of length one can be drop flq[1, drop=TRUE] # Replacing part of the object flq['0',,,1]<-0
Projection of an FLStock object for a fishing mortality target does not always require the features of fwd().Fast-forward an FLStock object for a fishing mortality yearly target only.
ffwd(object, sr, fbar = control, control = fbar, deviances = "missing")
ffwd(object, sr, fbar = control, control = fbar, deviances = "missing")
object |
An FLStock |
sr |
A stock-recruit relationship, FLSR or predictModel. |
fbar |
Yearly target for average fishing mortality, FLQuant. |
control |
Yearly target for average fishing mortality, fwdControl. |
deviances |
Deviances for the strock-recruit relationsip, FLQuant. |
The projected FLStock object.
Iago MOSQUEIRA (MWR), Henning WINKEL (JRC).
fwd
data(ple4) sr <- predictModel(model=bevholt, params=FLPar(a=140.4e4, b=1.448e5)) # Project for fixed Fbar=0.21 run <- ffwd(ple4, sr=sr, fbar=FLQuant(0.21, dimnames=list(year=1958:2017))) plot(run)
data(ple4) sr <- predictModel(model=bevholt, params=FLPar(a=140.4e4, b=1.448e5)) # Project for fixed Fbar=0.21 run <- ffwd(ple4, sr=sr, fbar=FLQuant(0.21, dimnames=list(year=1958:2017))) plot(run)
A basic 6D array class. No objects of this class are created in FLCore, as it is used only for method inheritance.
Internal S4 data representation, of class array
.
Array must have 6 dimensions
Array must be of class numeric
The FLR Team
A class for modelling age / length or biomass structured populations.
FLBiol(object, ...) ## S4 method for signature 'FLQuant' FLBiol(object, plusgroup = dims(object)$max, ...)
FLBiol(object, ...) ## S4 method for signature 'FLQuant' FLBiol(object, plusgroup = dims(object)$max, ...)
object |
FLQuant object used for sizing |
... |
Other objects to be assigned by name to the class slots |
plusgroup |
Plusgroup age, to be stored in range |
The FLBiol
class is a representation of a biological fish population.
This includes information on abundances, natural mortality and fecundity.
Numbers in the population. FLQuant
.
Mortality rate of the population. FLQuant
.
Mean weight of an individual. FLQuant
.
predictModel
.
predictModel
.
predictModel
.
Proportion of time step at which spawning ocurrs. FLQuant
.
Name of the object. character
.
Brief description of the object. character
.
Named numeric vector describing the range of the object. numeric
.
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
A construction method exists for this class that can take named arguments for
any of its slots. All slots are then created to match the requirements of the
class validity. If an unnamed FLQuant
object is provided, this is used
for sizing but not stored in any slot.
All FLQuant slots must have iters equal to 1 or 'n'.
The dimname for iter1 should be '1'.
The name of the quant dimension must be the same for all FLQuant slots.
The FLR Team
as.FLBiol, as.FLSR, coerce, plot, ssb catch.n,FLBiol-method
# An FLBiol example dataset data(ple4.biol) summary(ple4.biol)
# An FLBiol example dataset data(ple4.biol) summary(ple4.biol)
A list of FLBiol
objects.
FLBiols(object, ...) ## S4 method for signature 'FLBiol' FLBiols(object, ...) ## S4 method for signature 'missing' FLBiols(object, ...) ## S4 method for signature 'list' FLBiols(object, ...)
FLBiols(object, ...) ## S4 method for signature 'FLBiol' FLBiols(object, ...) ## S4 method for signature 'missing' FLBiols(object, ...) ## S4 method for signature 'list' FLBiols(object, ...)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
Internal S4 data representation, of class list
.
As textual description of the object contents
Can the object be extended/trimmed? TRUE
or FALSE
.
A character vector for the element names
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
A class for modelling cohorts.
FLCohort(object, ...) ## S4 method for signature 'FLQuant' FLCohort(object, ...) ## S4 method for signature 'FLCohort' FLCohort(object, units = units(object)) ## S4 method for signature 'array' FLCohort( object, dim = rep(1, 6), dimnames = "missing", units = "NA", iter = 1, fill.iter = TRUE ) ## S4 method for signature 'vector' FLCohort( object, dim = c(length(object), rep(1, 5)), dimnames = "missing", units = "NA", iter = 1 ) ## S4 method for signature 'missing' FLCohort(object, dim = rep(1, 6), dimnames = "missing", units = "NA", iter = 1)
FLCohort(object, ...) ## S4 method for signature 'FLQuant' FLCohort(object, ...) ## S4 method for signature 'FLCohort' FLCohort(object, units = units(object)) ## S4 method for signature 'array' FLCohort( object, dim = rep(1, 6), dimnames = "missing", units = "NA", iter = 1, fill.iter = TRUE ) ## S4 method for signature 'vector' FLCohort( object, dim = c(length(object), rep(1, 5)), dimnames = "missing", units = "NA", iter = 1 ) ## S4 method for signature 'missing' FLCohort(object, dim = rep(1, 6), dimnames = "missing", units = "NA", iter = 1)
object |
Input numeric object |
... |
Additonal arguments |
This class represents cohorts in columns. It simply shifts the typical matrix representation where cohorts are found on the diagonals, into a matrix where cohorts are found in columns. It is very usefull for all analysis that want to make use of cohorts instead of years.
Internal S4 data representation.
array
.
The data units in some understandable metric.
character
Objects of this class are generally constructed from an FLQuant object.
The FLR Team
[, as.data.frame, bubbles, ccplot, FLCohort,FLQuant-method, flc2flq, plot, quant, trim, units, units<-,FLCohort,character-method, xyplot, array
data(ple4) flq <- catch.n(ple4) flc <- FLCohort(flq) plot(trim(flc, cohort=1960:2000))
data(ple4) flq <- catch.n(ple4) flc <- FLCohort(flq) plot(trim(flc, cohort=1960:2000))
FLCohorts
is a class that extends list
through FLlst
but implements a set of features that give a little more structure to
list objects. The elements of FLCohorts
must all be of class
FLCohort
. It implements a lock mechanism that, when turned on, does
not allow the user to increase or decrease the object length.
FLCohorts(object, ...)
FLCohorts(object, ...)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
The data. list
Names of the list elements. character
Description of the object. character
Lock
mechanism, if turned on the length of the list can not be modified by adding
or removing elements. logical
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
*, Arith, as.data.frame, bubbles, catch<-, iter, model.frame, show, summary, xyplot, FLlst, list
A virtual class that forms the basis for most FLR classes composed of slots
of class FLQuant
. No objects of this class can be
constructed.
All FLQuant slots must have iters equal to 1 or 'n'.
The dimname for iter1 should be '1'.
The name of the quant dimension must be the same for all FLQuant slots.
A character vector for the object name.
A textual description of the object contents.
A named numeric vector with various values of quant and year ranges, plusgroup, fishing mortality ranges, etc. Elements are specific to each child class.
The FLR Team
[, [<-, as.data.frame, iter, propagate, qapply, summary, transform, trim, units,FLComp-method, units<-,FLComp,list-method, window
A virtual class that forms the basis for many FLR list classes. No objects of this class can be constructed.
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
All elements must be of a class that inherits from FLComp
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock mechanism, if turned on the length of the list can not be
modified by adding or removing elements. logical
.
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
A VIRTUAL class that holds data and parameters related to abundance indices.
object |
FLQuant object used for sizing |
... |
Other objects to be assigned by name to the class slots |
Statistical distribution of the index values (character
).
Index values (FLQuant
).
Variance of the index (FLQuant
).
Catch numbers used to create the index (FLQuant
).
Catch weight of the index (FLQuant
).
Effort used to create the index (FLQuant
).
Selection pattern for the index (FLQuant
).
Catchability of the index (FLQuant
).
Name of the stock (character
).
General description of the object (character
).
Range of the object (numeric
)
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
A construction method exists for this class that can take named arguments for
any of its slots. All slots are then created to match the requirements of the
class validity. If an unnamed FLQuant
object is provided, this is used
for sizing but not stored in any slot.
All FLQuant slots must have iters equal to 1 or 'n'.
The dimname for iter1 should be '1'.
The name of the quant dimension must be the same for all FLQuant slots.
The FLR Team
computeCatch, dims, iter, plot, propagate, summary, transform, trim, window, FLComp
A class for modelling abundance indices.
FLIndex(object, ...) ## S4 method for signature 'FLQuant' FLIndex(object, plusgroup = dims(object)$max, ...) ## S4 method for signature 'missing' FLIndex(object, ...)
FLIndex(object, ...) ## S4 method for signature 'FLQuant' FLIndex(object, plusgroup = dims(object)$max, ...) ## S4 method for signature 'missing' FLIndex(object, ...)
The FLIndex
object holds data and parameters related to abundance
indices.
Type of index (character
).
Statistical distribution of the index values
(character
).
Index values (FLQuant
).
Variance of the index (FLQuant
).
Catch numbers used to create the index (FLQuant
).
Catch weight of the index (FLQuant
).
Effort used to create the index (FLQuant
).
Selection pattern for the index (FLQuant
).
Catchability of the index (FLQuant
).
Name
of the stock (character
).
General description of the
object (character
).
Named numeric vector containing the
quant and year ranges, the plusgroup, and the period of the year, expressed
as proportions of a year, that corresponds to the index (numeric
).
The FLR Team
computeCatch, dims, iter, plot, propagate, summary, transform, trim, window, FLComp
# Create an FLIndex object. fli <- FLIndex(index=FLQuant(rnorm(8), dim=c(1,8)), name="myTestFLindex") summary(fli) index(fli) # Creat an FLIndex object using an existing FLQuant object. data(ple4) # Create a perfect index of abundance from abundance at age fli2 <- FLIndex(index=stock.n(ple4)) # Add some noise around the signal index(fli2) <- index(fli2)*exp(rnorm(1, index(fli2)-index(fli2), 0.1))
# Create an FLIndex object. fli <- FLIndex(index=FLQuant(rnorm(8), dim=c(1,8)), name="myTestFLindex") summary(fli) index(fli) # Creat an FLIndex object using an existing FLQuant object. data(ple4) # Create a perfect index of abundance from abundance at age fli2 <- FLIndex(index=stock.n(ple4)) # Add some noise around the signal index(fli2) <- index(fli2)*exp(rnorm(1, index(fli2)-index(fli2), 0.1))
A class for modelling biomass indices.
FLIndexBiomass(object, ...) ## S4 method for signature 'FLQuant' FLIndexBiomass(object, plusgroup = dims(object)$max, ...) ## S4 method for signature 'missing' FLIndexBiomass(object, ...)
FLIndexBiomass(object, ...) ## S4 method for signature 'FLQuant' FLIndexBiomass(object, plusgroup = dims(object)$max, ...) ## S4 method for signature 'missing' FLIndexBiomass(object, ...)
object |
FLQuant object used for sizing |
... |
Other objects to be assigned by name to the class slots |
The FLIndexBiomass
object holds data and parameters related to
biomass indices.
Statistical distribution of
the index values (character
).
Index values
(FLQuant
).
Variance of the index (FLQuant
).
Catch numbers used to create the index (FLQuant
).
Catch weight of the index (FLQuant
).
Effort used to create the index (FLQuant
).
Selection pattern for the index (FLQuant
).
Catchability of the index (FLQuant
).
Name of the stock (character
).
General description of the object (character
).
Range of the object (numeric
)
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
A construction method exists for this class that can take named arguments for
any of its slots. All slots are then created to match the requirements of the
class validity. If an unnamed FLQuant
object is provided, this is used
for sizing but not stored in any slot.
All FLQuant slots must have iters equal to 1 or 'n'.
The dimname for iter1 should be '1'.
The name of the quant dimension must be the same for all FLQuant slots.
The FLR Team
computeCatch, dims, iter, plot, propagate, summary, transform, trim, window, FLComp
idx <- FLIndexBiomass(index=FLQuant(1:10, quant='age')) data(ple4) ida <- FLIndexBiomass(index=ssb(ple4), catch.n=catch.n(ple4))
idx <- FLIndexBiomass(index=FLQuant(1:10, quant='age')) data(ple4) ida <- FLIndexBiomass(index=ssb(ple4), catch.n=catch.n(ple4))
FLIndices
is a class that extends list
through FLlst
but implements a set of features that give a little more structure to
list objects. The elements of FLIndices
must all be of class
FLIndex
. It implements a lock mechanism that, when turned on, does
not allow the user to increase or decrease the object length.
FLIndices(object, ...) ## S4 method for signature 'FLI' FLIndices(object, ...) ## S4 method for signature 'missing' FLIndices(object, ...) ## S4 method for signature 'list' FLIndices(object, ...)
FLIndices(object, ...) ## S4 method for signature 'FLI' FLIndices(object, ...) ## S4 method for signature 'missing' FLIndices(object, ...) ## S4 method for signature 'list' FLIndices(object, ...)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock
mechanism, if turned on the length of the list can not be modified by adding
or removing elements. logical
.
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
data(ple4.index) flis <- FLIndices(INDa=ple4.index, INDb=window(ple4.index, end=2000))
data(ple4.index) flis <- FLIndices(INDa=ple4.index, INDb=window(ple4.index, end=2000))
FLlst
is a class that extends list
but implements a set of
features that give a little more structure to list objects. First the
elements of FLlst
must all be of the same class. Second it implements
a lock mechanism that, when turned on, does not allow the user to increase
or decrease the object length.
FLlst(object, ...)
FLlst(object, ...)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock mechanism, if turned on the length of the list can not be
modified by adding or removing elements. logical
.
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
[, [<-, [[<-, $<-, coerce, lapply, window, list
fll01 <- new("FLlst", list(a=1:10, b=10:20)) fll02 <- new("FLlst", list(1:10, 10:20), names=c("a","b")) fll03 <- FLlst(a=1:10, b=10:20) fll04 <- FLlst(list(a=1:10, b=10:20)) fll05 <- FLlst(c(1:10), c(10:20)) names(fll05) <- names(fll01) names(fll01)
fll01 <- new("FLlst", list(a=1:10, b=10:20)) fll02 <- new("FLlst", list(1:10, 10:20), names=c("a","b")) fll03 <- FLlst(a=1:10, b=10:20) fll04 <- FLlst(list(a=1:10, b=10:20)) fll05 <- FLlst(c(1:10), c(10:20)) names(fll05) <- names(fll01) names(fll01)
A virtual class for statistical models
FLModel(model, ...)
FLModel(model, ...)
The FLModel
class provides a virtual class that developers of various
statistical models can use to implement classes that allow those models to
be tested, fitted and presented.
Slots in this class attempt to map all the usual outputs for a modelling
exercise, together with the standard inputs. Input data are stored in slots
created by a specified class based on FLModel
. See for example
FLSR
for a class used for stock-recruitment models.
The initial
slot contains a function used to obtain initial values for
the numerical solver. It can also contain two attributes, upper
and
lower
that limit the sarch area for each parameter.
Various fitting algorithms, similar to those present in the basic R packages,
are currently available for FLModel
, including fmle
,
nls-FLCore
and glm
.
Name of the object, character
.
Description of the object, character
.
Range, numeric
.
Associated error probability dfistribution, factor
.
Estimated values, FLQuant
.
Residuals obtained from the model fit, FLQuant
.
Model formula, formula
.
Function returning the gradient of the likelihood, function
.
Log-likelihood function. function
.
Function returning initial parameter values for the
optimizer, as an object of class FLPar
, function
.
Estimated parameter values, FLPar
.
Value of the log-likelihood, logLik
.
Variance-covariance matrix, array
.
Hessian matrix obtained from the parameter fitting, array
.
extra information on the model fit procedure, list
.
The FLR Team
# Normally, FLModel objects won't be created if "class" is not set summary(FLModel(length~width*alpha)) # Objects of FLModel-based classes use their own constructor, # which internally calls FLModel fsr <- FLModel(rec~ssb*a, class='FLSR') is(fsr) summary(fsr) # An example constructor method for an FLModel-based class # Create class FLGrowth with a single new slot, 'mass' setClass('FLGrowth', representation('FLModel', mass='FLArray')) # Define a creator method based on FLModel setGeneric("FLGrowth", function(object, ...) standardGeneric("FLGrowth")) setMethod('FLGrowth', signature(object='ANY'), function(object, ...) return(FLModel(object, ..., class='FLGrowth'))) setMethod('FLGrowth', signature(object='missing'), function(...) return(FLModel(formula(NULL), ..., class='FLGrowth'))) # Define an accessor method setMethod('mass', signature(object='FLGrowth'), function(object) return(slot(object, 'mass')))
# Normally, FLModel objects won't be created if "class" is not set summary(FLModel(length~width*alpha)) # Objects of FLModel-based classes use their own constructor, # which internally calls FLModel fsr <- FLModel(rec~ssb*a, class='FLSR') is(fsr) summary(fsr) # An example constructor method for an FLModel-based class # Create class FLGrowth with a single new slot, 'mass' setClass('FLGrowth', representation('FLModel', mass='FLArray')) # Define a creator method based on FLModel setGeneric("FLGrowth", function(object, ...) standardGeneric("FLGrowth")) setMethod('FLGrowth', signature(object='ANY'), function(object, ...) return(FLModel(object, ..., class='FLGrowth'))) setMethod('FLGrowth', signature(object='missing'), function(...) return(FLModel(formula(NULL), ..., class='FLGrowth'))) # Define an accessor method setMethod('mass', signature(object='FLGrowth'), function(object) return(slot(object, 'mass')))
A virtual class for statistical simulation models
FLModelSim(object, ...) ## S4 method for signature 'missing' FLModelSim(object, ...)
FLModelSim(object, ...) ## S4 method for signature 'missing' FLModelSim(object, ...)
The FLModelSim
class provides a virtual class that developers of various
statistical models can use to implement classes that allow those models to
be tested, fitted and presented.
Slots in this class attempt to map all the usual outputs for a modelling
exercise, together with the standard inputs. Input data are stored in slots
created by a specified class that is based on FLModelSim
. See for example
FLSR
for a class used for stock-recruitment models.
Various fitting algorithms, similar to those present in the basic R packages,
are currently available for FLModelSim
, including fmle
,
nls-FLCore
and glm
.
Estimated parameter values. FLPar
.
character
array
formula
The FLR Team
A list of FLModelSim
objects.
FLModelSims(object, ...) ## S4 method for signature 'ANY' FLModelSims(object, ...) ## S4 method for signature 'missing' FLModelSims(object, ...) ## S4 method for signature 'list' FLModelSims(object) ## S4 method for signature 'FLModelSims' FLModelSims(object)
FLModelSims(object, ...) ## S4 method for signature 'ANY' FLModelSims(object, ...) ## S4 method for signature 'missing' FLModelSims(object, ...) ## S4 method for signature 'list' FLModelSims(object) ## S4 method for signature 'FLModelSims' FLModelSims(object)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock mechanism, if turned on the length of the list can not be
modified by adding or removing elements. logical
.
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
A class for storing parameters of a model.
FLPar(object, ...)
FLPar(object, ...)
The FLPar
class is based on the array class which can store
Monte Carlo samples and the names of the relevant parameter vectors.
Methods for this class include subsetting and replacement as for the
FLQuant
class. There are methods for extracting
statistics of the sample (mean, median etc.) and for plotting the parameter
samples.
Describe slot. array
.
Units of measurement. character
.
The FLR Team
[, [<-, as.data.frame, densityplot, histogram, iter, iter<-, mean, median, plot, splom, summary, units,FLPar-method, units<-,FLPar,character-method, var
FLPar(rnorm(4), params=c('a','b','c','sigma2')) FLPar(rnorm(20), dimnames=list(params=c('a','b'), year=1990:1999, iter=1), units='NA') # with iters FLPar(rnorm(80), params=c('a', 'b'), iter=1:40)
FLPar(rnorm(4), params=c('a','b','c','sigma2')) FLPar(rnorm(20), dimnames=list(params=c('a','b'), year=1990:1999, iter=1), units='NA') # with iters FLPar(rnorm(80), params=c('a', 'b'), iter=1:40)
A class for storing parameters of a jackknifed model fit.
## S4 method for signature 'ANY' FLParJK(object, orig) ## S4 method for signature 'FLParJK' orig(object)
## S4 method for signature 'ANY' FLParJK(object, orig) ## S4 method for signature 'FLParJK' orig(object)
.Data
Jackknifed object, FLPar
.
units
units of measurement, character
.
orig
original object being jackknifed, FLPar
.
You can inspect the class validity function by using
getValidity(getClassDef('FLParJK'))
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
Objects of this class are commonly created by calling the jackknife()
method
A construction method exists for this class that can take named arguments for
any of its slots. All slots are then created to match the requirements of the
class validity.
The FLR Team
A list of FLPar
objects.
FLPars(object, ...) ## S4 method for signature 'ANY' FLPars(object, ...) ## S4 method for signature 'missing' FLPars(object, ...) ## S4 method for signature 'list' FLPars(object) ## S4 method for signature 'FLPars' FLPars(object)
FLPars(object, ...) ## S4 method for signature 'ANY' FLPars(object, ...) ## S4 method for signature 'missing' FLPars(object, ...) ## S4 method for signature 'list' FLPars(object) ## S4 method for signature 'FLPars' FLPars(object)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
Internal S4 data representation, of class list
.
As textual description of the object contents
Can the object be extended/trimmed? TRUE
or FALSE
.
A character vector for the element names
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
The FLQuant
class is a six-dimensional array
designed to store most quantitative data used in fisheries and population
modelling.
FLQuant(object, ...) ## S4 method for signature 'missing' FLQuant( object, dim = rep(1, 6), dimnames = "missing", quant = NULL, units = "NA", iter = 1 ) ## S4 method for signature 'vector' FLQuant( object, dim = rep(1, 6), dimnames = "missing", quant = NULL, units = "NA", iter = 1, fill.iter = TRUE ) ## S4 method for signature 'array' FLQuant( object, dim = rep(1, 6), dimnames = "missing", quant = NULL, units = "NA", iter = 1, fill.iter = TRUE ) ## S4 method for signature 'matrix' FLQuant(object, dim = lapply(dimnames, length), dimnames = "missing", ...) ## S4 method for signature 'FLQuant' FLQuant( object, quant = attributes(object)[["quant"]], units = attributes(object)[["units"]], dimnames = attributes(object)[["dimnames"]], iter = dim(object)[6], fill.iter = TRUE, dim = attributes(object)[["dim"]] )
FLQuant(object, ...) ## S4 method for signature 'missing' FLQuant( object, dim = rep(1, 6), dimnames = "missing", quant = NULL, units = "NA", iter = 1 ) ## S4 method for signature 'vector' FLQuant( object, dim = rep(1, 6), dimnames = "missing", quant = NULL, units = "NA", iter = 1, fill.iter = TRUE ) ## S4 method for signature 'array' FLQuant( object, dim = rep(1, 6), dimnames = "missing", quant = NULL, units = "NA", iter = 1, fill.iter = TRUE ) ## S4 method for signature 'matrix' FLQuant(object, dim = lapply(dimnames, length), dimnames = "missing", ...) ## S4 method for signature 'FLQuant' FLQuant( object, quant = attributes(object)[["quant"]], units = attributes(object)[["units"]], dimnames = attributes(object)[["dimnames"]], iter = dim(object)[6], fill.iter = TRUE, dim = attributes(object)[["dim"]] )
object |
Input numeric object |
... |
Additional arguments |
dim |
Vector of dimension lengths |
dimnames |
List of dimension names |
quant |
Character vector for name of first dimension |
units |
Character vctor of units of measurement, see uom |
iter |
Number of iterations, i.e. length of the 6th dimension |
fill.iter |
Should iterations be filled with the same content as the first? |
The six dimensions are named. The name of the first dimension can be
altered by the user from its default, quant
. This could typically be
age
or length
for data related to natural populations. The
only name not accepted is 'cohort', as data structured along cohort should
be stored using the FLCohort
class instead. Other dimensions
are always names as follows: year
, for the calendar year of the
datapoint; unit
, for any kind of division of the population, e.g. by
sex; season
, for any temporal strata shorter than year; area
,
for any kind of spatial stratification; and iter
, for replicates
obtained through bootstrap, simulation or Bayesian analysis.
In addition, FLQuant
objects contain a units
attribute, of
class character
, intended to contain the units of
measurement relevant to the data.
Array must have 6 dimensions
Array must be of class numeric
Dimensions 2 to 6 must be named "year", "unit", "season", "area" and "iter"
The FLQuant
method provides a flexible constructor for objects of the class.
Inputs can be of class:
vector
:A numeric vector will be placed along the year dimension by default.
matrix
:A matrix will be placed along dimensions 1 and 2, unless otherwise specified by 'dim'. The matrix dimnames will be used unless overriden by 'dimnames'.
As above
If no input is given, an empty FLQuant
(NA) is returned, but dimensions and dimnames can still be specified.
Additional arguments to the constructor:
The units of measurement, a character
string.
The dimensions of the object, a numeric
vector of length 6.
A list
object providing the dimnames of the array. Only those different from the default ones need to be specified.
The name of the first dimension, if different from 'quant', as a character
string.
The FLR Team
# creating a new FLQuant flq <- FLQuant() flq <- FLQuant(1:10, dim=c(2,5)) summary(flq) # Vectors are used column first... dim(FLQuant(1:10)) # ...while matrices go row first. dim(FLQuant(matrix(1:10))) FLQuant(matrix(rnorm(100), ncol=20)) FLQuant(array(rnorm(100), dim=c(5,2,1,1,1,10))) FLQuant(array(rnorm(100), dim=c(5,2)), iter=10) # working with FLQuant objects flq <- FLQuant(rnorm(200), dimnames=list(age=1:5, year=2000:2008), units='diff') summary(flq) flq[1,] flq[,1] flq[1,1] <- 0 units(flq) quant(flq) plot(flq) FLQuant() summary(FLQuant()) FLQuant(1:10) FLQuant(array(rnorm(9), dim=c(3,3,3))) FLQuant(matrix(rnorm(12), nrow=4, ncol=3)) FLQuant(FLQuant(array(rnorm(9), dim=c(3,3,3)), units='kg'), units='t')
# creating a new FLQuant flq <- FLQuant() flq <- FLQuant(1:10, dim=c(2,5)) summary(flq) # Vectors are used column first... dim(FLQuant(1:10)) # ...while matrices go row first. dim(FLQuant(matrix(1:10))) FLQuant(matrix(rnorm(100), ncol=20)) FLQuant(array(rnorm(100), dim=c(5,2,1,1,1,10))) FLQuant(array(rnorm(100), dim=c(5,2)), iter=10) # working with FLQuant objects flq <- FLQuant(rnorm(200), dimnames=list(age=1:5, year=2000:2008), units='diff') summary(flq) flq[1,] flq[,1] flq[1,1] <- 0 units(flq) quant(flq) plot(flq) FLQuant() summary(FLQuant()) FLQuant(1:10) FLQuant(array(rnorm(9), dim=c(3,3,3))) FLQuant(matrix(rnorm(12), nrow=4, ncol=3)) FLQuant(FLQuant(array(rnorm(9), dim=c(3,3,3)), units='kg'), units='t')
This extended FLQuant class holds both a measure of central tendendy (mean, median) and of dispersion (tipically variance), to be later used to generate, for example, random numbers with those mean and variances.
FLQuantDistr(object, var, ...) ## S4 method for signature 'ANY,ANY' FLQuantDistr(object, var, ...) ## S4 method for signature 'FLQuant,FLQuant' FLQuantDistr(object, var, units = object@units, distr = "norm")
FLQuantDistr(object, var, ...) ## S4 method for signature 'ANY,ANY' FLQuantDistr(object, var, ...) ## S4 method for signature 'FLQuant,FLQuant' FLQuantDistr(object, var, units = object@units, distr = "norm")
object |
Input numeric object |
... |
Additonal arguments |
Unnamed slot for storing the mean (or other measure of
expectation) (FLQuant
).
Variance, or other measure of dispersion, (FLQuant
).
Name of the probability distribution, see Details
(character
).
.Data and var slots must have the same dimensions.
.Data and var slots must have the same dimnames.
You can inspect the class validity function by using
getValidity(getClassDef('FLQuantDistr'))
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
The contents of the unnamed slot (.Data) can be accessed through the
e()
method, see Example below.
A construction method exists for this class that can take named arguments for
any of its slots. All slots are then created to match the requirements of the
class validity. If an unnamed FLQuant
object is provided, this is used
for the .Data slot.
Methods exist for various calculations based on values stored in the class:
.
The methods under the Arith group have been defined for objects of
this class, both for operations between two FLQuantDistr
objects and
with objects of class FLQuant
(FLArray
) as follows:
.
.
.
The FLR Team
data(ple4) fqd <- FLQuantDistr(catch.n(ple4), var=catch.n(ple4) * 10, distr='norm')
data(ple4) fqd <- FLQuantDistr(catch.n(ple4), var=catch.n(ple4) * 10, distr='norm')
This extended FLQuant class holds both a jackknifed FLQuant, one in which each
iter is missing one element, and the original object, as a separate
FLQuant
in the orig
slot.
## S4 method for signature 'ANY' FLQuantJK(object, orig) ## S4 method for signature 'FLQuantJK' orig(object) ## S4 method for signature 'FLQuants' orig(object)
## S4 method for signature 'ANY' FLQuantJK(object, orig) ## S4 method for signature 'FLQuantJK' orig(object) ## S4 method for signature 'FLQuants' orig(object)
object |
Input numeric object |
... |
Additonal arguments |
.Data and orig slots must have the same dimensions 1-5.
.Data and var slots must have the same dimnames 1-5.
You can inspect the class validity function by using
getValidity(getClassDef('FLQuantJK'))
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
Objects of this class must be constructed from an FLQuant that
is to be jackknifed, through the jackknife
method.
All methods defined for the FLQuant class are available, but
they will operate only on the jackknifed (.Data
) slot. Please use
orig()
to apply them to the original object stored in the class.
The FLR Team
data(ple4) fjk <- jackknife(stock(ple4)) # New object has as many iters as length of jackknifed dimension (defaults to 'year') dim(fjk)
data(ple4) fjk <- jackknife(stock(ple4)) # New object has as many iters as length of jackknifed dimension (defaults to 'year') dim(fjk)
The FLQuantPoint
class summarizes the contents of an FLQuant
object with multiple iterations along its sixth dimension using a number of
descriptive statistics.
FLQuantPoint(object, ...) ## S4 method for signature 'missing' FLQuantPoint(..., units = "NA", n = 1) ## S4 method for signature 'FLQuant' FLQuantPoint(object, ..., probs = c(0.25, 0.75)) ## S4 method for signature 'FLQuantPoint' n(object, ...)
FLQuantPoint(object, ...) ## S4 method for signature 'missing' FLQuantPoint(..., units = "NA", n = 1) ## S4 method for signature 'FLQuant' FLQuantPoint(object, ..., probs = c(0.25, 0.75)) ## S4 method for signature 'FLQuantPoint' n(object, ...)
object |
Input numeric object |
... |
Additonal arguments |
An object of this class has a set structure along its sixth dimension (iter), which will always be of length 5, and with dimnames mean, median, var, uppq and lowq. They refer, respectively, to the sample mean, sample median, variance, and lower (0.25) and upper (0.75) quantiles.
Objects of this class wil be typically created from an FLQuant
. The
various statistics are calculated along the iter dimension of the
original FLQuant
using apply
.
The main array holding the computed statistics. array
.
Units of measurement. character
.
'mean' element on 6th dimension, arithmetic mean.
'median' element on 6th dimension, median.
'var' element on 6th dimension, variance.
'lowq' element on 6th dimension, lower quantile (0.25 by default).
'uppq' element on 6th dimension, upper quantile (0.75 by default).
returns the 'lowq' or 'uppq' iter, depending on the value of 'probs' (0.25 or 0.75).
Inputs can be of class:
FLQuant
:An FLQuant object with iters (i.e. dim6 > 1)
iter dimension is of length 5.
iter dimnames are 'mean', 'median', 'var', 'uppq' and'lowq'
The FLR Team
flq <- FLQuant(rlnorm(2000), dim=c(10,20,1,1,1,200), units="kg") flqp <- FLQuantPoint(flq) flqp <- FLQuantPoint(flq, probs=c(0.05, 0.95)) summary(flqp) mean(flqp) var(flqp) rnorm(200, flqp)
flq <- FLQuant(rlnorm(2000), dim=c(10,20,1,1,1,200), units="kg") flqp <- FLQuantPoint(flq) flqp <- FLQuantPoint(flq, probs=c(0.05, 0.95)) summary(flqp) mean(flqp) var(flqp) rnorm(200, flqp)
FLQuants
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 FLQuants
must all be of class
FLQuant
.
FLQuants(object, ...) ## S4 method for signature 'ANY' FLQuants(object, ...) ## S4 method for signature 'FLComp' FLQuants(object, ...) ## S4 method for signature 'missing' FLQuants(object, ...) ## S4 method for signature 'list' FLQuants(object, ...) ## S4 method for signature 'FLQuants' FLQuants(object, ...)
FLQuants(object, ...) ## S4 method for signature 'ANY' FLQuants(object, ...) ## S4 method for signature 'FLComp' FLQuants(object, ...) ## S4 method for signature 'missing' FLQuants(object, ...) ## S4 method for signature 'list' FLQuants(object, ...) ## S4 method for signature 'FLQuants' FLQuants(object, ...)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock
mechanism, if turned on the length of the list can not be modified by adding
or removing elements. logical
.
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
*, Arith, as.data.frame, bubbles, catch<-, iter, model.frame, show, summary, xyplot, FLlst, list
# Compute various FLStock indicators data(ple4) fqs <- FLQuants(ssb=ssb(ple4), catch=catch(ple4), rec=rec(ple4), f=fbar(ple4)) summary(fqs) xyplot(data~year|qname, fqs, type='b', scales=list(relation='free'))
# Compute various FLStock indicators data(ple4) fqs <- FLQuants(ssb=ssb(ple4), catch=catch(ple4), rec=rec(ple4), f=fbar(ple4)) summary(fqs) xyplot(data~year|qname, fqs, type='b', scales=list(relation='free'))
A virtual class that forms the basis for the FLStock
and FLStockLen
classes. No objects of this class can be
constructed.
No particular validity checks
Total catch weight (FLQuant
).
Catch numbers (FLQuant
).
Mean catch weights (FLQuant
).
Description of the stock (character
).
Total discards weight (FLQuant
).
Discard numbers (FLQuant
).
Mean discard weights (FLQuant
).
Total landings weight (FLQuant
).
Landing numbers (FLQuant
).
Landing weights (FLQuant
).
Total stock weight (FLQuant
).
Stock numbers (FLQuant
).
Mean stock weights (FLQuant
).
Natural mortality (FLQuant
).
Proportion of natural mortality before spawning (FLQuant
).
Proportion mature (FLQuant
).
Harvest rate or fishing mortality. The units of this slot
should be set to 'harvest' or 'f' accordingly (FLQuant
).
Proportion of harvest/fishing mortality before
spawning (FLQuant
).
Name of the stock (character
).
Named numeric vector containing the quant and year ranges,
the plusgroup and the quant range that the average fishing mortality should
be calculated over (numeric
).
The FLR Team
[, [<-, as.data.frame, iter, propagate, qapply, summary, transform, trim, units,FLComp-method, units<-,FLComp,list-method, window
Class for stock-recruitment models.
FLSR(model, ...) ## S4 method for signature 'ANY' FLSR(model, ...) ## S4 method for signature 'missing' FLSR(model, ...)
FLSR(model, ...) ## S4 method for signature 'ANY' FLSR(model, ...) ## S4 method for signature 'missing' FLSR(model, ...)
A series of commonly-used stock-recruitment models are already available,
including the corresponding likelihood functions and calculation of initial
values. See SRModels
for more details and the exact
formulation implemented for each of them.
Name of the object (character
).
Description of the object (character
).
Range (numeric
).
Recruitment series (FLQuant
).
Index of reproductive potential, e.g. SSB or egg oor egg production (FLQuant
).
Estimated values for rec (FLQuant
).
Residuals obtained from the model fit (FLArray
).
Covariates for SR model (FLQuants
).
Model formula (formula
).
Function returning the gradient of the likelihood (function
).
Log-likelihood function (function
).
Function returning initial parameter values for the optimizer (function
).
Estimated parameter values (FLPar
).
Value of the log-likelihood (logLik
).
Variance-covariance matrix (array
).
Extra information on the model fit procedure (list
).
Is the error on a log scale (logical
).
(factor
).
Resulting Hessian matrix from the fit (array
).
The FLR Team
# Create an empty FLSR object. sr1 <- FLSR() # Create an FLSR object using the existing SR models. sr2 <- FLSR(model = 'ricker') sr2@model sr2@initial sr2@logl sr3 <- FLSR(model = 'bevholt') sr3@model sr3@initial sr3@logl # Create an FLSR using a function. mysr1 <- function(){ model <- rec ~ a*ssb^b return(list(model = model))} sr4 <- FLSR(model = mysr1) # Create an FLSR using a function and check that it works. mysr2 <- function(){ formula <- rec ~ a+ssb*b logl <- function(a, b, sigma, rec, ssb) sum(dnorm(rec, a + ssb*b, sqrt(sigma), TRUE)) initial <- structure(function(rec, ssb) { a <- mean(rec) b <- 1 sigma <- sqrt(var(rec)) return(list(a=a, b=b, sigma=sigma))}, lower = c(0, 1e-04, 1e-04), upper = rep(Inf, 3)) return(list(model = formula, initial = initial, logl = logl)) } ssb <- FLQuant(runif(10, 10000, 100000)) rec <- 10000 + 2*ssb + rnorm(10,0,1) sr5 <- FLSR(model = mysr2, ssb = ssb, rec = rec) sr5.mle <- fmle(sr5) sr5.nls <- nls(sr5) # NS Herring stock-recruitment dataset data(nsher) # already fitted with a Ricker SR model summary(nsher) plot(nsher) # change model model(nsher) <- bevholt() # fit through MLE nsher <- fmle(nsher) plot(nsher)
# Create an empty FLSR object. sr1 <- FLSR() # Create an FLSR object using the existing SR models. sr2 <- FLSR(model = 'ricker') sr2@model sr2@initial sr2@logl sr3 <- FLSR(model = 'bevholt') sr3@model sr3@initial sr3@logl # Create an FLSR using a function. mysr1 <- function(){ model <- rec ~ a*ssb^b return(list(model = model))} sr4 <- FLSR(model = mysr1) # Create an FLSR using a function and check that it works. mysr2 <- function(){ formula <- rec ~ a+ssb*b logl <- function(a, b, sigma, rec, ssb) sum(dnorm(rec, a + ssb*b, sqrt(sigma), TRUE)) initial <- structure(function(rec, ssb) { a <- mean(rec) b <- 1 sigma <- sqrt(var(rec)) return(list(a=a, b=b, sigma=sigma))}, lower = c(0, 1e-04, 1e-04), upper = rep(Inf, 3)) return(list(model = formula, initial = initial, logl = logl)) } ssb <- FLQuant(runif(10, 10000, 100000)) rec <- 10000 + 2*ssb + rnorm(10,0,1) sr5 <- FLSR(model = mysr2, ssb = ssb, rec = rec) sr5.mle <- fmle(sr5) sr5.nls <- nls(sr5) # NS Herring stock-recruitment dataset data(nsher) # already fitted with a Ricker SR model summary(nsher) plot(nsher) # change model model(nsher) <- bevholt() # fit through MLE nsher <- fmle(nsher) plot(nsher)
FLSRS
is a class that extends list
through FLlst
but
implements a set of features that give a little bit more structure to list
objects. The elements of FLSRs
must all be of class
FLSR
. It implements a lock mechanism that, when turned on, does
not allow the user to increase or decrease the object length.FLSRS
is a class that extends list
through FLlst
but
implements a set of features that give a little bit more structure to list
objects. The elements of FLSRs
must all be of class
FLSR
. It implements a lock mechanism that, when turned on, does
not allow the user to increase or decrease the object length.
FLSRs(object, ...) ## S4 method for signature 'FLSR' FLSRs(object, ...) ## S4 method for signature 'missing' FLSRs(object, ...) ## S4 method for signature 'list' FLSRs(object, ...)
FLSRs(object, ...) ## S4 method for signature 'FLSR' FLSRs(object, ...) ## S4 method for signature 'missing' FLSRs(object, ...) ## S4 method for signature 'list' FLSRs(object, ...)
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock
mechanism, if turned on the length of the list can not be modified by adding
or removing elements. logical
.
The FLR Team
data(nsher) bnsher <- nsher model(bnsher) <- bevholt bnsher <- fmle(bnsher) fls <- FLSRs(Ricker=nsher, BevHolt=bnsher) summary(fls)
data(nsher) bnsher <- nsher model(bnsher) <- bevholt bnsher <- fmle(bnsher) fls <- FLSRs(Ricker=nsher, BevHolt=bnsher) summary(fls)
A class for modelling a fish stock.
FLStock(object, ...) ## S4 method for signature 'FLQuant' FLStock(object, plusgroup = dims(object)$max, ...) ## S4 method for signature 'missing' FLStock(object, ...) ## S4 method for signature 'FLQuants' FLStock(object, ...)
FLStock(object, ...) ## S4 method for signature 'FLQuant' FLStock(object, plusgroup = dims(object)$max, ...) ## S4 method for signature 'missing' FLStock(object, ...) ## S4 method for signature 'FLQuants' FLStock(object, ...)
object |
FLQuant object used for sizing |
... |
Other objects to be assigned by name to the class slots |
plusgroup |
Plusgroup age, to be stored in range |
The FLStock
object contains a representation of a fish stock as
constructed for the purposes of scientific analysis and advice. This includes
information on removals (i.e. catches, landings and discards), maturity,
natural mortality and the results of an analytical assessment (i.e. estimates
of abundance and removal rates) .
Total catch weight (FLQuant
).
Catch numbers (FLQuant
).
Mean catch weights (FLQuant
).
Total discards weight (FLQuant
).
Discard numbers (FLQuant
).
Mean discard weights (FLQuant
).
Total landings weight (FLQuant
).
Landing numbers (FLQuant
).
Landing weights (FLQuant
).
Total stock weight (FLQuant
).
Stock numbers (FLQuant
).
Mean stock weights (FLQuant
).
Natural mortality (FLQuant
).
Proportion mature (FLQuant
).
Harvest rate or fishing mortality. The units of this slot
should be set to 'hr' or 'f' accordingly (FLQuant
).
Proportion of harvest/fishing mortality before
spawning (FLQuant
).
Proportion of natural mortality before spawning
(FLQuant
).
Name of the stock (character
).
Description of the stock (character
).
Named numeric vector containing the quant and year ranges,
the plusgroup and the quant range that the average fishing mortality should
be calculated over (numeric
).
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
A construction method exists for this class that can take named arguments for
any of its slots. All slots are then created to match the requirements of the
class validity. If an unnamed FLQuant
object is provided, this is used
for sizing but not stored in any slot.
The FLR Team
[, [<-, as.FLBiol, as.FLSR, catch, catch<-, catch.n, catch.n<-, catch.wt, catch.wt<-, coerce, computeCatch, computeDiscards, computeLandings, discards, discards<-, discards.n, discards.n<-, discards.wt, discards.wt<-, harvest, harvest<-, harvest.spwn, landings, landings<-, landings.n, landings.n<-, landings.wt, landings.wt<-, m, m<-, mat, m.spwn, plot, ssb, ssbpurec, stock, stock.n, stock.wt, trim, FLComp
data(ple4) summary(ple4) # get the landings slot and assign values to it landings(ple4) landings(ple4) <- apply(landings.n(ple4)*landings.wt(ple4),2,sum) # perform similar calculation as the preceding apply function discards(ple4) <- computeDiscards(ple4) catch(ple4) <- computeCatch(ple4) catch(ple4) <- computeCatch(ple4, slot="all") # set the units of the harvest slot of an FLStock object harvest(ple4) <- 'f' # subset and trim the FLStock ple4[,1] trim(ple4, age=2:6, year=1980:1990) # Calculate SSB, and SSB per recruit at zero fishing mortality ssb(ple4) ssbpurec(ple4) # Coerce an FLStock to an FLBiol biol <- as(ple4, "FLBiol") # Initialise an FLSR object from an FLStock flsr <- as.FLSR(ple4)
data(ple4) summary(ple4) # get the landings slot and assign values to it landings(ple4) landings(ple4) <- apply(landings.n(ple4)*landings.wt(ple4),2,sum) # perform similar calculation as the preceding apply function discards(ple4) <- computeDiscards(ple4) catch(ple4) <- computeCatch(ple4) catch(ple4) <- computeCatch(ple4, slot="all") # set the units of the harvest slot of an FLStock object harvest(ple4) <- 'f' # subset and trim the FLStock ple4[,1] trim(ple4, age=2:6, year=1980:1990) # Calculate SSB, and SSB per recruit at zero fishing mortality ssb(ple4) ssbpurec(ple4) # Coerce an FLStock to an FLBiol biol <- as(ple4, "FLBiol") # Initialise an FLSR object from an FLStock flsr <- as.FLSR(ple4)
A class for modelling a length-structured fish stock.
FLStockLen(object, ...) ## S4 method for signature 'FLQuant' FLStockLen(object, ...) ## S4 method for signature 'missing' FLStockLen(object, ...)
FLStockLen(object, ...) ## S4 method for signature 'FLQuant' FLStockLen(object, ...) ## S4 method for signature 'missing' FLStockLen(object, ...)
The FLStockLen
object contains a length based representation of a
fish stock. This includes information on removals (i.e. catches, landings and
discards), maturity, natural mortality and the results of an analytical
assessment (i.e. estimates of abundance and removal rates).
The middle of the length bins (numeric
).
Total catch weight (FLQuant
).
Catch numbers (FLQuant
).
Mean catch weights (FLQuant
).
Total discards weight (FLQuant
).
Discard numbers (FLQuant
).
Mean discard weights (FLQuant
).
Total landings weight (FLQuant
).
Landing numbers (FLQuant
).
Landing weights (FLQuant
).
Total stock weight (FLQuant
).
Stock numbers (FLQuant
).
Mean stock weights (FLQuant
).
Natural mortality (FLQuant
).
Proportion mature (FLQuant
).
Harvest rate or fishing mortality. The units of this slot
should be set to 'harvest' or 'f' accordingly (FLQuant
).
Proportion of harvest/fishing mortality before
spawning (FLQuant
).
Proportion of natural mortality before spawning
(FLQuant
).
Name of the stock (character
).
Description of the stock (character
).
Named numeric vector containing the quant and year ranges,
the plusgroup and the quant range that the average fishing mortality should
be calculated over (numeric
).
The FLR Team
[, [<-, as.FLBiol, as.FLSR, computeCatch, computeDiscards, computeLandings, plot, ssb, ssbpurec, trim, FLComp
stkl <- FLStockLen(m=FLQuant(0.2, dimnames=list(len=seq(5, 50, by=2), year=2015:2020))) summary(stkl) # Unnamed FLQuant used for sizing stkl <- FLStockLen(FLQuant(0.2, dimnames=list(len=seq(5, 50, by=2), year=2015:2020))) summary(stkl) m(stkl)
stkl <- FLStockLen(m=FLQuant(0.2, dimnames=list(len=seq(5, 50, by=2), year=2015:2020))) summary(stkl) # Unnamed FLQuant used for sizing stkl <- FLStockLen(FLQuant(0.2, dimnames=list(len=seq(5, 50, by=2), year=2015:2020))) summary(stkl) m(stkl)
FLStocks
is a class that extends list
through FLlst
but
implements a set of features that give a little bit more structure to list
objects. The elements of FLStocks
must all be of class
FLStock
. It implements a lock mechanism that, when turned on, does
not allow the user to increase or decrease the object length.
FLStocks(object, ...) ## S4 method for signature 'FLStock' FLStocks(object, ...) ## S4 method for signature 'missing' FLStocks(object, ...) ## S4 method for signature 'list' FLStocks(object, ...)
FLStocks(object, ...) ## S4 method for signature 'FLStock' FLStocks(object, ...) ## S4 method for signature 'missing' FLStocks(object, ...) ## S4 method for signature 'list' FLStocks(object, ...)
object |
unnamed object to be added to the list |
... |
other named or unnamed objects |
The data. list
.
Names of the list elements. character
.
Description of the object. character
.
Lock
mechanism, if turned on the length of the list can not be modified by adding
or removing elements. logical
.
A constructor method exists for this class that can take named arguments for any of the list elements.
The FLR Team
data(ple4) fls <- FLStocks(sa=ple4, sb=window(ple4, end=1980)) summary(fls)
data(ple4) fls <- FLStocks(sa=ple4, sb=window(ple4, end=1980)) summary(fls)
Recruitment in number of fish is the first row of the 'stock.n' slot of an age-structured 'FLStock'. These convenience functions allow a clearer syntax when retrieving of altering the content of 'stock.nrec.age,', where 'rec.age' is usually the first age in the object.
## S4 method for signature 'FLStock' rec(object, rec.age = as.character(object@range["min"]))
## S4 method for signature 'FLStock' rec(object, rec.age = as.character(object@range["min"]))
object |
An object of class 'FLStock' |
rec.age |
What age to extract, defaults to first one. As 'character' to select by name or as 'numeric' by position. |
RETURN Lorem ipsum dolor sit amet
The FLR Team
data(ple4) rec(ple4) # Multiple recruitment by a factor of 2 rec(ple4) <- rec(ple4) * 2
data(ple4) rec(ple4) # Multiple recruitment by a factor of 2 rec(ple4) <- rec(ple4) * 2
Computes the fishing mortality at age (harvest) associated with either landings (Fwanted) or discards (Funwanted) through the respective proportions at age. The function names reflect the convention used in ICES.
Funwanted(x, ages = dimnames(x)$age)
Funwanted(x, ages = dimnames(x)$age)
x |
An FLStock object, with harvest |
ages |
Ages over which the respective Fbar calculation applies |
An FLQuant
data(ple4) Fwanted(ple4, ages=2:6) Funwanted(ple4, ages=1:3)
data(ple4) Fwanted(ple4, ages=2:6) Funwanted(ple4, ages=1:3)
Objects to be projected into the future are extended until an end year, and the values of certain quantities, usually assume constant, are set following different mechanisms.
fwdWindow(x, y, ...) ## S4 method for signature 'FLStock,missing' fwdWindow( x, end = dims(x)$maxyear, nsq = 3, fun = c("mean", "sample"), years = list(wt = nsq, mat = nsq, m = nsq, spwn = nsq, discards.ratio = nsq, catch.sel = nsq) )
fwdWindow(x, y, ...) ## S4 method for signature 'FLStock,missing' fwdWindow( x, end = dims(x)$maxyear, nsq = 3, fun = c("mean", "sample"), years = list(wt = nsq, mat = nsq, m = nsq, spwn = nsq, discards.ratio = nsq, catch.sel = nsq) )
x |
The FLR object to extend. |
y |
A second object from which information is taken. |
For 'FLStock'
An object of the same class as 'x'.
The FLR Team.
data(ple4) # Use mean of last three years and extend until 2020 fut <- fwdWindow(ple4, end=2020) # Check values on catch.wt catch.wt(fut)[, ac(2015:2020)] # Use mean of the 2010:2015 period fut <- fwdWindow(ple4, end=2020, years=2010:2015) # Use last three years mean, but last five for 'wt' fut <- fwdWindow(ple4, end=2020, nsq=3, years=list(wt=5)) stock.wt(fut)[, ac(2013:2020)] catch.sel(fut)[, ac(2013:2020)] # Resample from last years for 'wt' fut <- fwdWindow(ple4, end=2020, nsq=3, fun=c(wt='sample')) # Years to resample can be different for 'catch.sel' fut <- fwdWindow(ple4, end=2020, nsq=3, fun=c(wt='sample', catch.sel='sample'), years=c(wt=10, catch.sel=5)) # 'wt' slot has been resampled, stock.wt(fut)[, ac(2015:2020)] # while others have used a 3 year average catch.sel(fut)[, ac(2015:2020)]
data(ple4) # Use mean of last three years and extend until 2020 fut <- fwdWindow(ple4, end=2020) # Check values on catch.wt catch.wt(fut)[, ac(2015:2020)] # Use mean of the 2010:2015 period fut <- fwdWindow(ple4, end=2020, years=2010:2015) # Use last three years mean, but last five for 'wt' fut <- fwdWindow(ple4, end=2020, nsq=3, years=list(wt=5)) stock.wt(fut)[, ac(2013:2020)] catch.sel(fut)[, ac(2013:2020)] # Resample from last years for 'wt' fut <- fwdWindow(ple4, end=2020, nsq=3, fun=c(wt='sample')) # Years to resample can be different for 'catch.sel' fut <- fwdWindow(ple4, end=2020, nsq=3, fun=c(wt='sample', catch.sel='sample'), years=c(wt=10, catch.sel=5)) # 'wt' slot has been resampled, stock.wt(fut)[, ac(2015:2020)] # while others have used a 3 year average catch.sel(fut)[, ac(2015:2020)]
This function returns the names, as a character vector, of the slots in an S4 object that are of the class specified by the 'class' argument. Comparison is done using is(), so class inheritance is matched.
getSlotNamesClass(object, class)
getSlotNamesClass(object, class)
object |
An S4 object to check slots from. |
class |
The name of the class to match, 'character'. |
The FLR Team
data(ple4) getSlotNamesClass(ple4, 'FLQuant')
data(ple4) getSlotNamesClass(ple4, 'FLQuant')
Array objects (e.g. FLQuant or FLQuants) are divided along a single dimnension following a given index or expression, an aggregating function is applied to each subset, and the results are joined again. Data can be added, for example, by decade or for two age groups.
group(x, FUN, ...) ## S4 method for signature 'FLQuant,function' group(x, FUN = sum, ...)
group(x, FUN, ...) ## S4 method for signature 'FLQuant,function' group(x, FUN = sum, ...)
x |
An object to group. |
FUN |
A function to apply along the chosen dimension, defaults to 'sum'. |
... |
An expression or indexing vector, named as the chosen dimension. Extra arguments to FUN can also be provided, but cannmot match names in x. |
A single object with reduced dimensionality.
Iago Mosqueira (WMR)
data(ple4) # Add catch-at-age along two age groups, 'juv'eniles and 'adu'lts group(catch.n(ple4), sum, age=c('juv', 'juv', rep('adu', 8))) # An expression can use based on dimnames group(catch.n(ple4), sum, age=age < 3) # Mean by lustrum, by using 'year - year %% 5' group(catch.n(ple4), mean, year = year - year %% 5)
data(ple4) # Add catch-at-age along two age groups, 'juv'eniles and 'adu'lts group(catch.n(ple4), sum, age=c('juv', 'juv', rep('adu', 8))) # An expression can use based on dimnames group(catch.n(ple4), sum, age=age < 3) # Mean by lustrum, by using 'year - year %% 5' group(catch.n(ple4), mean, year = year - year %% 5)
The inter-annual variability of a time series stored in an FLQuant object,
is computed as . The resulting object will
be one year shorter than the input. The first year will be missing as values
are assigned to the final year of each pair.
iav(object)
iav(object)
An object of the same class as object.
The FLR Team
data(ple4) # Compute inter-annual variability in catch iav(catch(ple4))
data(ple4) # Compute inter-annual variability in catch iav(catch(ple4))
z = (k * (linf - lmean)) / (lmean - lc) lmean = sum(naa * len) / sum(naa) lc, length at first capture
indicators.len( object, indicators = "lbar", model = vonbert, params, cv = 0.1, lmax = 1.25, bin = 1, n = 500, metric = catch.n, ... ) lenquantile(x, quantile = 0.5) lmax5(x) l95(x) l25(x) lc50(x) lmode(x) lbar(x) lmean(x) lmaxy(x, lenwt) pmega(x, linf, lopt = linf * 2/3) bheqz(x, linf, k, t0, lc = lc50(x))
indicators.len( object, indicators = "lbar", model = vonbert, params, cv = 0.1, lmax = 1.25, bin = 1, n = 500, metric = catch.n, ... ) lenquantile(x, quantile = 0.5) lmax5(x) l95(x) l25(x) lc50(x) lmode(x) lbar(x) lmean(x) lmaxy(x, lenwt) pmega(x, linf, lopt = linf * 2/3) bheqz(x, linf, k, t0, lc = lc50(x))
Kell, L.T., Minto, C., Gerritsen, H.D. 2022. Evaluation of the skill of length-based indicators to identify stock status and trends. ICES Journal of Marine Science. doiu: 10.1093/icesjms/fsac043.
ICES. 2015. Report of the Fifth Workshop on the Development of Quantitative Assessment Methodologies based on Life-history Traits, Exploitation Characteristics and other Relevant Parameters for Data-limited Stocks (WKLIFE V), 5–9 October 2015, Lisbon, Portugal. ICES CM 2015/ACOM:56. 157 pp.
ICES. 2020. Tenth Workshop on the Development of Quantitative Assessment Methodologies based on LIFE-history traits, exploitation characteristics, and other relevant parameters for data-limited stocks (WKLIFE X). ICES Scientific Reports. 2:98. 72 pp. http://doi.org/10.17895/ices.pub.5985
data(ple4) indicators.len(ple4, indicators=c('lbar', 'lmaxy'), params=FLPar(linf=132, k=0.080, t0=-0.35), metric='catch.n', lenwt=FLPar(a=0.01030, b=2.975)) indicators.len(ple4, indicators=c('pmega'), params=FLPar(linf=60, k=2.29e-01, t0=-1.37), metric='catch.n') data(ple4.index) indicators.len(ple4.index, indicators=c('lbar', 'lmean'), params=FLPar(linf=132, k=0.080, t0=-0.35), metric='index') # ialk <- invALK(params=FLPar(linf = 60, k = 2.29e-01, t0 = -1.37e+00), model=vonbert, age=1:10, lmax=1.2) samps <- lenSamples(catch.n(ple4), invALK=ialk, n=250) lenquantile(samps, 0.50) lmax5(samps) l95(samps) l25(samps) lc50(samps) lmode(samps) lbar(samps) lmean(samps) # Linf(ple4) = 60 lmean(samps) / (0.75 * lc50(samps) + 0.25 * 60) # lenwt <- FLPar(a=0.01030, b=2.975) lmaxy(samps, lenwt) pmega(samps, linf=60) linf <- 60 k <- 2.29e-01 t0 <- -1.37e+00 bheqz(samps, linf = 60, k = 2.29e-01, t0 = -1.37e+00)
data(ple4) indicators.len(ple4, indicators=c('lbar', 'lmaxy'), params=FLPar(linf=132, k=0.080, t0=-0.35), metric='catch.n', lenwt=FLPar(a=0.01030, b=2.975)) indicators.len(ple4, indicators=c('pmega'), params=FLPar(linf=60, k=2.29e-01, t0=-1.37), metric='catch.n') data(ple4.index) indicators.len(ple4.index, indicators=c('lbar', 'lmean'), params=FLPar(linf=132, k=0.080, t0=-0.35), metric='index') # ialk <- invALK(params=FLPar(linf = 60, k = 2.29e-01, t0 = -1.37e+00), model=vonbert, age=1:10, lmax=1.2) samps <- lenSamples(catch.n(ple4), invALK=ialk, n=250) lenquantile(samps, 0.50) lmax5(samps) l95(samps) l25(samps) lc50(samps) lmode(samps) lbar(samps) lmean(samps) # Linf(ple4) = 60 lmean(samps) / (0.75 * lc50(samps) + 0.25 * 60) # lenwt <- FLPar(a=0.01030, b=2.975) lmaxy(samps, lenwt) pmega(samps, linf=60) linf <- 60 k <- 2.29e-01 t0 <- -1.37e+00 bheqz(samps, linf = 60, k = 2.29e-01, t0 = -1.37e+00)
Objects sharing certain dimensions, as inferred by their dimnames, are subset to the common ones along all dimensions. The returned object is of one of the FLlst classes, as corresponds to the input class. The objects in the list can then be, for example, combined or directly compared, as shown in the examples.
## S4 method for signature 'FLArray,FLArray' intersect(x, y)
## S4 method for signature 'FLArray,FLArray' intersect(x, y)
x |
First object to be compared and subset |
y |
Second object to be compared and subset |
And object of the corresponding FLsdt-based plural class.
The FLR Team
big <- FLQuant(64.39, dimnames=list(age=1:4, year=2001:2012)) small <- FLQuant(3.52, dimnames=list(age=2:3, year=2001:2005)) intersect(big, small) # Two FLQuant objects can be added along their common dimension using Reduce() Reduce('+', intersect(big, small))
big <- FLQuant(64.39, dimnames=list(age=1:4, year=2001:2012)) small <- FLQuant(3.52, dimnames=list(age=2:3, year=2001:2005)) intersect(big, small) # Two FLQuant objects can be added along their common dimension using Reduce() Reduce('+', intersect(big, small))
Select or modify iterations of an FLR object
iter(obj, ...) ## S4 method for signature 'FLArray' iter(obj, iter)
iter(obj, ...) ## S4 method for signature 'FLArray' iter(obj, iter)
To extract or modify a subset of the iterations contained in an FLR object,
the iter
and iter<-
methods can be used.
In complex objects with various FLQuant
slots, the iter
method
checks whether individual slots contain more than one iteration, i.e.
dims(object)[6] > 1
. If a particular slot contains a single
iteration, that is returned, otherwise the chosen iteration is selected.
This is in contrast with the subset operator [
, which does not carry
out this check.
For objects of class FLModel
, iters are extracted for slots of
classes FLQuant
, FLCohort
and FLPar
.
iter(object) iter<-(object,value)
The FLR Team
# For an FLQuant flq <- FLQuant(rnorm(800), dim=c(4,10,2), iter=10) iter(flq, 2) # For the more complex FLStock object data(ple4) fls <- propagate(ple4, 10) # Extraction using iter... fls2 <- iter(fls, 2) summary(fls2)
# For an FLQuant flq <- FLQuant(rnorm(800), dim=c(4,10,2), iter=10) iter(flq, 2) # For the more complex FLStock object data(ple4) fls <- propagate(ple4, 10) # Extraction using iter... fls2 <- iter(fls, 2) summary(fls2)
Jackknife resampling
## S4 method for signature 'FLQuant' jackknife(object, dim = "year", na.rm = TRUE) ## S4 method for signature 'FLQuants' jackknife(object, ...) ## S4 method for signature 'FLModel' jackknife(object, slot)
## S4 method for signature 'FLQuant' jackknife(object, dim = "year", na.rm = TRUE) ## S4 method for signature 'FLQuants' jackknife(object, ...) ## S4 method for signature 'FLModel' jackknife(object, slot)
The jackknife
method sets up objects ready for jackknifing, i.e. to
systematically recompute a given statistic leaving out one observation at a
time. From this new set of "observations" for the statistic, estimates for
the bias and variance of the statstic can be calculated.
Input objects cannot have length > 1 along the iter
dimension, and
the main slot in the resulting object will have as many iter
s as the
number of elements in the original object that are not NA
.
jackknife(object, ...)
The FLR Team
flq <- FLQuant(1:8) flj <- jackknife(flq) iters(flj)
flq <- FLQuant(1:8) flj <- jackknife(flq) iters(flj)
FLQuant objects are joined along a single dimension, on which dimnames are different. This is the reverse operation to divide.
join(x, y, ...) ## S4 method for signature 'FLQuant,FLQuant' join(x, y) ## S4 method for signature 'FLQuants,missing' join(x, y)
join(x, y, ...) ## S4 method for signature 'FLQuant,FLQuant' join(x, y) ## S4 method for signature 'FLQuants,missing' join(x, y)
x |
An object to join |
y |
An object to join |
A single object
Iago Mosqueira (WMR)
data(ple4) # JOIN over age dimension x <- catch.n(ple4)[1,] y <- catch.n(ple4)[2,] join(x, y) # JOIN over year dimension x <- catch.n(ple4)[,10:20] y <- catch.n(ple4)[,21:25] join(x, y) div <- divide(catch.n(ple4), dim=1) is(div) length(div) join(div) all.equal(join(divide(catch.n(ple4), dim=1)), catch.n(ple4))
data(ple4) # JOIN over age dimension x <- catch.n(ple4)[1,] y <- catch.n(ple4)[2,] join(x, y) # JOIN over year dimension x <- catch.n(ple4)[,10:20] y <- catch.n(ple4)[,21:25] join(x, y) div <- divide(catch.n(ple4), dim=1) is(div) length(div) join(div) all.equal(join(divide(catch.n(ple4), dim=1)), catch.n(ple4))
Implementation of Trellis graphics in FLR
## S4 method for signature 'formula,FLQuant' xyplot(x, data, ...) ## S4 method for signature 'formula,FLCohort' xyplot(x, data, ...) ## S4 method for signature 'formula,FLQuants' xyplot(x, data, ...) ## S4 method for signature 'formula,FLComp' xyplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' bwplot(x, data, ...) ## S4 method for signature 'formula,FLComp' bwplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' dotplot(x, data, ...) ## S4 method for signature 'formula,FLComp' dotplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' barchart(x, data, ...) ## S4 method for signature 'formula,FLComp' barchart(x, data, ...) ## S4 method for signature 'formula,FLQuant' stripplot(x, data, ...) ## S4 method for signature 'formula,FLComp' stripplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' histogram(x, data, ...) ## S4 method for signature 'formula,FLComp' histogram(x, data, ...) ## S4 method for signature 'formula,FLQuants' histogram(x, data, ...) ## S4 method for signature 'formula,FLPar' densityplot(x, data, ...)
## S4 method for signature 'formula,FLQuant' xyplot(x, data, ...) ## S4 method for signature 'formula,FLCohort' xyplot(x, data, ...) ## S4 method for signature 'formula,FLQuants' xyplot(x, data, ...) ## S4 method for signature 'formula,FLComp' xyplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' bwplot(x, data, ...) ## S4 method for signature 'formula,FLComp' bwplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' dotplot(x, data, ...) ## S4 method for signature 'formula,FLComp' dotplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' barchart(x, data, ...) ## S4 method for signature 'formula,FLComp' barchart(x, data, ...) ## S4 method for signature 'formula,FLQuant' stripplot(x, data, ...) ## S4 method for signature 'formula,FLComp' stripplot(x, data, ...) ## S4 method for signature 'formula,FLQuant' histogram(x, data, ...) ## S4 method for signature 'formula,FLComp' histogram(x, data, ...) ## S4 method for signature 'formula,FLQuants' histogram(x, data, ...) ## S4 method for signature 'formula,FLPar' densityplot(x, data, ...)
Plot methods in the lattice
package are available for
an object of classes FLQuant
, FLQuants
or those derived from
FLComp
.
See the help page in lattice
for a full description
of each plot method and all possible arguments.
Plot methods from lattice are called by passing a data.frame obtained by converting the FLR objects using as.data.frame. For details on this transformation, see as.data.frame-FLCore.
barchart(x, data, ...)
bwplot(x, data, ...)
densityplot(x, data, ...)
dotplot(x, data, ...)
histogram(x, data, ...)
stripplot(x, data, ...)
xyplot(x, data, ...)
The FLR Team
xyplot, barchart, bwplot, densityplot, dotplot, histogram, stripplot
data(ple4) # xyplot on FLQuant xyplot(data~year|age, catch.n(ple4)[, 1:20]) xyplot(data~year|as.factor(age), catch.n(ple4)[, 1:20], type='b', pch=19, cex=0.5) # bwplot on FLQuant with iter... flq <- rnorm(100, catch.n(ple4)[, 1:20], catch.n(ple4)[,1:20]) bwplot(data~year|as.factor(age), flq) # ...now with same style modifications bwplot(data~year|as.factor(age), flq, scales=list(relation='free', x=list(at=seq(1, 20, by=5), labels=dimnames(catch.n(ple4)[,1:20])$year[seq(1, 20, by=5)])), cex=0.5, strip=strip.custom(strip.names=TRUE, strip.levels=TRUE, var.name='age'))
data(ple4) # xyplot on FLQuant xyplot(data~year|age, catch.n(ple4)[, 1:20]) xyplot(data~year|as.factor(age), catch.n(ple4)[, 1:20], type='b', pch=19, cex=0.5) # bwplot on FLQuant with iter... flq <- rnorm(100, catch.n(ple4)[, 1:20], catch.n(ple4)[,1:20]) bwplot(data~year|as.factor(age), flq) # ...now with same style modifications bwplot(data~year|as.factor(age), flq, scales=list(relation='free', x=list(at=seq(1, 20, by=5), labels=dimnames(catch.n(ple4)[,1:20])$year[seq(1, 20, by=5)])), cex=0.5, strip=strip.custom(strip.names=TRUE, strip.levels=TRUE, var.name='age'))
Franses, PH. "A note on the Mean Absolute Scaled Error". International Journal of Forecasting. 32 (1): 20–22. doi:10.1016/j.ijforecast.2015.03.008.
mase(ref, preds, ...) ## S4 method for signature 'FLQuant,FLQuants' mase(ref, preds, order = c("inverse", "ahead")) ## S4 method for signature 'FLIndices,list' mase(ref, preds, order = "inverse", wt = "missing")
mase(ref, preds, ...) ## S4 method for signature 'FLQuant,FLQuants' mase(ref, preds, order = c("inverse", "ahead")) ## S4 method for signature 'FLIndices,list' mase(ref, preds, order = "inverse", wt = "missing")
ref |
Reference or naive prediction. |
preds |
Predicitions to compare to reference. |
... |
Extra arguments. |
order |
Are predictions in 'inverse' (default) or 'ahead' order. |
wt |
Mean weights-at-age to use with indices. |
A numeric vector of the same length as 'preds'.
Equivalent to the mean fishing mortality metric returned by 'fbar', 'mbar' calculates the mean natural mortality across the ages inside the range defined by 'minfbar' and 'maxfbar'.
mbar(object, ...)
mbar(object, ...)
object |
An object of class 'FLStock'. |
An object of class 'FLQuant'.
The FLR Team, proposal by H. Winker.
fbar
data(ple4) mbar(ple4)
data(ple4) mbar(ple4)
Average age in the stock numbers or catch-at-age.
meanage(object) meanageCatch(object)
meanage(object) meanageCatch(object)
object |
An age-structured FLStock object |
An FLQuant object
The FLR Team
data(ple4) meanage(ple4) meanageCatch(ple4)
data(ple4) meanage(ple4) meanageCatch(ple4)
Average weight in the stock numbers or catch-at-age.
meanwt(object) meanwtCatch(object)
meanwt(object) meanwtCatch(object)
object |
An age-structured FLStock object |
An FLQuant object
The FLR Team
data(ple4) meanwt(ple4) meanwtCatch(ple4)
data(ple4) meanwt(ple4) meanwtCatch(ple4)
Time series summaries of complex objects are commonly needed, for example for
plotting the inputs and outputs of a class like FLStock
. These
methods allow for simple specification of those metrics by means of function
calls and formulas.
metrics(object, metrics, ...) ## S4 method for signature 'FLComp,list' metrics(object, metrics, ...) ## S4 method for signature 'FLS,missing' metrics(object, metrics, ...)
metrics(object, metrics, ...) ## S4 method for signature 'FLComp,list' metrics(object, metrics, ...) ## S4 method for signature 'FLS,missing' metrics(object, metrics, ...)
object |
A complex FLR object from which to extract time series metrics. |
An object, generally of class FLQuants
.
The FLR Team
data(ple4) # missing metrics(ple4) # metrics = function metrics(ple4, metrics=function(x) FLQuants(SSB=ssb(x), REC=rec(x), F=fbar(x), SSBREC=ssb(x) / rec(x))) # metrics = formula metrics(ple4, metrics=~ssb) metrics(ple4, metrics=list(SSB=~ssb)) metrics(ple4, metrics=list(SBMSY=~ssb/SBMSY), FLPar(SBMSY=3.87e4)) # metrics = list metrics(ple4, metrics=list(SSB=ssb, REC=rec, F=fbar)) metrics(ple4, metrics=list(SSB=~ssb, REC=rec, F=fbar))
data(ple4) # missing metrics(ple4) # metrics = function metrics(ple4, metrics=function(x) FLQuants(SSB=ssb(x), REC=rec(x), F=fbar(x), SSBREC=ssb(x) / rec(x))) # metrics = formula metrics(ple4, metrics=~ssb) metrics(ple4, metrics=list(SSB=~ssb)) metrics(ple4, metrics=list(SBMSY=~ssb/SBMSY), FLPar(SBMSY=3.87e4)) # metrics = list metrics(ple4, metrics=list(SSB=ssb, REC=rec, F=fbar)) metrics(ple4, metrics=list(SSB=~ssb, REC=rec, F=fbar))
A common measure of the strength of stock assessment retrospective patterns is Mohn's rho. This function does not carry out the calculation but returns a matrix with the metrics value for the n restrospective runs, in columns, and n + 2 years, in rows.
mohnMatrix(stocks, metric = "fbar", ...)
mohnMatrix(stocks, metric = "fbar", ...)
stocks |
An FLStocks object from a restrospective analysis |
metric |
Metric to be computed, as a character vector or function |
A metrics of n + 2 x n, where n is the numbers of objects in stocks.
Reference points based on equilibirum calculations of Maximum Sustainable Yield (MSY) are computed by various FLR packages. The methods' generics are defined here for convenience. Please refer to the help pages of particular methods for further details
msy(x, ...) bmsy(x, ...) sbmsy(x, ...) fmsy(x, ...)
msy(x, ...) bmsy(x, ...) sbmsy(x, ...) fmsy(x, ...)
x |
An input object from which to extract or compute a reference point |
The four methods provide the following parameter estimates:
msy
Maximum Sustainable Yield (MSY)
fmsy
Fishing mortality level expected to produce on average MSY
bmsy
Total biomass that should produce MSY
sbmsy
Spawning biomass that should produce MSY
A value for the requested reference point, 'FLPar'
The FLR Team
The names
method returns the names of the dimnames of an object. For
some classes, the names attribute can be modified directly using names<-.
## S4 method for signature 'FLArray' names(x) ## S4 method for signature 'FLPar' names(x) ## S4 replacement method for signature 'FLPar,character' names(x) <- value
## S4 method for signature 'FLArray' names(x) ## S4 method for signature 'FLPar' names(x) ## S4 replacement method for signature 'FLPar,character' names(x) <- value
names(x) names<-(x, value)
The FLR Team
# FLQuant data(ple4) names(catch.n(ple4)) # Contrast this with dimnames(catch.n(ple4))
# FLQuant data(ple4) names(catch.n(ple4)) # Contrast this with dimnames(catch.n(ple4))
Standard plot methods for every FLCore class. FLR plot methods are based on
lattice
, and attempt to show a general view of the
object contents.
## S4 method for signature 'FLQuant,missing' plot( x, xlab = "year", ylab = paste("data (", units(x), ")", sep = ""), type = "p", ... ) ## S4 method for signature 'FLStock,missing' plot(x, auto.key = TRUE, ...) ## S4 method for signature 'FLBiol,missing' plot(x, y, ...) ## S4 method for signature 'FLIndex,missing' plot(x, type = c("splom"), ...) ## S4 method for signature 'FLSR,missing' plot(x, main = "Functional form", log.resid = FALSE, cex = 0.8) ## S4 method for signature 'FLPar,missing' plot(x, y = "missing", ...)
## S4 method for signature 'FLQuant,missing' plot( x, xlab = "year", ylab = paste("data (", units(x), ")", sep = ""), type = "p", ... ) ## S4 method for signature 'FLStock,missing' plot(x, auto.key = TRUE, ...) ## S4 method for signature 'FLBiol,missing' plot(x, y, ...) ## S4 method for signature 'FLIndex,missing' plot(x, type = c("splom"), ...) ## S4 method for signature 'FLSR,missing' plot(x, main = "Functional form", log.resid = FALSE, cex = 0.8) ## S4 method for signature 'FLPar,missing' plot(x, y = "missing", ...)
Users are encouraged to write their own plotting code and make use of the
overloaded lattice
methods, for example
xyplot
or bwplot
. See also
lattice-FLCore
.
plot(x,y)
The FLR Team
data(ple4) # FLQuant plot(catch.n(ple4)[, 1:20]) plot(catch.n(ple4)[, 1:20], type='b', pch=19, cex=0.5) # FLStock data(ple4sex) plot(ple4) plot(ple4sex) # FLBiol data(ple4.biol) plot(ple4.biol) # FLIndex data(ple4.index) plot(ple4.index) # FLSR data(nsher) plot(nsher) # FLPar fpa <- FLPar(a=rnorm(100, 1, 20), b=rlnorm(100, 0.5, 0.2)) plot(fpa)
data(ple4) # FLQuant plot(catch.n(ple4)[, 1:20]) plot(catch.n(ple4)[, 1:20], type='b', pch=19, cex=0.5) # FLStock data(ple4sex) plot(ple4) plot(ple4sex) # FLBiol data(ple4.biol) plot(ple4.biol) # FLIndex data(ple4.index) plot(ple4.index) # FLSR data(nsher) plot(nsher) # FLPar fpa <- FLPar(a=rnorm(100, 1, 20), b=rlnorm(100, 0.5, 0.2)) plot(fpa)
Object of the predictModel class are used in various FLR classes to allow flexible modelling of the dynamics of different biological and technological processes.
## S4 method for signature 'FLQuants,formula' predictModel(object, model, params = FLPar()) ## S4 method for signature 'FLQuants,missing' predictModel(object, params = FLPar()) ## S4 method for signature 'FLQuants,character' predictModel(object, model, params = FLPar()) ## S4 method for signature 'FLQuants,function' predictModel(object, model, params = FLPar()) ## S4 method for signature 'FLQuants,list' predictModel(object, model, params = FLPar()) ## S4 method for signature 'missing,ANY' predictModel(object, model, ...)
## S4 method for signature 'FLQuants,formula' predictModel(object, model, params = FLPar()) ## S4 method for signature 'FLQuants,missing' predictModel(object, params = FLPar()) ## S4 method for signature 'FLQuants,character' predictModel(object, model, params = FLPar()) ## S4 method for signature 'FLQuants,function' predictModel(object, model, params = FLPar()) ## S4 method for signature 'FLQuants,list' predictModel(object, model, params = FLPar()) ## S4 method for signature 'missing,ANY' predictModel(object, model, ...)
The dependency of life history processes, such as maturity and fecundity, to biological
and environmental factors, can be represented in objects of this class via a simple model
(represented by a formula
) and the corresponding paramaters (FLPar
) and inputs
(FLQuants
).
Inputs to the model not found in enclosing class (FLQuants
).
Model representation (formula
).
Model paramaters (FLPar
).
Neque porro quisquam est qui dolorem ipsum.
You can inspect the class validity function by using
getValidity(getClassDef('predictModel'))
All slots in the class have accessor and replacement methods defined that allow retrieving and substituting individual slots.
The values passed for replacement need to be of the class of that slot. A numeric vector can also be used when replacing FLQuant slots, and the vector will be used to substitute the values in the slot, but not its other attributes.
A construction method exists for this class that can take named arguments for any of its slots. All slots are then created to match the requirements of the class validity.
Methods exist for various calculations based on values stored in the class:
Neque porro quisquam est qui dolorem ipsum.
The FLR Team
fec <- FLQuants(fec=FLQuant(rlnorm(10, 20, 5), dimnames=list(year=2000:2009), units='1')) predictModel(fec, model=~fec) predictModel(fec) predictModel(fec, model="bevholt") predictModel(fec, model=bevholt) predictModel(fec, model=bevholt()) predictModel(model=rec~a*ssb, params=FLPar(a=1.234)) predictModel(model=bevholt, params=FLPar(a=1.234)) predictModel(model="bevholtss3", params=FLPar(a=1.234))
fec <- FLQuants(fec=FLQuant(rlnorm(10, 20, 5), dimnames=list(year=2000:2009), units='1')) predictModel(fec, model=~fec) predictModel(fec) predictModel(fec, model="bevholt") predictModel(fec, model=bevholt) predictModel(fec, model=bevholt()) predictModel(model=rec~a*ssb, params=FLPar(a=1.234)) predictModel(model=bevholt, params=FLPar(a=1.234)) predictModel(model="bevholtss3", params=FLPar(a=1.234))
Returns the computed yearly production
production(object, ...) ## S4 method for signature 'FLStock' production(object, what = "ssb", ...)
production(object, ...) ## S4 method for signature 'FLStock' production(object, what = "ssb", ...)
object |
An object with biomass and catch data. |
what |
One of the production options: "ssb", "biomass", or "exploitation". |
Production can be calculated for an FLStock based on the spawning stock biomass ("ssb"), total biomass ("biomass"), or exploitation ("exploitation").
The production by year, of class FLQuant.
Laurie Kell (Sea++), Iago Mosqueira (WMR)
data(ple4) # For SSB production(ple4, "ssb") # For total biomass production(ple4, "biomass")
data(ple4) # For SSB production(ple4, "ssb") # For total biomass production(ple4, "biomass")
Methods to extend objects of various FLR classes along the iter
(6th FLQuant) dimension. Objects must generally have a single
iter
to be extended. The new iterations can be filled with copies
of the existing, or remain as NA
.
propagate(object, ...) ## S4 method for signature 'FLQuant' propagate(object, iter, fill.iter = TRUE)
propagate(object, ...) ## S4 method for signature 'FLQuant' propagate(object, iter, fill.iter = TRUE)
object |
Object to be propagated. |
fill.iter |
Should first array be copied to others? Defaults to FALSE. |
iters |
No. of iterations in output. |
propagate(object, ...)
The FLR Team
# An FLQuant with one iter (dim(flq)[6] == 1) flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age') # can now be extended along the `iter` dimension, with #' copies of the first propagate(flq, 100) # or without iter(propagate(flq, 100, fill.iter=FALSE), 2)
# An FLQuant with one iter (dim(flq)[6] == 1) flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age') # can now be extended along the `iter` dimension, with #' copies of the first propagate(flq, 100) # or without iter(propagate(flq, 100, fill.iter=FALSE), 2)
Returns a series of properties of the fisheries element represented by the class.
properties(object, ...)
properties(object, ...)
object |
An object from which properties can be extracted. |
The correspodning properties, an FLPar.
Laurie Kell (Sea++), Iago Mosqueira (WMR)
Function to get or set the name of the first dimension (quant) in an object
of any FLArray-based class, like FLQuant
or FLCohort
.
quant(object, ...) ## S4 method for signature 'FLArray' quant(object) ## S4 replacement method for signature 'FLArray,character' quant(object) <- value
quant(object, ...) ## S4 method for signature 'FLArray' quant(object) ## S4 replacement method for signature 'FLArray,character' quant(object) <- value
quant(object) quant<-(object,value)
The FLR Team
# quant is 'quant' by default quant(FLQuant()) flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age') quant(flq) quant(flq) <- 'length' summary(flq) # quant is 'quant' by default quant(FLQuant()) flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age') quant(flq) quant(flq) <- 'length' summary(flq)
# quant is 'quant' by default quant(FLQuant()) flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age') quant(flq) quant(flq) <- 'length' summary(flq) # quant is 'quant' by default quant(FLQuant()) flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age') quant(flq) quant(flq) <- 'length' summary(flq)
Methods to compute totals over selected dimensions of FLQuant
objects
These methods return an object of same dimensions as the input but with the
sums along the first (yearTotals
) or second dimension
(quantTotals
). Although the names might appear contradictory, it must
be noted that what each method really returns are the totals over the
selected dimension.
quantTotals(x, ...)
quantTotals(x, ...)
quantTotals(x)
yearTotals(x)
The FLR Team
flq <- FLQuant(rlnorm(100), dim=c(10,10)) quantTotals(flq) # See how the values obtained by yearSums are being replicated yearSums(flq) # Get the proportions by quant flq / quantTotals(flq) # or year flq / yearTotals(flq)
flq <- FLQuant(rlnorm(100), dim=c(10,10)) quantTotals(flq) # See how the values obtained by yearSums are being replicated yearSums(flq) # Get the proportions by quant flq / quantTotals(flq) # or year flq / yearTotals(flq)
Reads a single file with one year of data in VPA format as output by ICES Intercatch
readVPAIntercatch(file)
readVPAIntercatch(file)
file |
Intercatch VPA file to load |
An object of class FLQuant.
residuals
## S4 method for signature 'FLQuant' residuals(object, fit, type = "log", ...)
## S4 method for signature 'FLQuant' residuals(object, fit, type = "log", ...)
data(ple4) fit <- rlnorm(1, log(catch(ple4)), 0.1) residuals(catch(ple4), fit) residuals(catch(ple4), fit, type="student") rraw(catch(ple4), fit) rlogstandard(catch(ple4), fit) rstandard(catch(ple4), fit) rstudent(catch(ple4), fit)
data(ple4) fit <- rlnorm(1, log(catch(ple4)), 0.1) residuals(catch(ple4), fit) residuals(catch(ple4), fit, type="student") rraw(catch(ple4), fit) rlogstandard(catch(ple4), fit) rstandard(catch(ple4), fit) rstudent(catch(ple4), fit)
A noise generator
## S4 method for signature 'numeric,FLQuant' rnoise( n = n, len = len, sd = 1, b = 0, burn = 0, trunc = 0, what = c("year", "cohort", "age"), seed = NA ) ## S4 method for signature 'numeric,missing' rnoise(n = n, sd = 1, b = 0, burn = 0, trunc = 0, seed = NA) ## S4 method for signature 'numeric,FLQuant' rlnoise( n = n, len = len, sd = 1, b = 0, burn = 0, trunc = 0, what = c("year", "cohort", "age"), seed = NA )
## S4 method for signature 'numeric,FLQuant' rnoise( n = n, len = len, sd = 1, b = 0, burn = 0, trunc = 0, what = c("year", "cohort", "age"), seed = NA ) ## S4 method for signature 'numeric,missing' rnoise(n = n, sd = 1, b = 0, burn = 0, trunc = 0, seed = NA) ## S4 method for signature 'numeric,FLQuant' rlnoise( n = n, len = len, sd = 1, b = 0, burn = 0, trunc = 0, what = c("year", "cohort", "age"), seed = NA )
n |
number of iterations |
len |
an |
sd |
standard error for simulated series |
b |
autocorrelation parameter a real number in 0,1 |
burn |
gets rid of 1st values i series |
trunc |
get rid of values > abs(trunc) |
what |
returns time series for year, cohort or age" |
... |
any |
A FLQuant
with autocorrelation equal to B.
Ranta and Kaitala 2001 Proc. R. Soc. vt = b * vt-1 + s * sqrt(1 - b^2) s is a normally distributed random variable with mean = 0 b is the autocorrelation parameter
## Not run: flq <- FLQuant(1:100, quant="age") white <- rnoise(100,flq,sd=.3,b=0) plot(white) acf(white) red <- rnoise(100,flq,sd=.3,b=0.7) plot(red) acf(red) res <- rnoise(100,flq,sd=.3,b=0) ggplot() + geom_point(aes(year,age,size=data), data=subset(as.data.frame(res), data>0)) + geom_point(aes(year,age,size=-data), data=subset(as.data.frame(res),data<=0),colour="red")+ scale_size_area(max_size=4, guide="none")+ facet_wrap(~iter) data(ple4) res <- rnoise(4,m(ple4),burn=10,b=0.9,what="cohort") ggplot()+ geom_point(aes(year,age,size= data), data=subset(as.data.frame(res),data>0))+ geom_point(aes(year,age,size=-data), data=subset(as.data.frame(res),data<=0),colour="red")+ scale_size_area(max_size=4, guide="none")+ facet_wrap(~iter) ## End(Not run)
## Not run: flq <- FLQuant(1:100, quant="age") white <- rnoise(100,flq,sd=.3,b=0) plot(white) acf(white) red <- rnoise(100,flq,sd=.3,b=0.7) plot(red) acf(red) res <- rnoise(100,flq,sd=.3,b=0) ggplot() + geom_point(aes(year,age,size=data), data=subset(as.data.frame(res), data>0)) + geom_point(aes(year,age,size=-data), data=subset(as.data.frame(res),data<=0),colour="red")+ scale_size_area(max_size=4, guide="none")+ facet_wrap(~iter) data(ple4) res <- rnoise(4,m(ple4),burn=10,b=0.9,what="cohort") ggplot()+ geom_point(aes(year,age,size= data), data=subset(as.data.frame(res),data>0))+ geom_point(aes(year,age,size=-data), data=subset(as.data.frame(res),data<=0),colour="red")+ scale_size_area(max_size=4, guide="none")+ facet_wrap(~iter) ## End(Not run)
A receiver operating characteristic (ROC) curve shows the ability of a binary classifier. Here it is applied to compare two sets of values, stored as two FLQuant objects. The first is the result of aplying a logical comparison of a given state against a reference value, so it contains a binary (0, 1) label. The second, the score, contains an alternative metric that attempts to measure the absolute value of the first. The examples below compare an observation of stock status, SSB being less than a reference point, and an alternative metric, here the catch curve estimates of total mortality.
roc(label, ind, direction = c(">=", "<=")) auc(x = NULL, TPR = x$TPR, FPR = x$FPR)
roc(label, ind, direction = c(">=", "<=")) auc(x = NULL, TPR = x$TPR, FPR = x$FPR)
data(ple4) # OM 'reality' on stock status (fbar) state <- fbar(ple4)[, ac(1960:2017)] # Model estimates of F using catch curves ind <- acc(catch.n(ple4)[, ac(1960:2017)]) # Compute TSS, returns data.frame roc(state >= 0.22, ind) # Needs ggplotFL ## Not run: ggplot(roc(state >= 0.22, ind, direction='>='), aes(x=FPR, y=TPR)) + geom_line() + geom_abline(slope=1, intercept=0, colour="red", linetype=2) ## End(Not run) # Computes auc using the output of roc() with(roc(state >= 0.22, ind), auc(TPR=TPR, FPR=FPR)) auc(roc(state >= 0.22, ind))
data(ple4) # OM 'reality' on stock status (fbar) state <- fbar(ple4)[, ac(1960:2017)] # Model estimates of F using catch curves ind <- acc(catch.n(ple4)[, ac(1960:2017)]) # Compute TSS, returns data.frame roc(state >= 0.22, ind) # Needs ggplotFL ## Not run: ggplot(roc(state >= 0.22, ind, direction='>='), aes(x=FPR, y=TPR)) + geom_line() + geom_abline(slope=1, intercept=0, colour="red", linetype=2) ## End(Not run) # Computes auc using the output of roc() with(roc(state >= 0.22, ind), auc(TPR=TPR, FPR=FPR)) auc(roc(state >= 0.22, ind))
Returns a set of standard rules to be used by the verify method for an object of a given class.
ruleset(object, ...) ## S4 method for signature 'FLStock' ruleset(object, ...)
ruleset(object, ...) ## S4 method for signature 'FLStock' ruleset(object, ...)
object |
An object of any FLR class for which the method has been defined. |
... |
Names of positions in the standard list to subset. |
A standard minimal set of rules to check FLStock objects against using the verify method. The included rules are (with names in italics) check that:
there are no NAs in any slot, anyna.
catch.wt, landings.wt, discards.wt and stock.wt > 0.
mat, m.spwn and harvest.spwn values are between 0 and 1.
harvest >= 0.
cohorts in the stock.n slot contain decreasing numbers, except for the plusgroup age.
A named list containing the rules defined for for the class object belongs to.
The FLR Team
data(ple4) ruleset(ple4) # Extract single rule by name ruleset(ple4, 'anyna')
data(ple4) ruleset(ple4) # Extract single rule by name ruleset(ple4, 'anyna')
Computes Runs Test p-values
runstest(fit, obs, ...) ## S4 method for signature 'FLQuants,missing' runstest(fit, combine = TRUE) ## S4 method for signature 'FLQuants,FLQuants' runstest(fit, obs, combine = TRUE) ## S4 method for signature 'FLQuant,FLQuant' runstest(fit, obs, combine = TRUE) ## S4 method for signature 'FLQuant,missing' runstest(fit, combine = TRUE) ## S4 method for signature 'numeric,numeric' runstest(fit, obs, combine = TRUE) ## S4 method for signature 'numeric,missing' runstest(fit, obs, combine = TRUE)
runstest(fit, obs, ...) ## S4 method for signature 'FLQuants,missing' runstest(fit, combine = TRUE) ## S4 method for signature 'FLQuants,FLQuants' runstest(fit, obs, combine = TRUE) ## S4 method for signature 'FLQuant,FLQuant' runstest(fit, obs, combine = TRUE) ## S4 method for signature 'FLQuant,missing' runstest(fit, combine = TRUE) ## S4 method for signature 'numeric,numeric' runstest(fit, obs, combine = TRUE) ## S4 method for signature 'numeric,missing' runstest(fit, obs, combine = TRUE)
fit |
The result of a model fit. |
obs |
The observations used in the fit. |
... |
Extra arguments. |
combine |
Should ages be combined by addition, defaults to TRUE. |
A list with elements 'p.values' and 'pass'.
data(nsher) # Compute 'runstest' for FLSR fit runstest(fit=fitted(nsher), obs=rec(nsher)) # Example runstest by age data(ple4) runstest(catch.n(ple4), landings.n(ple4), combine=FALSE) runstest(fit=FLQuants(D=residuals(catch(ple4), discards(ple4)), L=residuals(catch(ple4), landings(ple4)))) runstest(fit=residuals(fitted(nsher), rec(nsher))) runstest(FLQuants(residuals(fitted(nsher), rec(nsher)))) # Returns value per iter runstest(fit=rnorm(25, residuals(fitted(nsher), rec(nsher)), 0.2)) runstest(ssb(nsher)) runstest(rnorm(1, FLQuant(1, dimnames=list(year=1973:2021)))) runstest(rep(0.1, 10), cumsum(rnorm(10, 0.1, 0.01))) runstest(rnorm(10, 0, 0.1))
data(nsher) # Compute 'runstest' for FLSR fit runstest(fit=fitted(nsher), obs=rec(nsher)) # Example runstest by age data(ple4) runstest(catch.n(ple4), landings.n(ple4), combine=FALSE) runstest(fit=FLQuants(D=residuals(catch(ple4), discards(ple4)), L=residuals(catch(ple4), landings(ple4)))) runstest(fit=residuals(fitted(nsher), rec(nsher))) runstest(FLQuants(residuals(fitted(nsher), rec(nsher)))) # Returns value per iter runstest(fit=rnorm(25, residuals(fitted(nsher), rec(nsher)), 0.2)) runstest(ssb(nsher)) runstest(rnorm(1, FLQuant(1, dimnames=list(year=1973:2021)))) runstest(rep(0.1, 10), cumsum(rnorm(10, 0.1, 0.01))) runstest(rnorm(10, 0, 0.1))
The last year of an FLQuant
object is used as atrating point to generate
a time series following a random walk with drift:
where is
rwalk(x0, end = 1, sd = 0.05, delta = 0)
rwalk(x0, end = 1, sd = 0.05, delta = 0)
x0 |
The initial state of the random walk, 'FLQuant'. |
end |
The number of years or the final year of the series. numeric. |
sd |
The standard deviation of the random walk, numeric. |
delta |
The drift of the random walk. |
The length of the series is set by argument end. This is taken as a number of years, if its value is smaller than the final 'year' of 'x0', or as a final year if larger or of class 'character'.
An 'FLQuant' object.
Iago Mosqueira, WMR (2023)
data(ple4) # Generate random walk recruitmrnt with positive drift rwalk(rec(ple4), end=5, sd=0.08, delta=0.05) # Use append() to add the new values at the end append(rec(ple4), rwalk(rec(ple4), end=10, sd=0.04, delta=0)) # Use end as number of years rwalk(rec(ple4), end=5) # or as final year rwalk(rec(ple4), end=2020)
data(ple4) # Generate random walk recruitmrnt with positive drift rwalk(rec(ple4), end=5, sd=0.08, delta=0.05) # Use append() to add the new values at the end append(rec(ple4), rwalk(rec(ple4), end=10, sd=0.04, delta=0)) # Use end as number of years rwalk(rec(ple4), end=5) # or as final year rwalk(rec(ple4), end=2020)
Standard display of an object contents in an interactive session. Objects of
class FLQuant
with length > 1 along the sixth dimension
(iter) are output in a summarised form, as median(mad)
, where
mad is the median absolute deviation. See mad
.
## S4 method for signature 'FLArray' show(object)
## S4 method for signature 'FLArray' show(object)
The same format is used for objects of class FLPar
with
length > 1 on the last dimension (iter).
show(object)
The FLR Team
# no 'iter' flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age', units='kg') flq # with 'iter' flq <- FLQuant(rnorm(800), dim=c(4,20,1,1,1,10), quant='age', units='kg') flq
# no 'iter' flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age', units='kg') flq # with 'iter' flq <- FLQuant(rnorm(800), dim=c(4,20,1,1,1,10), quant='age', units='kg') flq
Objects of many FLR classes might be aggregated along the "unit", "season", and/or "area" dimensions according to the type of data they contain.
simplify(object, ...) ## S4 method for signature 'FLStock' simplify( object, dims = c("unit", "season", "area")[dim(object)[3:5] > 1], spwn.season = 1, rec.season = spwn.season, harvest = TRUE, weighted = FALSE )
simplify(object, ...) ## S4 method for signature 'FLStock' simplify( object, dims = c("unit", "season", "area")[dim(object)[3:5] > 1], spwn.season = 1, rec.season = spwn.season, harvest = TRUE, weighted = FALSE )
object |
A complex FLR object to aggregate. |
An object of the same class as the input.
The FLR Team
Objects of FLR classes can vary in the length along the sixth dimension
in any slot of class FLQuant. This reduces object size and memory
usage. If an object has been extended fully, for example by using
propagate
, we can slim down the object by reducing
any slot where all iters are identical and keeping only yhe first iter.
slim(object, ...) ## S4 method for signature 'FLComp' slim(object, ...)
slim(object, ...) ## S4 method for signature 'FLComp' slim(object, ...)
object |
A complex FLR object to slim down. |
The test for whether an slot can be slimmed is based on checking if the sum of the variance along the 6th dimensions is equal to zero.
An object of the same class as the input.
The FLR Team
data(ple4) # Extend all of ple4 to 50 iters ple4 <- propagate(ple4, 50) # Add variability in catch.n catch.n(ple4) <- rlnoise(50, log(catch.n(ple4)), log(catch.n(ple4))/10) summary(ple4) # slim object by dropping identical iters sple4 <- slim(ple4) summary(sple4)
data(ple4) # Extend all of ple4 to 50 iters ple4 <- propagate(ple4, 50) # Add variability in catch.n catch.n(ple4) <- rlnoise(50, log(catch.n(ple4)), log(catch.n(ple4))/10) summary(ple4) # slim object by dropping identical iters sple4 <- slim(ple4) summary(sple4)
Similar to base::split, but working along the 6th, iter, dimension of any singular FLR object. The object is divided into as many objects as unique values in f, and returned as an FLlst-derived object, e.g. an FLQuants object when applied to an FLQuant.
## S4 method for signature 'FLQuant,vector' split(x, f) ## S4 method for signature 'FLComp,vector' split(x, f)
## S4 method for signature 'FLQuant,vector' split(x, f) ## S4 method for signature 'FLComp,vector' split(x, f)
x |
The object to be split. |
f |
The vector of group names. |
An object of the corresponding plural class (FLQuants from FLQuant).
Iago Mosqueira (WMR).
# FROM FLQuant to FLQuants flq <- rlnorm(20, FLQuant(seq(0.1, 0.8, length=10)), 0.2) split(flq, c(rep(1, 5), rep(2,15)))
# FROM FLQuant to FLQuants flq <- rlnorm(20, FLQuant(seq(0.1, 0.8, length=10)), 0.2) split(flq, c(rep(1, 5), rep(2,15)))
Draws a conditional scatter plot matrix.
## S4 method for signature 'FLPar,missing' splom(x, data, ...)
## S4 method for signature 'FLPar,missing' splom(x, data, ...)
See the help page in lattice
for a full description
of each plot and all possible arguments.
splom(x,data)
The FLR Team
flp <- FLPar(c(t(mvrnorm(500, mu=c(0, 120, 0.01, 20), Sigma=matrix(.7, nrow=4, ncol=4) + diag(4) * 0.3))), dimnames=list(params=c('a','b','c','d'), iter=1:500), units="NA") splom(flp)
flp <- FLPar(c(t(mvrnorm(500, mu=c(0, 120, 0.01, 20), Sigma=matrix(.7, nrow=4, ncol=4) + diag(4) * 0.3))), dimnames=list(params=c('a','b','c','d'), iter=1:500), units="NA") splom(flp)
Inside a function, a call to spread() will attach to the function environment, sys.frame(), the elements in the list, or of the conversion to list of the object (e.g. named vector or FLPar), so that they be called by name. The function environment will be deleted once the function returns, so those variables won't make it to the environment from which the function was called, or further up in the call stack.
spread(object, FORCE = FALSE)
spread(object, FORCE = FALSE)
object |
A named list or vector whose elements are to be loaded into the calling environment. |
FORCE |
Should existing variable with matching names be redefined? |
By default, spread() will not overwrite variables in the function environment with the same name as any list element, unless FORCE=TRUE
Invisibly the names of the variables loaded into the calling environment.
The FLR Team
# EXAMPLE function foo <- function (params) { a <- spread(params) print(a) x*y } # x and y are accesible to the internal calculation foo(params=list(x=3.5, y=9)) # Works with FLPar foo(params=FLPar(x=3L, y=0.99238)) # Elements in object must be named ## Not run: foo(list(3, y=0.99238)) # If a variable is missing from the spread object, function will fail ## Not run: foo(list(x=4)) # Unless the variable is already defined in the calling environment, # in this case <environment: R_GlobalEnv> y <- 45 foo(params=list(x=4))
# EXAMPLE function foo <- function (params) { a <- spread(params) print(a) x*y } # x and y are accesible to the internal calculation foo(params=list(x=3.5, y=9)) # Works with FLPar foo(params=FLPar(x=3L, y=0.99238)) # Elements in object must be named ## Not run: foo(list(3, y=0.99238)) # If a variable is missing from the spread object, function will fail ## Not run: foo(list(x=4)) # Unless the variable is already defined in the calling environment, # in this case <environment: R_GlobalEnv> y <- 45 foo(params=list(x=4))
A range of stock-recruitment (SR) models commonly used in fisheries science are provided in FLCore.
ricker() bevholt() bevholtDa() bevholtss3() segreg() geomean() shepherd() cushing() rickerSV() bevholtSV() shepherdSV() bevholtAR1() rickerAR1() segregAR1() rickerCa() survRec(ssf, R0, Sfrac, beta, SF0 = ssf[, 1]) bevholtsig() mixedsrr()
ricker() bevholt() bevholtDa() bevholtss3() segreg() geomean() shepherd() cushing() rickerSV() bevholtSV() shepherdSV() bevholtAR1() rickerAR1() segregAR1() rickerCa() survRec(ssf, R0, Sfrac, beta, SF0 = ssf[, 1]) bevholtsig() mixedsrr()
rho |
Autoregression |
sigma2 |
Autoregression |
obs |
Observed values |
hat |
estimated values |
steepness |
Steepness. |
vbiomass |
Virgin biomass. |
spr0 |
Spawners per recruit at F=0, see |
model |
character vector with model name, either 'bevholt' or 'ricker'. |
Each method is defined as a function returning a list with one or more elements as follows:
model: Formula for the model, using the slot names rec and ssb to refer to the usual inputs
logl: Function to calculate the loglikelihood of the given model when
estimated through MLE (See fmle
)
initial: Function to provide initial values for all parameters to the
minimization algorithms called by fmle
or
nls
. If required, this function also has two attributes,
lower
and upper
, that give lower and upper limits
for the parameter values, respectively. This is used by some of the methods
defined in optim
, like "L-BFGS-B"
.
The model<- method for FLModel
can then be called
with value being a list as described above, the name of the function
returning such a list, or the function itself. See the examples below.
Several functions to fit commonly-used SR models are available. They all use
maximum likelihood to estimate the parameters through the method
loglAR1
.
ricker: Ricker stock-recruitment model fit:
a is related to productivity (recruits per stock unit at small stock size) and b to density dependence. (a, b > 0).
bevholt: Beverton-Holt stock-recruitment model fit:
a is the
maximum recruitment (asymptotically) and b is the stock level needed
to produce the half of maximum recruitment .
(a, b > 0).
segreg: Segmented regression stock-recruitment model fit:
a is the slope of the recruitment for stock levels below b, and
is the mean recruitment for stock levels above b.
(a, b > 0).
geomean: Constant recruitment model fit, equal to the historical geometric mean recruitment.
shepherd: Shepherd stock-recruitment model fit:
a represents density-independent survival (similar to a in the Ricker stock-recruit model), b the stock size above which density-dependent processes predominate over density-independent ones (also referred to as the threshold stock size), and c the degree of compensation.
cushing: Cushing stock-recruitment model fit:
This model has been used less often, and is limited by the fact that it is unbounded for b>=1 as S increases. (a, b > 0).
Stock recruitment models parameterized for steepness and virgin biomass:
rickerSV: Fits a ricker stock-recruitment model parameterized for steepness and virgin biomass.
bevholtSV: Fits a Beverton-Holt stock-recruitment model parameterised for steepness and virgin biomass.
sheperdSV: Fits a shepher stock-recruitment model parameterized for steepness and virgin biomass.
Models fitted using autoregressive residuals of first order:
bevholtAR1, rickerAR1, segregAR1: Beverton-Holt, Ricker and segmented
regression stock-recruitment models with autoregressive normal log residuals
of first order. In the model fit, the corresponding stock-recruit
model is combined with an autoregressive normal log likelihood of first order
for the residuals. If is the observed recruitment and
is the predicted recruitment, an autoregressive model
of first order is fitted to the log-residuals,
.
where follows a normal distribution with mean 0:
.
Ricker model with one covariate. The covariate can be used, for example, to account for an enviromental factor that influences the recruitment dynamics. In the equations, c is the shape parameter and X is the covariate.
rickerCa: Ricker stock-recruitment model with one multiplicative covariate.
The FLR Team
Beverton, R.J.H. and Holt, S.J. (1957) On the dynamics of exploited fish populations. MAFF Fish. Invest., Ser: II 19, 533.
Needle, C.L. Recruitment models: diagnosis and prognosis. Reviews in Fish Biology and Fisheries 11: 95-111, 2002.
Ricker, W.E. (1954) Stock and recruitment. J. Fish. Res. Bd Can. 11, 559-623.
Shepherd, J.G. (1982) A versatile new stock-recruitment relationship for fisheries and the construction of sustainable yield curves. J. Cons. Int. Explor. Mer 40, 67-75.
# inspect the output of one of the model functions bevholt() names(bevholt()) bevholt()$logl # once an FLSR model is in the workspace ... data(nsher) # the three model-definition slots can be modified # at once by calling 'model<-' with # (1) a list model(nsher) <- bevholt() # (2) the name of the function returning this list model(nsher) <- 'bevholt' # or (3) the function itself that returns this list model(nsher) <- bevholt
# inspect the output of one of the model functions bevholt() names(bevholt()) bevholt()$logl # once an FLSR model is in the workspace ... data(nsher) # the three model-definition slots can be modified # at once by calling 'model<-' with # (1) a list model(nsher) <- bevholt() # (2) the name of the function returning this list model(nsher) <- 'bevholt' # or (3) the function itself that returns this list model(nsher) <- bevholt
The calculated Spawning Stock Biomass (SSB) of a fish population is returned
by this method. SSB is the combined weight of all individuals in a fish stock
that are capable of reproducing. In some classes this is calculated from
information stored in different slots, while in others ssb()
is simply
an slot accessor. When the later is the case, the corresponding replacement
method also exists.
For an object of class FLStock
, the calculation of SSB depends
on the value of the 'units' attribute in the harvest
slot. If this is
in terms of fishing mortality (units(harvest(object)) == 'f'
), and
assuming an object structured by age, then SSB is calculated as
where is the abundance in numbers (
stock.n
) by
age (a) and year (y), is the fishing mortality (
harvest
),
is the proportion of fishing mortality before spawning
(
harvest.spwn
),
is the natural mortality (
m
),
is the proportion of natural mortality before spawning
(
m.spwn
),
is the mean weight at age in the stock (
m
), and
is the proportion mature at age in the stock (
mat
).
For FLStock
objects with other dimensions (area
,
unit
), the calculation is carried out along those dimensions too. To
obtain a global value please use the corresponding summing method.
If the harvest slot contains estimates in terms of harvest rates
(units(harvest(object)) == "hr"
), SSB will be computed as
where is the harvest rate (proportion of catch in weight
over total biomass).
ssb(object, ...) ## S4 method for signature 'FLStock' ssb(object, ...) ## S4 method for signature 'FLBiol' ssb(object, ...)
ssb(object, ...) ## S4 method for signature 'FLStock' ssb(object, ...) ## S4 method for signature 'FLBiol' ssb(object, ...)
object |
Object on which |
Objects of the FLBiol class do not contain any information on
catch or fishing mortality, so a call to ssb()
will only correct abundances
for natural mortality to the moment of spawning. The method can also take
information on catches or fishing mortality and use them when calculating
abundances at spawning time. An FLQuant named either 'catch.n', 'f', 'hr' or
'harvest' can be used. The first three are self-explanatory, while for the last
units must be either 'f' or 'hr'. The quantities should refer to total yearly
values, as the value in the 'spwn' slot will be used to calculate what fraction
of fishing mortality to apply.
An object, generally of class FLQuant
.
The FLR Team
data(ple4) # SSB from FLStock ssb(ple4) biol <- as(ple4, "FLBiol") # SSB from FLBiol, abundances corrected only for M ssb(biol) # Provide catch-at-age, F or HR to correct N ssb(biol, catch.n=catch.n(ple4)) ssb(biol, f=harvest(ple4)) ssb(biol, harvest=harvest(ple4)) ssb(biol, hr=catch.n(ple4) / stock.n(ple4))
data(ple4) # SSB from FLStock ssb(ple4) biol <- as(ple4, "FLBiol") # SSB from FLBiol, abundances corrected only for M ssb(biol) # Provide catch-at-age, F or HR to correct N ssb(biol, catch.n=catch.n(ple4)) ssb(biol, f=harvest(ple4)) ssb(biol, harvest=harvest(ple4)) ssb(biol, hr=catch.n(ple4) / stock.n(ple4))
The spawning stock biomass (SSB) of the stock gets calculated from the survivors of the previous year. This provides a value for the first year after the end of the object. Weights-at-age, maturity in this extra year are calculated as averages over the last wts.nyears.
ssb_next(x, fbar = 0, wts.nyears = 3, fbar.nyears = 3)
ssb_next(x, fbar = 0, wts.nyears = 3, fbar.nyears = 3)
x |
An FLStock object containing estimates of abundance and harvesting. |
fbar |
The Fbar rate assumed on the extra year. Defaults to 0. |
wts.nyears |
Number of years in calculation of mean weight-at-age and maturity for the extra year. |
fbar.nyears |
Number of years in calculation of mean selectivity, natural mortality and fraction of F abnd M before spawning for the extra year. |
For stocks spawning later in the year, a value for the average fishing mortality, fbar, expected in that year can be provided. Mortality until spawning is then calculated, with M and selectivity assumed in the extra year to be an average of the last fbar.nyears.
An FLQuant.
data(ple4) ssb_next(ple4) # Compare with ssb() ssb(ple4)[, ac(2014:2017)] / ssb_next(ple4)[, ac(2014:2017)]
data(ple4) ssb_next(ple4) # Compare with ssb() ssb(ple4)[, ac(2014:2017)] / ssb_next(ple4)[, ac(2014:2017)]
Returns values for the units of each FLQuant slot according to the standard adopted by the FLR Team for the supplied class.
standardUnits(object, ...) ## S4 method for signature 'character' standardUnits(object, ...) ## S4 method for signature 'FLS' standardUnits(object, ...) ## S4 method for signature 'FLBiol' standardUnits(object, ...)
standardUnits(object, ...) ## S4 method for signature 'character' standardUnits(object, ...) ## S4 method for signature 'FLS' standardUnits(object, ...) ## S4 method for signature 'FLBiol' standardUnits(object, ...)
object |
for which the standard units are to be returned |
For objects derived from class FLS, which currently includes FLStock and FLStockLen, the adopted standard includes: 'kg' for individual weights, '1000' for number of individuals, 't' for biomass, 'f' for harvest, 'm' for natural mortality, and an empty string for proportions (spwn, mat).
For objects derived of class FLBiol the adopted standard units are: 'kg' for individual weights, '1000' for number of individuals, 'm' for natural mortality, and an empty string for proportions (spwn, mat).
A list with the corresponding units value for each slot
The FLR Team
stk <- FLStock(catch=FLQuant(runif(20, 2, 120))) # FLStock object has no units summary(stk) # Obtain standard units for the class as a list standardUnits(stk) # which can then be assigned to the object units(stk) <- standardUnits(stk) summary(stk) # units<- methjod also accepts a function to be called to provide units units(stk) <- standardUnits bio <- FLBiol(n=FLQuant(runif(50, 2, 120), dim=c(5, 10))) # Object has no units summary(bio) # Obtain standard units for the class as a list standardUnits(bio) # which can then be assigned to the object units(bio) <- standardUnits(bio) summary(stk)
stk <- FLStock(catch=FLQuant(runif(20, 2, 120))) # FLStock object has no units summary(stk) # Obtain standard units for the class as a list standardUnits(stk) # which can then be assigned to the object units(stk) <- standardUnits(stk) summary(stk) # units<- methjod also accepts a function to be called to provide units units(stk) <- standardUnits bio <- FLBiol(n=FLQuant(runif(50, 2, 120), dim=c(5, 10))) # Object has no units summary(bio) # Obtain standard units for the class as a list standardUnits(bio) # which can then be assigned to the object units(bio) <- standardUnits(bio) summary(stk)
Outputs a general summary of the structure and content of an fwdControl object. The method invisibly returns the data.frame shown on screen.
## S4 method for signature 'FLArray' summary(object, ...) ## S4 method for signature 'FLQuantPoint' summary(object, ...) ## S4 method for signature 'FLPar' summary(object, title = TRUE, ...) ## S4 method for signature 'FLComp' summary(object, ...) ## S4 method for signature 'FLQuants' summary(object) ## S4 method for signature 'predictModel' summary(object) ## S4 method for signature 'FLBiol' summary(object) ## S4 method for signature 'FLModel' summary(object, ...) ## S4 method for signature 'FLlst' summary(object)
## S4 method for signature 'FLArray' summary(object, ...) ## S4 method for signature 'FLQuantPoint' summary(object, ...) ## S4 method for signature 'FLPar' summary(object, title = TRUE, ...) ## S4 method for signature 'FLComp' summary(object, ...) ## S4 method for signature 'FLQuants' summary(object) ## S4 method for signature 'predictModel' summary(object) ## S4 method for signature 'FLBiol' summary(object) ## S4 method for signature 'FLModel' summary(object, ...) ## S4 method for signature 'FLlst' summary(object)
summary(object)
The FLR Team
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') summary(flq) data(ple4) summary(ple4) data(nsher) summary(nsher)
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') summary(flq) data(ple4) summary(ple4) data(nsher) summary(nsher)
A method to generate observations of abundance at age.
survey(object, index, ...) ## S4 method for signature 'FLStock,FLIndex' survey( object, index, sel = sel.pattern(index), ages = dimnames(index)$age, timing = mean(range(index, c("startf", "endf"))), index.q = [email protected], stability = 1 ) ## S4 method for signature 'FLStock,FLIndexBiomass' survey( object, index, sel = sel.pattern(index), ages = ac(seq(range(index, c("min")), range(index, c("max")))), timing = mean(range(index, c("startf", "endf"))), catch.wt = stock.wt(object)[, dimnames(index)$year], index.q = [email protected], stability = 1 ) ## S4 method for signature 'FLStock,missing' survey( object, sel = catch.sel(object), ages = dimnames(sel)$age, timing = 0.5, index.q = 1, biomass = FALSE, stability = 1 ) ## S4 method for signature 'FLStock,FLIndices' survey(object, index, ...)
survey(object, index, ...) ## S4 method for signature 'FLStock,FLIndex' survey( object, index, sel = sel.pattern(index), ages = dimnames(index)$age, timing = mean(range(index, c("startf", "endf"))), index.q = index@index.q, stability = 1 ) ## S4 method for signature 'FLStock,FLIndexBiomass' survey( object, index, sel = sel.pattern(index), ages = ac(seq(range(index, c("min")), range(index, c("max")))), timing = mean(range(index, c("startf", "endf"))), catch.wt = stock.wt(object)[, dimnames(index)$year], index.q = index@index.q, stability = 1 ) ## S4 method for signature 'FLStock,missing' survey( object, sel = catch.sel(object), ages = dimnames(sel)$age, timing = 0.5, index.q = 1, biomass = FALSE, stability = 1 ) ## S4 method for signature 'FLStock,FLIndices' survey(object, index, ...)
object |
The object on which to draw the observation |
An FLQuant for the index of abundance
The FLR Team
data(ple4) data(ple4.index) # CONSTRUCT a survey from stock and index survey(ple4, ple4.index) # Create FLIndexBiomass ple4.biom <- as(ple4.index, "FLIndexBiomass") survey(ple4, ple4.biom) data(ple4) survey(ple4) survey(ple4, biomass=TRUE)
data(ple4) data(ple4.index) # CONSTRUCT a survey from stock and index survey(ple4, ple4.index) # Create FLIndexBiomass ple4.biom <- as(ple4.index, "FLIndexBiomass") survey(ple4, ple4.biom) data(ple4) survey(ple4) survey(ple4, biomass=TRUE)
An FLStock object containing estimates of adundance at age ('stock.n') and harvest level at age ('harvest'), is used to bring forward the population by applying the total mortality at age ('z'). No calculation is made on recruitment, so abundances for the first age will be set as 'NA', unless a value is provided.
survivors(object, rec = NA)
survivors(object, rec = NA)
object |
An FLStock with estimated harvest and abundances |
rec |
Value for recruitment, first age abundance, 'numeric' or 'FLQuant'.' |
The abundances at age of the survivors, 'FLQuant'.
data(ple4) stock.n(ple4[, ac(2002:2006)]) survivors(ple4[, ac(2002:2006)])
data(ple4) stock.n(ple4[, ac(2002:2006)]) survivors(ple4[, ac(2002:2006)])
Use R's sweep method on FLCore classes
## S4 method for signature 'FLArray' sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...) ## S4 method for signature 'FLPar' sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...)
## S4 method for signature 'FLArray' sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...) ## S4 method for signature 'FLPar' sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...)
These methods call base R sweep
method on FLCore classes and then ensure
that the returned object is of same class.
sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...)
The FLR Team
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') # Get ratio of max value by year sweep(flq, 2, apply(flq, 2, max), "/")
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') # Get ratio of max value by year sweep(flq, 2, apply(flq, 2, max), "/")
Standard tail and head methods can be applied along any dimension of an FLQuant object.
## S4 method for signature 'FLQuant' tail(x, n = 1, dim = 2, ...) ## S4 method for signature 'FLQuant' head(x, n = 1, dim = 2, ...)
## S4 method for signature 'FLQuant' tail(x, n = 1, dim = 2, ...) ## S4 method for signature 'FLQuant' head(x, n = 1, dim = 2, ...)
x |
The object to extract from, FLQuant. |
n |
The number of elements to extract, numeric. |
dim |
Dimension to extract from, defaults to 2, 'year'. |
An FLQuant with the extracted elements.
Iago Mosqueira (WMR)
x <- FLQuant(1:10) # Extract the last 3 years tail(x, 3) # Extract all but the first 3 years tail(x, -3) # Extract the first 3 years head(x, 3) # Extract all but the last 3 years head(x, -3)
x <- FLQuant(1:10) # Extract the last 3 years tail(x, 3) # Extract all but the first 3 years tail(x, -3) # Extract the first 3 years head(x, 3) # Extract all but the last 3 years head(x, -3)
Trim FLR objects using named dimensions
trim(x, ...) ## S4 method for signature 'FLArray' trim(x, ...) ## S4 method for signature 'FLComp' trim(x, ...) ## S4 method for signature 'FLS' trim(x, ...) ## S4 method for signature 'FLBiol' trim(x, ...)
trim(x, ...) ## S4 method for signature 'FLArray' trim(x, ...) ## S4 method for signature 'FLComp' trim(x, ...) ## S4 method for signature 'FLS' trim(x, ...) ## S4 method for signature 'FLBiol' trim(x, ...)
Subsetting of FLR objects can be carried out with dimension names by using
trim
. A number of dimension names and selected dimensions are passed
to the method and those are used to subset the input object.
Exceptions are made for those classes where certain slots might differ in
one or more dimensions. If trim is applied to an FLQuant object of length 1
in its first dimension and with dimension name equal to 'all', values to
trim
specified for that dimension will be ignored. For example,
FLStock
objects contain slots with length=1 in their first
dimension. Specifying values to trim over the first dimension will have no
effect on those slots (catch
, landings
, discards
, and
stock
). Calculations might need to be carried out to recalculate
those slots (e.g. using computeCatch
, computeLandings
,
computeDiscards
and computeStock
) if their quant-structured
counterparts are modified along the first dimension.
trim(x)
The FLR Team
FLQuant, FLStock, FLCohort, FLIndex
flq <- FLQuant(rnorm(90), dimnames=list(age=1:10, year=2000:2016)) trim(flq, year=2000:2005) # which is equivalent to window(flq, start=2000, end=2005) trim(flq, year=2000:2005, age=1:2) # Now on an FLStock data(ple4) summary(trim(ple4, year=1990:1995)) # If 'age' is trimmed in ple4, catch, landings and discards need to be # recalculated shpl4 <- trim(ple4, age=1:4) landings(shpl4) <- computeLandings(shpl4) discards(shpl4) <- computeDiscards(shpl4) catch(shpl4) <- computeCatch(shpl4) summary(shpl4)
flq <- FLQuant(rnorm(90), dimnames=list(age=1:10, year=2000:2016)) trim(flq, year=2000:2005) # which is equivalent to window(flq, start=2000, end=2005) trim(flq, year=2000:2005, age=1:2) # Now on an FLStock data(ple4) summary(trim(ple4, year=1990:1995)) # If 'age' is trimmed in ple4, catch, landings and discards need to be # recalculated shpl4 <- trim(ple4, age=1:4) landings(shpl4) <- computeLandings(shpl4) discards(shpl4) <- computeDiscards(shpl4) catch(shpl4) <- computeCatch(shpl4) summary(shpl4)
units
attribute for FLQuant and FLArray-derived objects
## S4 method for signature 'FLArray' units(x) ## S4 replacement method for signature 'FLArray,character' units(x) <- value setunits(x, value) ## S4 method for signature 'FLPar' units(x) ## S4 replacement method for signature 'FLPar,character' units(x) <- value ## S4 method for signature 'FLComp' units(x) ## S4 replacement method for signature 'FLComp,list' units(x) <- value ## S4 replacement method for signature 'FLComp,character' units(x) <- value ## S4 replacement method for signature 'FLComp,function' units(x) <- value
## S4 method for signature 'FLArray' units(x) ## S4 replacement method for signature 'FLArray,character' units(x) <- value setunits(x, value) ## S4 method for signature 'FLPar' units(x) ## S4 replacement method for signature 'FLPar,character' units(x) <- value ## S4 method for signature 'FLComp' units(x) ## S4 replacement method for signature 'FLComp,list' units(x) <- value ## S4 replacement method for signature 'FLComp,character' units(x) <- value ## S4 replacement method for signature 'FLComp,function' units(x) <- value
Objects of FLArray
-based classes (e.g. FLQuant
) contain a
units
attribute of class character
. This should be used to store
the corresponding units of measurement. This attribute can be directly accessed
and modified using the units
and units<-
methods.
For complex objects, units
will return a named list containing the
attributes of all FLQuant
slots. units
of a complex object can
be modified for all slots or a subset of them, by passing a named list with
the new values. See examples below.
The complete set of units for a complex object can be obtained as a named list.
Assignment of units to the FLQuant slots of a complex object can be carried out passing a named list or character vector containing the units for the slots to be modified.
units(x)
units<-(x,value)
The FLR Team
flq <- FLQuant(rnorm(100), dim=c(5,20), units='kg') units(flq) units(flq) <- 't' summary(flq) # units for a complex object data(ple4) units(ple4) units(ple4) <- list(harvest='hr') data(ple4) units(ple4) <- list(harvest="hr") units(ple4) <- c(harvest="hr")
flq <- FLQuant(rnorm(100), dim=c(5,20), units='kg') units(flq) units(flq) <- 't' summary(flq) # units for a complex object data(ple4) units(ple4) units(ple4) <- list(harvest='hr') data(ple4) units(ple4) <- list(harvest="hr") units(ple4) <- c(harvest="hr")
The 'units' attribute of FLQuant objects provides a mechanism for keeping track of the units of measurement of that particular piece of data.
uom(op, u1, u2) uomUnits(unit = missing)
uom(op, u1, u2) uomUnits(unit = missing)
op |
The arithmetic operator to be used, one of '+', '-', '*' or '/' |
u1 |
The units of measurement string of the first object |
u2 |
The units of measurement string of the second object |
unit |
A character vector for one or more units to be compared with those known to |
Arithmetic operators for 'FLQuant' objects are aware of a limited set of units of measurement and will output the right unit when two object are arithmetically combined. For example, the product of object with units of 'kg' and '1000' will output an object with 'units' of 't' (for metric tonnes).
Operations involving combinations of units not defined will issue a warning, and the resulting 'units' attribute will simply keep a string indicating the input units of measurement and the operation carried out, as in '10 * 1000'.
Note that no scaling or modification of the values in the object takes place.
Conversion across units is carried out by the uom()
function
The list of units known to uom
is stored internally but can be queried by calling uomUnits()
with no arguments. If a character vector is provided, a logical is returned telling whether the string is included or not in that table.
uom
returns a string with the corresponding units of measurement, or a character vector, showing the operation carried out, when units are not known to uom
or not compatible, e.g. "100 * d".
uomUnits
returns TRUE or FALSE if unit
is given, otherwise a character vector with all units known to uom
.
The FLR Team
# Conversion between weights FLQuant(1, units='kg') * FLQuant(1000, units='1') # Conversion between mortalities FLQuant(0.2, units='m') + FLQuant(0.34, units='f') # Check if units are known uomUnits('kg') uomUnits('kell')
# Conversion between weights FLQuant(1, units='kg') * FLQuant(1000, units='1') # Conversion between mortalities FLQuant(0.2, units='m') + FLQuant(0.34, units='f') # Check if units are known uomUnits('kg') uomUnits('kell')
uom defaults to NA unless defined below.
unit +/- itself, returns the same unit (e.g. kg + kg = kg)
numeric unit * 1 returns same unit (e.g. 1e4 * 1 = 1e4)
numeric unit * numeric unit returns product (e.g. 10 * 100 = 1000)
unit / unit returns "" (e.g. 100 / 100 = "")
numeric unit / smaller numeric unit returns division (e.g. 100 / 10 = 10)
100 times kg returns t
numeric unit * 'kg' returns the product in tonnes (e.g. kg * 1e4 = t * 10)
units with divisions are parsed (e.g. days/boat * boat = days)
An object of class array
Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
lower(object, ...) ## S4 method for signature 'FLModel' lower(object) ## S4 method for signature 'FLModel' upper(object)
lower(object, ...) ## S4 method for signature 'FLModel' lower(object) ## S4 method for signature 'FLModel' upper(object)
object |
Object to extract from or modify |
... |
Other arguments |
value |
New value |
Details: Aliquam sagittis feugiat felis eget consequat.
RETURN Lorem ipsum dolor sit amet
The FLR Team
Verifies the content of FLR objects according to a set of rules
verify(object, ...) ## S4 method for signature 'FLComp' verify(object, ..., report = TRUE) ## S4 method for signature 'FLStock' verify(object, rules = ruleset(object), ..., report = TRUE)
verify(object, ...) ## S4 method for signature 'FLComp' verify(object, ..., report = TRUE) ## S4 method for signature 'FLStock' verify(object, rules = ruleset(object), ..., report = TRUE)
object |
An object of any FLR class for which the method has been defined |
... |
Additional rules to be tested, as a formula or list. See details |
report |
Should the standard data.frame report be output (if TRUE) or a single logical value for all tests? |
rules |
Basic set of rules for a given class, as returned by ruleset(). |
Classes' validity functions generally check the structure and dimensions of objects and their component slots. But some checks on the data content of objects is often required. The various verify methods implement both a system to create rules that an object is expected to pass, and a minimum standard set of rules for each defined class
The data.frame output by the method when report=TRUE
contains one row per
rule and the following columns:
name, the rule name
items, number of comparisons carried out
passes, number of TRUE values
fails, number of FALSE values
NAs, number of logical NAs
valid, are all values TRUE?
rule, the expression being evaluated
Additional rules can be specify in a call to verify, in one of two forms.
Simple rules can be defined as a formula involving methods defined for the
class. A rule such as highm = ~ m < 2
will check if values in the m slot are
higher than 2 and return a logical FLQuant.
Some rules cannot simply use existing methods or functions, for example those operating on all slots of the object, or requiring additional computations. In this case, the argument to verify can be a list, with an element named rule of class formula and where test is defined. The test then calls for a new function, defined as another element of the list, and which will be used by verify when evaluating the set of rules. See below for examples.
A set of rules has been defined for the FLStock class, available by calling the ruleset method. The verify method for FLStock will by default evaluate those rules, as well as any other defined in the call.
A data.frame with the results of applying those rules, or a single logical value, if report=FALSE
The FLR Team
# Verifying a new rule for an FLSR object data(nsher) # rule: are all recruitment values greater than 0? verify(nsher, rec=~rec > 0) # Define rule calling its own function data(ple4) # rule: ssb is less verify(ple4, ssbstock = ~ssb < stock) data(ple4) # verify for the standard set of rules for FLStock verify(ple4) # verify a single rule from set verify(ple4, rules=ruleset(ple4, 'anyna'), report=FALSE) # add own rule to set verify(ple4, m = ~m >=0)
# Verifying a new rule for an FLSR object data(nsher) # rule: are all recruitment values greater than 0? verify(nsher, rec=~rec > 0) # Define rule calling its own function data(ple4) # rule: ssb is less verify(ple4, ssbstock = ~ssb < stock) data(ple4) # verify for the standard set of rules for FLStock verify(ple4) # verify a single rule from set verify(ple4, rules=ruleset(ple4, 'anyna'), report=FALSE) # add own rule to set verify(ple4, m = ~m >=0)
Growth models
ivonbert
gompertz
richards
vonbert(linf, k, t0, age) ivonbert(linf, k, t0, len) gompertz(linf, a, k, age) richards(linf, k, b, m, age)
vonbert(linf, k, t0, age) ivonbert(linf, k, t0, len) gompertz(linf, a, k, age) richards(linf, k, b, m, age)
data(ple4) vonbert vonbert(linf=35, k=0.352, t0=-0.26, age=1:14) ivonbert(35, 0.352, -0.26, 1:34) gompertz(linf=179.13, k=0.4088, a=1.7268, age=1:12) richards(linf=178.63, k=0.424, b=-7.185, m=2880.4, age=1:12)
data(ple4) vonbert vonbert(linf=35, k=0.352, t0=-0.26, age=1:14) ivonbert(35, 0.352, -0.26, 1:34) gompertz(linf=179.13, k=0.4088, a=1.7268, age=1:12) richards(linf=178.63, k=0.424, b=-7.185, m=2880.4, age=1:12)
Facilitates the calculation of weighted means across a FLQuants object.
## S4 method for signature 'FLQuants,FLQuants' weighted.mean(x, w)
## S4 method for signature 'FLQuants,FLQuants' weighted.mean(x, w)
x |
Values to be averaged, as an object of class |
w |
weights to be used, as an object of class |
An object of class FLQuants containing elements over which an average is to computed, is combined with another one, of the same length, containing values to be used as weights. The overall weighted mean is calculated by computing the product of each element to its corresponding weight, and dividing by the sum of all weights. NAs in the value elements are substituted for zeroes, so do not influence the mean.
A single FLQuant
object.
The FLR Team
FLCore::FLQuants stats::weighted.mean
data(ple4) # Weighted mean of landings and discards weights-at-age weighted.mean(FLQuants(L=landings.wt(ple4), D=discards.wt(ple4)), FLQuants(L=landings.n(ple4), D=discards.n(ple4)))
data(ple4) # Weighted mean of landings and discards weights-at-age weighted.mean(FLQuants(L=landings.wt(ple4), D=discards.wt(ple4)), FLQuants(L=landings.n(ple4), D=discards.n(ple4)))
3D plot for FLQuant objects
## S4 method for signature 'formula,FLQuant' wireframe(x, data, ...)
## S4 method for signature 'formula,FLQuant' wireframe(x, data, ...)
x |
a |
data |
a |
... |
Additional argument list to be passed to |
Method to plot 3D representations of FLQuant objects
a wireframe
plot
data(ple4) wireframe(data~age+year, data=harvest(ple4))
data(ple4) wireframe(data~age+year, data=harvest(ple4))
A resample from an FLQuant object along the 'year' dimension is returned. The 'year' dimnames of the output object can be specified, although that is not needed if the resample is to be assigned in a slot.
yearSample(x, size = length(years), years, replace = TRUE, prob = NULL)
yearSample(x, size = length(years), years, replace = TRUE, prob = NULL)
x |
An FLQuant object. |
size |
Number of samples (years), non-negative integer. |
years |
Optional vector to set as 'year' dimnames in output. |
replace |
should sampling be with replacement? Defaults to TRUE. |
prob |
a vector of probability weights. |
RETURN Description, class
Iago Mosqueira (WMR)
data(ple4) # Take 20 samples of recent recruitment yearSample(rec(ple4)[, ac(2013:2017)], 20) # Providing 'years' sets the output object dimnames yearSample(rec(ple4)[, ac(2013:2017)], 20, year=2000:2019)
data(ple4) # Take 20 samples of recent recruitment yearSample(rec(ple4)[, ac(2013:2017)], 20) # Providing 'years' sets the output object dimnames yearSample(rec(ple4)[, ac(2013:2017)], 20, year=2000:2019)
Returns the calculation of total mortality, z, usually as the sum of fishing mortality, f, and natural mortality, m.
z(object, ...) ## S4 method for signature 'FLS' z(object, ...)
z(object, ...) ## S4 method for signature 'FLS' z(object, ...)
object |
Object to calculate on. |
... |
Any extra arguments. |
An object of the corresponding class, usually FLQuant.
The FLR Team
data(ple4) z(ple4)
data(ple4) z(ple4)