
Prepare weight composition data for model input
prep_wf_data.RdTransforms a pivoted wide-format weight-frequency data frame into model-ready arrays and vectors that get_weight_like() expects. Also precomputes the rebinning matrix for converting predicted length compositions to weight compositions.
Usage
prep_wf_data(
data,
wf_wide,
wf_keep_fisheries = NULL,
wf_switch = 1L,
wf_minbin = NULL,
wf_maxbin = NULL,
wf_var_adjust = NULL,
wf_cap = NULL
)Arguments
- data
list containing at minimum: lw_a, lw_b, len_bin_start, len_bin_width, n_len, n_fishery, and the weight bin scalars wt_bin_start, wt_bin_width, n_wt.
- wf_wide
data.frame in wide format: columns fishery, year, month, ts plus one numeric column per weight bin (named by bin value).
- wf_keep_fisheries
integer vector of fishery indices to retain (NULL = keep all).
- wf_switch
integer likelihood type (1=multinomial, 2=Dirichlet, 3=Dirichlet-multinomial). Default 1L.
- wf_minbin
integer vector (length n_fishery) min weight bin index. Defaults to rep(1L, n_fishery).
- wf_maxbin
integer vector (length n_fishery) max weight bin index. Defaults to rep(n_wt, n_fishery).
- wf_var_adjust
numeric vector (length n_fishery) variance adjustment divisors. Defaults to rep(1, n_fishery).
- wf_cap
positive integer (or
NULL). When supplied, each effective sample size is capped: \(n_i = \min(n_i, \text{wf\_cap})\). Applied after proportions are computed so that observed compositions are unaffected. DefaultNULL(no cap). This is a Multifan-CL legacy feature.
Value
data list with the following weight composition elements appended:
wf_switchPassed through from the argument.
wt_lower,wt_upper,wt_midWeight bin boundary and midpoint vectors derived from the scalar inputs.
wt_bin_edgesWeight bin boundary vector (length n_wt + 1).
wf_rebin_matrixPrecomputed rebinning matrix (n_wt x n_len) for converting predicted length compositions to weight compositions.
n_wfTotal number of WF observation rows.
wf_obs_inMatrix of observed proportions (n_wf x n_wt).
wf_obs_flatFlattened numeric vector of counts (for multinomial,
wf_switch = 1).wf_obs_intsFlattened integer vector of rounded counts (for Dirichlet-multinomial,
wf_switch = 3).wf_obs_propFlattened numeric vector of normalised proportions (for Dirichlet,
wf_switch = 2).wf_nNumeric vector of sample sizes per observation row.
wf_fisheryInteger vector of fishery index per observation row.
wf_fishery_fInteger vector of unique fishery indices with WF data.
wf_n_fInteger vector of observation counts per fishery.
wf_yearInteger vector of model timestep per observation row.
wf_minbin,wf_maxbinPassed through from arguments.
wf_var_adjustPassed through from argument; numeric vector
[n_fishery]of variance-adjustment divisors applied towf_n.