metrics: Extract simply-defined metrics from complex objects

metricsR Documentation

Extract simply-defined metrics from complex objects

Description

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.

Usage

metrics(object, metrics, ...)

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

## S4 method for signature 'FLS,missing'
metrics(object, metrics, ...)

## S4 method for signature 'FLBiol,missing'
metrics(object, metrics, ...)

Arguments

object

A complex FLR object from which to extract time series metrics.

metrics

A named list of function, expressions or function names.

...

Extra definitions for metrics to be added to the class defaults

Details

A set of default metrics are defined for each class, as listed below. A call to the metrics method with no 'metrics' argument will return the default ones. Extra metrics can be computed by passing them as named arguments, like in ther examples below.

Value

An object, generally of class FLQuants.

Author(s)

The FLR Team

See Also

FLComp, linkFLStock, FLBiol

Examples

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)
# Get default metrics
metrics(ple4)
# Adds to defaults
metrics(ple4, PG=function(x) stock.n(x)[10,])
# Defines metrics to be computed
metrics(ple4, metrics=list(PG=function(x) stock.n(x)[10,]))
data(ple4.biol)
# Get default metrics
metrics(ple4.biol)
# Adds to defaults
metrics(ple4.biol, PG=function(x) n(x)[10,])
# Defines metrics to be computed
metrics(ple4.biol, metrics=list(PG=function(x) n(x)[10,]))

flr/FLCore documentation built on June 12, 2025, 3:17 p.m.