On this page

Convert one simulated replicate from sim_data() to the three tables that run_acl() and run_alscl() take.

Usage

simulation_to_tables(sm, pa = NULL, first_year = NULL)

Arguments

ArgumentDefaultDescription
smrequired

A simulated replicate, either the list returned by sim_data() or the sim.data object loaded from a sim_rep<id> file.

paNULL

Optional parameter list from initialize_params() that generated the replicate. It supplies len_mid, growth_step and first.year for a replicate that does not record them. Length-bin midpoints in pa must match those recorded in sm.

first_yearNULL

Optional first observation year. It replaces the years recorded in sm.

Value

A list with the data frames data.CatL (the survey index table), data.wgt (the weight table) and data.mat (the maturity table). Each has a LengthBin column followed by one column per model time step.

Details

Rows are length bins, labelled by the length-bin midpoints. Columns are the model time steps recorded in the replicate. sm is the list returned by sim_data() or the sim.data object loaded from a sim_rep<id> file. pa supplies len_mid, growth_step and first.year for a replicate that does not record them; its length-bin midpoints must match those recorded in sm.

The function stops when the dimensions of SN_at_len, weight or mat do not match the time and length coordinates, so rows are never recycled. sim_model(), sim_acl() and sim_alscl() apply the same conversion to saved replicates. To fit the tables, also pass len_border = sm$len_border and len_mid = sm$len_mid, as sim_model() does; otherwise the borders are placed halfway between the midpoints, which differs from the simulated bins when the bins have unequal widths (for example the krill preset). A fit also needs the recruitment age, the number of age classes, the natural mortality rate and the survey catchability settings.

Additional details from R help

The function stops when the dimensions of SN_at_len, weight or mat do not match the time and length coordinates, so rows are never recycled. sim_model, sim_acl and sim_alscl apply the same conversion to saved replicates.

Examples

Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.

Example setup
library(ALSCL)
pa <- initialize_params(species = "flatfish", nyear = 6, burn_in = 2)
sm <- sim_data(sim_cal(pa), pa, iter_range = 1, output_dir = tempdir())
tables <- simulation_to_tables(sm, pa)
names(tables)
dim(tables$data.CatL)

See also

Search documentation