Method to convert length-based data to age-based

l2a(object, model, ...)

# S4 method for FLQuant,a4aGr
l2a(
  object,
  model,
  halfwidth = c(diff(as.numeric(dimnames(object)[[1]])),
    tail(diff(as.numeric(dimnames(object)[[1]])), 1))/2,
  stat = "sum",
  max_age = NA
)

# S4 method for FLStockLen,a4aGr
l2a(object, model, plusgroup = NA, ...)

# S4 method for FLIndex,a4aGr
l2a(object, model, ...)

Arguments

object

an FLQuant, or FLStockLen object.

model

an a4aGr object

...

additional argument list that might never be used

halfwidth

the halfwidths of the length classes; a single numeric or vector the size of the number of length classes; not used if object is an FLStockLen

stat

the aggregation statistic, which must be mean or sum; only used if object is an FLQuant.

max_age

the maximum age in the returned FLQuant; all ages above this are set to max_age; only used if object is an FLQuant

plusgroup

the plusgroup of the stock; only used if the object is an FLStockLen.

Value

an age based FLQuant, FLStock

Details

A deterministic slicing method converts the length-based data to age-based data, using the supplied growth model (the a4aGr object). Each length-based observation is allocated to a corresponding age, based on the growth model, and aggregated accordingly (either the sum or the mean). There should be 1 or n iterations in both the object being sliced and the growth model. This means that although the slicing method is deterministic, the length-based data is sliced by each iteration of the growth parameters, thereby propagating the uncertainty in the biological growth parameters (representing process uncertainty) through to the age-based data.

Examples

# Southern hake
# Variance-covariance matrix for parameters
mm <- matrix(NA, ncol=3, nrow=3)
diag(mm) <- c(2310, 0.13, 0.84)
mm[upper.tri(mm)] <- mm[lower.tri(mm)] <- c(-7.22,-6.28,0.08)
# Make the von Bertalanffy growth model
md <- ~linf*(1-exp(-k*(t-t0)))
imd <- ~t0-1/k*log(1-len/linf)
prs <- FLPar(linf=130, k=0.164, t0=-0.092, units=c("cm","yr-1","yr"))
vbObj <- a4aGr(grMod=md, grInvMod=imd, params=prs, vcov=mm, distr="norm")
# Make a triangle copula for simulating process error
linf <- list(a=104.5, b=155.5, c=130) 
k <- list(a=0.132, b=0.196, c=0.164)
t0 <- list(a=-0.184, b=0, c=-0.092)
tri_pars <- list(linf = linf, k = k, t0 = t0)
# Simulate 10 iterations from it
vbObj_tri <- mvrtriangle(10, vbObj, paramMargins=tri_pars)
#> Warning: margins correct? Currently, have no function(s) named: ptriangle
#> Warning: margins correct? Currently, have no function(s) named: dtriangle
#> Error in qtriangle(x, a = 104.5, b = 155.5, c = 130): could not find function "qtriangle"
data(southernHakeLen)
# Extract the catch numbers at length from stock object
cth <- catch.n(shake_len) 
# Slice the data using the unsimulated growth object 
# so the stock and the growth object have 1 iteration
cthA1 <- l2a(cth, vbObj)
# Slice with 1 iteration in stock and multiple in growth object
cthA2 <- l2a(cth, vbObj_tri)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'model' in selecting a method for function 'l2a': object 'vbObj_tri' not found
# Result is age based catch with multiple iterations
# mod: iter=1, data: iter=n
cthA3 <- l2a(propagate(cth,10), vbObj)
# both with iter=n
cthA4 <- l2a(propagate(cth,10), vbObj_tri)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'model' in selecting a method for function 'l2a': object 'vbObj_tri' not found
# converting a stock object
shake_age <- l2a(shake_len, vbObj)
#> Warning: Individual weights, M and maturity will be (weighted) averaged accross lengths,
#>  harvest is not computed and everything else will be summed.
#>  If this is not what you want, you'll have to deal with these slots by hand.
shake_age <- l2a(shake_len, vbObj_tri)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'model' in selecting a method for function 'l2a': object 'vbObj_tri' not found
shake_age <- l2a(propagate(shake_len, 10), vbObj)
#> Warning: Individual weights, M and maturity will be (weighted) averaged accross lengths,
#>  harvest is not computed and everything else will be summed.
#>  If this is not what you want, you'll have to deal with these slots by hand.
shake_age <- l2a(propagate(shake_len, 10), vbObj_tri)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'model' in selecting a method for function 'l2a': object 'vbObj_tri' not found
# converting a index object
index_pt_age <- l2a(index_pt_len, vbObj)
index_pt_age <- l2a(index_pt_len, mvrnorm(10, vbObj))
#> Warning: Some ages are less than 0, indicating a mismatch between input data lengths
#>  and growth parameters (possibly t0)
#> Warning: Trimming age range to a minimum of 0
index_pt_age <- l2a(propagate(index_pt_len, 10), vbObj)