Set up biological inputs for the estimation model
Source:R/setup_biologicals.R
Setup_Mod_Biologicals.RdSets weight-at-age, maturity-at-age, ageing error, the size-age transition and
any growth model, the numbers-at-age state, and the natural mortality blocks and
mapping. Call after Setup_Mod_Dim.
Usage
Setup_Mod_Biologicals(
input_list,
WAA,
WAA_fish = NULL,
WAA_srv = NULL,
MatAA,
addtocomp = NULL,
comp_const_obs = NULL,
addtofishidx = NULL,
addtosrvidx = NULL,
addtotag = NULL,
AgeingError = NULL,
AgeingError_fish = NULL,
AgeingError_srv = NULL,
Use_M_prior = 0,
M_prior = NA,
fit_lengths = 0,
SizeAgeTrans = NA,
SizeAgeTrans_fish = NULL,
SizeAgeTrans_srv = NULL,
do_caal = 0,
growth_model = "none",
growth_spec = "est_all",
growth_fix = NULL,
growth_tv_model = NULL,
growth_tv_years = NULL,
growth_tv_link = "log",
growth_par_bounds = NULL,
growth_tv_sigma_spec = "fix",
growth_tv_spec = "est_all",
growth_tv_type = "curve",
growth_rw_init_sigma = 5,
growth_semipar = "none",
growth_semipar_spec = "fix",
growth_semipar_ages = NULL,
growth_semipar_years = NULL,
LenBinMap = NULL,
CAAL_LenBinMap = NULL,
growth_A1 = NULL,
growth_A2 = NULL,
growth_len_lower = NULL,
growth_L0 = NULL,
growth_cv_type = "len",
growth_sd_type = "cv",
growth_dist = "normal",
growth_plus_group = "mixture",
waa_model = "data",
wt_len_pars = NULL,
M_spec = "est_ln_M",
M_popblk_spec = "constant",
M_ageblk_spec = "constant",
M_regionblk_spec = "constant",
M_yearblk_spec = "constant",
M_seasblk_spec = "constant",
M_sexblk_spec = "constant",
Fixed_natmort = NULL,
NAA_re = "none",
NAA_re_ages = NULL,
NAA_re_years = NULL,
NAA_re_seasons = "annual",
NAA_re_season = "iid",
NAA_re_season_spec = "est_all",
NAA_re_where = NULL,
NAA_pe_spec = "est_all",
NAA_sigma_spec = "est",
NAA_re_region = "iid",
NAA_re_region_spec = "est_all",
NAA_re_pop = "iid",
NAA_re_sex = "iid",
NAA_sigma_popblk_spec = "constant",
NAA_sigma_regionblk_spec = "constant",
NAA_sigma_yearblk_spec = "constant",
NAA_sigma_seasblk_spec = "constant",
NAA_sigma_ageblk_spec = "constant",
NAA_sigma_sexblk_spec = "constant",
...
)Arguments
- input_list
Named list with
$data,$par,$mapand$verbose, as returned bySetup_Mod_Dim.- WAA
Spawning weight-at-age array
[n_pop × n_regions × n_years × n_seas × n_ages × n_sexes], also the fallback forWAA_fishandWAA_srv.- WAA_fish
Fishery weight-at-age array,
WAAwith a trailingn_fish_fleetsdim.NULL(default) readsWAAfor every fleet.- WAA_srv
Survey weight-at-age array,
WAAwith a trailingn_srv_fleetsdim.NULL(default) readsWAAfor every fleet.- MatAA
Maturity-at-age array in \([0,1]\), dimensioned like
WAA. Maturity at the first age must be exactly0underrec_lag = 0, soSetup_Mod_Recmust have been called first.- addtocomp
Deprecated here, pass it to
Setup_Mod_Weighting. Still forwarded with a message. The constant added to composition proportions to avoidlog(0), ignored by the logistic normal.- comp_const_obs
Deprecated here, pass it to
Setup_Mod_Weighting. Still forwarded with a message. Integer switch for whereaddtocompenters the multinomial:1adds it to the observed proportions that weight the likelihood as well as inside the logarithms, so the likelihood is stationary atpred = obs,0weights by the raw observed proportions.- addtofishidx, addtosrvidx, addtotag
Deprecated here, pass them to
Setup_Mod_Weighting. Still forwarded with a message. Constants added to the fishery indices, survey indices and tag recoveries.- AgeingError
Ageing error array mapping true model ages onto observed age bins. Each row is one model age's share across the observed bins, summing to one, or to zero to drop that age. The age-axis twin of
LenBinMap: the likelihood applies and validates the two identically. It sets which binsObsCatchAA,ObsDiscardAAandObsSrvIdxAAare dimensioned by; use the*_binsarguments to leave bins out of the likelihood instead. A[n_model_ages × n_obs_ages]matrix is time-invariant and expanded across years, a[n_years × n_model_ages × n_obs_ages]array is time-varying, andNULL(default) builds an identity matrix. For observed bins that are a subset of the model ages, supply a shifted identity such asdiag(1, n_model_ages)[, obs_age_index].- AgeingError_fish
Optional per-fleet ageing error for the fishery fleets, either
[n_model_ages × n_obs_ages × n_fish_fleets]or with a leadingn_yearsdim, orNULL(default) to read the sharedAgeingError. Each slice is validated asAgeingErroris, and every fleet must land on the same observed bins. Read by a fleet's age compositions and its catch and discards at age.- AgeingError_srv
As
AgeingError_fishwithn_srv_fleetsin place ofn_fish_fleets. Read by a fleet's age compositions and its index at age.- Use_M_prior
Integer flag for a lognormal prior on natural mortality.
0(default) or1.- M_prior
Data frame of prior hyperparameters, one row per block combination, with columns
popblk,regionblk,yearblk,ageblk,sexblk,muon the natural scale,sd, and optionallyseasblk(left out, it reads the block covering season one). Only used whenUse_M_prior = 1.- fit_lengths
Integer flag for fitting length compositions,
0(default) or1. Requires a validSizeAgeTrans.- SizeAgeTrans
Size-at-age transition array
[n_pop × n_regions × n_years × n_seas × n_lens × n_ages × n_sexes], column-stochastic over ages. Required whenfit_lengths = 1. Read by every fleet unless overridden.- SizeAgeTrans_fish, SizeAgeTrans_srv
Optional per-fleet size-at-age arrays, dimensioned like
SizeAgeTranswith a trailing fleet dim.NULL(default) reads the shared array. Only meaningful undergrowth_model = "none"; a growth model already derives one key per fleet at that fleet's timing and refuses these.- do_caal
Integer flag for building the joint arrays at length and age,
0(default) or1. Requiresfit_lengths = 1and addsFish_caal,Fish_caal_discardandSrv_caalto the report.- growth_model
"none"(default) keepsSizeAgeTransand the weight-at-age arrays as data."vb_schnute"builds the size-age key from estimable von Bertalanffy parameters in Schnute's form: lengthL1atgrowth_A1,L2atgrowth_A2, rateK, and CVsCV1andCV2at the two reference ages."richards"adds the coefficientrho, withrho = 1recovering von Bertalanffy. Both requirefit_lengths = 1and ignoreSizeAgeTrans.- growth_spec
How the growth parameters are estimated:
"est_all"(default, one set per population, region and sex),"est_shared_r","est_shared_s","est_shared_r_s", or"fix".- growth_fix
Logical vector, one entry per growth parameter, naming which of L1, L2, K, CV1, CV2 and rho stay at their starting values whatever
growth_specsays.- growth_tv_model
Time variation of the growth parameters.
NULL(default) holds every parameter constant. Otherwise a character vector of lengthn_growth_parsin parameter order, or named by parameter, each"none","iid","rw", or"dsem". A varying parameter gets a deviation seriesln_growth_devsand a log sigma in the time-varying half ofgrowth_pe_pars; under"dsem"the density comes fromSetup_Mod_DSEMand that sigma stays at its start.- growth_tv_years
Calendar years the deviations are active in.
NULL(default) for every model year, a vector for every varying parameter, or a list named by parameter. Deviations outside the range are kept at zero.- growth_tv_link
The scale a deviation enters on.
"log"(default) multiplies the parameter by \(e^{\delta}\);"logit"keeps it insidegrowth_par_bounds, so the parameter approaches a bound instead of crossing it.- growth_par_bounds
Matrix
[n_growth_pars x 2]of lower and upper bounds on the natural scale, required under the logit link.- growth_tv_sigma_spec
"fix"(default) holds the process error sds of the deviations at their starting values,"est"estimates them. Both read the time-varying half ofgrowth_pe_pars, one slot per growth parameter.- growth_tv_spec
How the deviations are shared across strata, in the
growth_specvocabulary:"est_all"(default),"est_shared_r","est_shared_s"or"est_shared_r_s".- growth_tv_type
"curve"(default) reads every year's size at age off that year's curve."cohort"advances size at age cohort by cohort: each cohort grows by the increment the current year's parameters imply from the size it reached, ages still in the linear phase keep their birth year's length atgrowth_A1, the first age pastgrowth_A1is placed on the current year's curve, and the plus group blends the entering cohort with the fish already there by numbers at age. The CV at age stays at the first year's sizes, and propagation starts in the first year any deviation is active.- growth_rw_init_sigma
Standard deviation given to the first year of a random walk on a growth parameter, as
srvsel_rw_init_sigmafor selectivity. Default5.- growth_semipar
Semi-parametric growth: a year by age surface of deviations multiplying the parametric curve, so the deviations move mean length around it.
"none"(default) keeps growth parametric; otherwise"iid","rw"over years within an age,"3dmarg"or"3dcond"(a Gaussian Markov random field over age, year and cohort on the marginal or conditional variance),"2dar1"(separable over ages and years), or"dsem"(density fromSetup_Mod_DSEM, one series per age, which refusesgrowth_semipar_spec = "est"). The spread at age follows the deviated mean, leaving the CV at age to the parametric part.- growth_semipar_spec
Whether the semi-parametric half of
growth_pe_parsis estimated ("est") or kept at its starting values ("fix", default). The deviations themselves are always estimated.- growth_semipar_ages
Ages the deviations are estimated over, as ages rather than indices.
NULL(default) uses every age; ages outside the set stay at zero.- growth_semipar_years
Calendar years the deviations are estimated over.
NULL(default) uses every year.- LenBinMap
Optional matrix
[n_lens x n_obs_lens]mapping the model's length bins onto the bins the compositions are recorded on, for compositions on coarser bins than the model has. Each row is one model bin's share across the observed bins, summing to one, or to zero to drop that bin. The length-axis twin ofAgeingError, applied and validated identically. Use the*LenComps_binsarguments to leave bins out of the likelihood instead.NULL(default) fits on the model bins.- CAAL_LenBinMap
Optional 0/1 matrix
[n_lens x n_caal_lens]saying which model length bins each length row of the conditional age-at-length data covers, one column per row. A row's expected ages are the numbers at length and age summed over the bins it covers, so rows can sit on coarser bins than the model, and need not cover every bin. UnlikeLenBinMap, its rows need not sum to one, since a model bin can sit in no row or in several. The age-at-length arrays are then dimensioned byn_caal_lens.NULL(default) gives one row per model bin.- growth_A1, growth_A2
Reference ages for
L1andL2.growth_A2 = "Linf"makesL2the asymptotic length itself.- growth_len_lower
Lower edges of the length bins.
lensinSetup_Mod_Dimare midpoints; the key is built on the edges.- growth_L0
Length at age zero anchoring the linear phase. Defaults to
growth_len_lower[1].- growth_cv_type
"len"(default) interpolates the CV on mean length betweenL1andL2,"age"on age.- growth_sd_type
"cv"(default) scales the mean by the CV parameters,"sd"reads them as standard deviations.- growth_dist
"normal"(default) or"lognormal"length at age.- growth_plus_group
"mixture"(default) takes the plus group's mean length as the survivorship-weighted mixture of the ages it holds, their numbers declining at an assumed 0.2 per year;"curve"reads the curve at the accumulator age.- waa_model
Where weight at age comes from.
"data"(default) readsWAA,WAA_fishandWAA_srv."wt_len"builds them from the size-age key and \(W = a L^b\) at the bin midpoints, so weight at age holds the spread of length at age; the spawning weight uses the key at spawning time and each fleet's weight the key att_fishort_srv. Under"wt_len"WAAmay beNULL, and reference point and projection code still readdata$WAA, so copy the reported arrays into the data list before calling them.- wt_len_pars
Weight-length parameters \(a, b\), a vector of two or an array
[n_pop x n_regions x n_sexes x 2]. Required underwaa_model = "wt_len".- M_spec
Natural mortality estimation.
"est_ln_M"(default) estimatesln_Macross the blocks;"fix"holds mortality atFixed_natmortand mapsln_Moff.- M_popblk_spec
Blocking for
ln_Macross populations, either"constant"(default) or a list of integer index vectors, e.g.list(1, 2).- M_ageblk_spec
Blocking across ages,
"constant"(default) or a list of integer index vectors, e.g.list(1:5, 6:10).- M_regionblk_spec
Blocking across regions,
"constant"(default) or a list of integer index vectors, e.g.list(1:3, 4:5).- M_yearblk_spec
Blocking across years,
"constant"(default) or a list of integer index vectors, e.g.list(1:10, 11:30).- M_seasblk_spec
Blocking across seasons,
"constant"(default, one rate all year) or a list of integer index vectors, e.g.list(1:2, 3:4). Blocks hold rates per year, so two half-year seasons at0.2and0.4accumulate an annual0.3. Only identifiable off within-year data (seasonal catch, seasonal comps, or surveys in more than one season), and even then the annual total comes back much better than the split, so prefer fixing the split and estimating the level. Warns for a single season model.- M_sexblk_spec
Blocking across sexes,
"constant"(default) or a list of integer index vectors, e.g.list(1, 2).- Fixed_natmort
Fixed natural mortality array, either
[n_pop × n_regions × n_years × n_ages × n_sexes]or the same withn_seasbetween years and ages; the 5d form is expanded across seasons. Values are rates per year either way, so mortality in a season is the rate timesseasdur. Required whenM_spec = "fix".- NAA_re
State-space numbers at age: the log numbers become parameters for ages two and older including the plus group, and the deterministic mortality and ageing step becomes the prediction they are penalized against.
"none"(default) keeps numbers deterministic; otherwise"iid","1dar1_a"over ages,"1dar1_y"over years,"2dar1"separable over both,"3dcond"or"3dmarg"over age, year and cohort, or"dsem", which takes the density fromSetup_Mod_DSEMone series per state age, leavesln_sigmaNAAat its start and refusesNAA_sigma_spec = "est". Each series is the log state with the log deterministic prediction as its mean. Age one belongs toln_RecDevsand year one at ages two and older toln_InitDevs, so the three partition the numbers at age. Which cells are estimated is set bymap$ln_NAAanddata$n_est_naa_re, never bydim(ln_NAA). The state covers the assessment years only, so a forecast fromDo_Population_Projectionomits this process error while the closed loop operating model projects the state forward.- NAA_re_ages
Ages the state is estimated over, matched against
input_list$data$agesby value. A model on ages0:4takesc(1, 2, 3, 4)for the full state.NULL(default) usesages[-1]. Must be a contiguous run.- NAA_re_years
Calendar years the state is estimated over, matched against
input_list$data$yearsby value.NULL(default) usesyears[-1]. Must be a contiguous run.- NAA_re_seasons
Seasons the state is estimated over.
"annual"(default) puts a state at season one only, leaving the numbers within a year deterministic."all"puts one at the start of every season, and an integer vector selects specific seasons, which need not be contiguous. Use it when only some seasons have observations, since a season with no data returns its prior as its posterior. The age, year and cohort correlations inNAA_pe_parshave no season dim, so every active season shares them within a population, region and sex; only the standard deviation varies by season, throughNAA_sigma_seasblk_spec.- NAA_re_season
Correlation across seasons within a year.
"iid"(default) leaves the seasonal innovations independent;"us"estimates an unstructured correlation, \(n_k(n_k-1)/2\) parameters over the \(n_k\) active seasons. Needs more than one active season.- NAA_re_season_spec
How the season correlations are shared, taking the same values as
NAA_re_region_spec.- NAA_re_where
Integer matrix
[population, region],1where the state runs and0where a population never occupies that region.NULL(default) gives every cell a state. A cell holding no fish has an undefined lognormal state, so0drops it from the map and the penalty; such cells need the region and population correlations off.- NAA_pe_spec
How the age, year and cohort correlations in
NAA_pe_parsare shared."est_all"(default) gives a free set per population, region and sex."est_shared_p","est_shared_r"and"est_shared_s"share one dim,"est_shared_p_r","est_shared_p_s"and"est_shared_r_s"two, and"est_shared_p_r_s"gives one set for the model."fix"holds them at their starting values. Sharing a correlation is not correlating the innovations: regions that share \(\rho\) still get independent shocks, whereasNAA_re_region = "us"makes the shocks covary.- NAA_sigma_spec
Whether the process error standard deviations are estimated (
"est", default) or kept at their starting values ("fix"). The states themselves are always estimated.- NAA_re_region
Correlation across regions, composed with the age and year grid.
"iid"(default) leaves regions independent,"us"estimates an unstructured correlation of \(n_r(n_r-1)/2\) parameters.- NAA_re_region_spec
How the region correlations are shared.
"est_all"(default) gives a free matrix per population and sex,"est_shared_p"and"est_shared_s"share one dim,"est_shared_p_s"gives a single matrix, and"fix"holds them.- NAA_re_pop, NAA_re_sex
Correlation across populations and across sexes, composed with the region, age and year structures.
"iid"(default) leaves them independent,"us"estimates an unstructured correlation. Both are global, so a two-sex model spends one parameter onNAA_re_sex = "us".- NAA_sigma_popblk_spec, NAA_sigma_regionblk_spec, NAA_sigma_yearblk_spec, NAA_sigma_seasblk_spec, NAA_sigma_ageblk_spec, NAA_sigma_sexblk_spec
Blocking for the process error standard deviation, each
"constant"(default) or a list of integer vectors, exactly as theM_*blk_specarguments. Blocking shares a standard deviation and never removes a cell from the state. OnlyNAA_re = "iid"admits one varying over years or ages; every other form is separable or Markov in a dim. The season dim is the exception, being whitened outside the age and year density, and is ruled out only byNAA_re_season = "us".- ...
Optional starting values by name.
ln_Mis dimensioned[n_popblks × n_regionblks × n_yearblks × n_seasblks × n_ageblks × n_sexblks]and defaults tolog(0.5); a 5d array from an older script works when there is one season block.ln_growth_parsis[n_pop × n_regions × n_sexes × n_growth_pars]in the orderL1, L2, K, CV1, CV2andrho, defaulting to the ends of the length bins with a rate of0.15and CVs of0.1, so supply your own for any real model.growth_pe_parsis[n_pop × n_regions × max(4, n_ages, n_growth_pars) × n_sexes × 2]: the time-varying half holds one log sigma per growth parameter, and the semi-parametric half holds the surface's correlations by age, year and cohort in slots one to three with a log scale in slot four, or one log sigma per age under"iid"and"rw". Slots a form does not read are mapped off. All...arguments are ignored whenM_spec = "fix".
Value
input_list with $data, $par and $map updated,
including $data$WAA, $data$WAA_fish, $data$WAA_srv,
$data$MatAA, $data$AgeingError, $data$M_blocks,
$par$ln_M and $map$ln_M.
See also
Other Model Setup:
Setup_Mod_Catch_and_F(),
Setup_Mod_Dim(),
Setup_Mod_Discard_Comps(),
Setup_Mod_FishIdx_and_Comps(),
Setup_Mod_Fishsel_and_Q(),
Setup_Mod_Movement(),
Setup_Mod_Rec(),
Setup_Mod_Retsel(),
Setup_Mod_SrvIdx_and_Comps(),
Setup_Mod_Srvsel_and_Q(),
Setup_Mod_Tagging(),
Setup_Mod_Weighting()