Skip to contents

Rceattle normally reads input data from an Excel workbook with read_data(). This vignette builds the same data object in R as a named list, for simulated data (testing, MSE operating models), programmatic inputs (scenario loops, sensitivity analyses) or pipelines without Excel. A data object read from Excel has the same structure, so this also helps when editing one. build_data(.check = TRUE) (the default) validates the result, fit_mod() fits it, and write_data() exports it back to Excel.

To start from a workbook instead, write_template() writes a minimal single-species starter workbook to edit and read back with read_data():

write_template("my_data_template.xlsx")
dat <- read_data("my_data_template.xlsx")

The quick path: build_data()

build_data() takes only the blocks a model uses and default-fills the rest (via clean_data()), so a single-species model does not need the predation, growth, or empirical-selectivity blocks. It has three combinable entry points:

library(Rceattle)

# 1. Copy-and-edit an existing data object (a bundled dataset, a read_data()
#    result, or a combine_data() result):
dat <- build_data(base = BS2017SS, projyr = 2060)

The other two need your own workbook or blocks, so are shown but not run:

# 2. Read a workbook, then override a few blocks:
dat <- build_data(file = "GOA_pollock.xlsx",
                  fleet_control = fc)          # fc overrides the sheet

# 3. Assemble from named blocks (the rest are default-filled):
dat <- build_data(nspp = 1, styr = 1977, endyr = 2023,
                  fleet_control = fc, weight = wt, maturity = mat,
                  sex_ratio = sr, catch_data = catch, index_data = survey,
                  comp_data = ages)

build_data() checks each block name: a typo (maturty) or case-slip (Maturity) is caught with a suggestion, and legacy names (fsh_biom, srv_biom, wt, pmature, Pyrs) are mapped to their canonical names. Printing the result shows a specification tree rather than the raw list:

dat            # <Rceattle data>: dimensions -> fleets -> processes -> ...

Which inputs does my model need?

data_requirements() reports, for a given configuration, which blocks are Required, Optional (used if supplied, otherwise default-filled), or Ignored (the feature is off), under the conditions the fit-time validation enforces.

data_requirements(msmMode = 0)            # single-species: predation Ignored
data_requirements(msmMode = 1)            # multispecies: diet + bioenergetics Required
data_requirements(BS2017SS, msmMode = 0)  # preview an existing object as single-species

The conditional requirements it encodes:

Field Required when
comp_data (always optional)
caal_data any(growth_model > 0) (estimating growth)
emp_sel any fleet has Selectivity = "Fixed"
NByageFixed any(estDynamics > 0)
env_data env linkages / Ceq > 1
diet_data msmMode > 0
ration_data msmMode > 0
Bioenergetics scalars (Ceq, CA, CB, Tco, …) msmMode > 0

In single-species mode (msmMode = 0) you can omit the msmMode > 0 rows by leaving them unset.

Building the list by hand

The rest of this vignette assembles the list field by field: the structure build_data() wraps. Skip the sections you don’t need.

Setup

library(Rceattle)

# Core dimensions; these set the size of every downstream array.
nspp     <- 2   # number of species (or stocks)
nages    <- 10  # number of age bins (same for all species here)
nlengths <- 20  # number of length bins (for age-length keys / CAAL data)
nyrs     <- 30  # number of hindcast years
years    <- 1:nyrs

simData <- list()

1. Species / model controls

Scalars and vectors giving each species’ biological structure and which population model is used.

simData$nspp    <- nspp
simData$styr    <- 1       # first year of hindcast
simData$endyr   <- nyrs    # last year of hindcast
simData$projyr  <- nyrs + 10  # last year of the projection period

# Character labels shown in plots and output tables
simData$spnames <- paste0("Species", 1:nspp)

# nsex: 1 = combined-sex model (male and female treated as one group),
#        2 = sex-structured model (separate selectivity and mortality by sex)
simData$nsex    <- rep(1, nspp)

# Calendar month of spawning, used to compute the fraction-of-year weight
# applied to spawning stock biomass (e.g., 6 = mid-year spawning)
simData$spawn_month <- rep(6, nspp)

simData$nages   <- rep(nages, nspp)   # number of age classes per species
simData$minage  <- rep(1, nspp)       # minimum age (usually 1)
simData$nlengths <- rep(nlengths, nspp)

# estDynamics controls how population abundance is estimated:
#   0 = estimate population dynamics (standard statistical catch-at-age)
#   1 = fix N-at-age exactly to values in NByageFixed (e.g., external estimates)
#   2 = as 1, times a per-species scalar estimated if msmMode > 0
simData$estDynamics <- rep(0, nspp)

# Indices linking each species to its weight and growth datasets.
# Multiple weight schedules can exist (e.g., fleet-specific); these point to
# which one is used for total biomass (pop) and spawning biomass (ssb).
simData$pop_wt_index <- 1:nspp
simData$ssb_wt_index <- 1:nspp
simData$pop_age_transition_index <- rep(1, nspp)

# Length-weight relationship coefficients: W = alpha * L ^ beta.
# Used internally to convert length-based selectivity to weight when estimating growth.
simData$alpha_wt_len <- rep(0.00001, nspp)
simData$beta_wt_len  <- rep(3, nspp)

# Prior or initial standard deviation for log-recruitment deviations. Controls the
# strength of the recruitment penalty in penalized-likelihood mode.
simData$sigma_rec <- rep(1, nspp)

# Non-modeled ("other") prey biomass available to predators, read in
# multi-species mode. Too low forces predators to over-eat modeled prey; too
# high dilutes the predation signal.
simData$other_food <- rep(1e5, nspp)   # metric tons of non-modelled prey

2. Fleet control table

Each row defines one fleet (fishery or survey) and controls how it is modeled. Multiple fleets can target the same species.

# Fleet_type:
#   "Fishery", contributes catch and catch-at-age/length composition data
#   "Survey", contributes an abundance index and composition data
#   "Off", fleet is present in the data but excluded from the likelihood

# Selectivity options (Selectivity column), use the string name or integer code:
#   "Fixed"              (0), fixed at values in emp_sel; not estimated
#   "Logistic"           (1), two-parameter ascending logistic (a50, slope)
#   "NonParametric"      (2), freely estimated selectivity-at-age/length with smoothness penalty
#   "DoubleLogistic"     (3), ascending + descending dome-shaped logistic
#   "DescendingLogistic" (4), descending logistic only (declining with age)
#   "Hake"               (5), non-parametric selectivity à la Taylor et al. (2015; Pacific hake)
#   "2DAR1"              (6), 2D autoregressive random effects (bin × year)
#   "3DAR1"              (7), 3D autoregressive random effects (bin × year × cohort)
#   "DoubleNormal"       (8), Gaussian ascending/descending limbs blended at peak
#   "NonParametricPM"    (9), Ianelli non-parametric, ADMB AMAK penalty
#   "LogisticPM"        (11), AMAK logistic with multiplicative deviations
#   "NonParametricIntegrable" (13), deviations with a proper density (random_sel)
#   "DoubleNormalSS3"   (15), SS3 size pattern 24, six-parameter
#   (10, 12 and 14 are unused)
#
# Selectivity_dimension: "Age" or "Length"
#   Length-based selectivity requires an age-to-length transition matrix (see below).

# Catchability options (Catchability column), use the string name or integer code:
#   "Fixed"                (0), Q fixed at Catchability_init; not estimated
#   "Estimated"            (1), freely estimated on log scale
#   "Estimated-with-prior" (2), estimated with a lognormal prior (Catchability_init, Catchability_prior_sd)
#   "Analytical"           (3), closed-form maximum likelihood Q (Walters & Ludwig 1994 when lognormal)
#   "PowerEquation"        (4), NOT YET IMPLEMENTED; data_check() refuses it
#   "AnalyticalArith"      (7), arithmetic-mean analytical Q
#   "Environmental"        (5), mu_q + X * beta, where X is a covariate in env_data
#   "AR1"                  (6), refused by data_check(). Use a q
#                                  linkage with ar1(1 | Year) and observe = <column>
#   NA, not applicable (use for fisheries without CPUE)

# Comp_distribution / CAAL_distribution options:
#   "Multinomial", standard multinomial
#   "DirichletMultinomial", overdispersed; estimates a concentration parameter
#   "MultinomialAFSC", AFSC variant of multinomial (marginal age + length)

simData$fleet_control <- data.frame(
  Fleet_name  = paste0(c("Survey", "Fishery"),
                       rep(paste(" Species", 1:nspp), each = 2)),
  Fleet_code  = 1:(nspp * 2),       # unique integer ID per fleet
  Fleet_type  = rep(c("Survey", "Fishery"), nspp),
  Species     = rep(1:nspp, each = 2),
  Month       = 0,                   # 0 = not specified; read for comps and
                                     # weight-at-age when growth is estimated

  # Fleets with the same Selectivity_index share all selectivity parameters.
  Selectivity_index         = 1:(nspp * 2),
  Selectivity               = "Logistic",
  Selectivity_dimension     = "Age",
  N_sel_bins                = NA,    # used for NonParametric only
  Sel_curve_pen1            = NA,    # smoothness penalty (NonParametric)
  Sel_curve_pen2            = NA,
  # Time_varying_sel:
  #   0 / "Off" = time-invariant (default)
  #   1 / "IID" = penalized log-normal deviates (SD fixed at Time_varying_sel_sd
  #       unless random_sel = TRUE in fit_mod)
  #   2 / "AR1" = refused by data_check()
  #   3 / "Block" = time blocks (Selectivity_block column of index_data / catch_data)
  #   4 / "RandomWalk" = random walk
  #   5 / "RandomWalkAscending" = random walk on ascending portion of double logistic
  Time_varying_sel          = 0,
  Time_varying_sel_sd = 1,
  Age_first_selected        = 1,     # first age selected (absolute age); 0 below it
  Sel_norm_bin             = "Off", # "Max", "Off", or a bin to normalize at
  Sel_norm_bin_upper       = "Off", # "Off", or the top of a bin range
  # Two-sex models only: whether the normalization reference is pooled over the
  # sexes ("AcrossSexes", default, keeps relative sex selectivity) or taken per
  # sex ("WithinSex", both sexes reach 1, only the shape differs).
  Sel_norm_scope           = "AcrossSexes",

  # Composition likelihoods
  Comp_distribution = "Multinomial",
  Comp_weights = 1,                  # input effective sample size multiplier
  CAAL_distribution = "Multinomial",
  CAAL_weights = 1,

  # Index units and weight/growth linkage
  Observation_units     = 1,          # 1 = weight (mt), 2 = numbers
  Weight_index         = rep(1:nspp, each = 2),
  Age_transition_index = 1,

  # Catchability_index links fleets that share the same catchability parameter.
  Catchability_index              = 1:(nspp * 2),
  Catchability         = rep(c("Estimated", NA), nspp),
  Catchability_init              = rep(c(1,   NA), nspp),
  Catchability_prior_sd           = rep(c(0.2, NA), nspp),
  # Time_varying_q:
  #   0 / "Off" = time-invariant
  #   1 / "IID" = penalized log-normal deviates (SD fixed at Time_varying_q_sd
  #       unless random_q = TRUE in fit_mod)
  #   2 / "AR1" = refused by data_check()
  #   3 / "Block" = time blocks
  #   4 / "RandomWalk" = random walk
  Time_varying_q          = rep(c(0, NA), nspp),
  Time_varying_q_sd = rep(c(1, NA), nspp),

  # Estimate_index_sd:
  #   0 = fix at Log_sd from index_data
  #   1 = estimate a single SD
  #   2 = analytical sigma (Walters & Ludwig 1994)
  Estimate_index_sd  = rep(c(0,  NA), nspp),
  Index_sd     = rep(c(1,  NA), nspp),

  # Estimate_catch_sd:
  #   0 = fix at Log_sd from catch_data (treats catch as known)
  #   1 = estimate
  #   2 = analytical sigma (Walters & Ludwig 1994); concentrates the sd out of
  #       the catch likelihood, so catch stops pinning F as tightly
  Estimate_catch_sd  = rep(c(NA, 0),  nspp),
  Catch_sd     = rep(c(NA, 1),  nspp),

  # Proj_F_proportion: how future F is distributed across fishery fleets per species.
  # Must sum to 1 across fishery fleets for each species. NA for surveys.
  Proj_F_proportion = rep(c(NA, 1), nspp)
)

3. Survey index data

One row per survey fleet-year. Observation is the index on the natural scale (mt, or thousands of fish if Observation_units = 2), not a log, and data_check() requires it to be positive. A negative Year predicts the index without including it in the likelihood.

simData$index_data <- data.frame(
  Fleet_name        = rep(paste("Survey Species", 1:nspp), each = nyrs),
  Fleet_code        = rep(seq(1, nspp * 2, by = 2), each = nyrs),
  Species           = rep(1:nspp, each = nyrs),
  Year              = rep(years, nspp),
  # Month the index prediction uses: 0 = start of year, before any mortality;
  # 6 = mid-year. A mid-year survey left at 0 is predicted 10.5% high at Z = 0.2.
  Month             = 0,
  # Selectivity_block: integer index into the selectivity/Q parameter block.
  # Used when Time_varying_sel or Time_varying_q = 3 (time blocks).
  Selectivity_block = 1,
  Observation       = rlnorm(nyrs * nspp, log(5e5), 0.2), # natural scale (mt)
  Log_sd            = 0.1                   # observation SE on the log scale
)

4. Catch data

One row per fishery fleet-year. Log_sd is typically set small (0.01–0.05) when catch is treated as known; increase it if catch is highly uncertain.

simData$catch_data <- data.frame(
  Fleet_name        = rep(paste("Fishery Species", 1:nspp), each = nyrs),
  Fleet_code        = rep(seq(2, nspp * 2, by = 2), each = nyrs),
  Species           = rep(1:nspp, each = nyrs),
  Year              = rep(years, nspp),
  Month             = 0,
  Selectivity_block = 1,
  Catch             = abs(rnorm(nyrs * nspp)),  # replace with real catch (mt)
  Log_sd            = 0.05
)

5. Composition data (optional)

Age comps (Age0_Length1 = 0) or length comps (1). Sex = 0 for combined sex, 1 for females, 2 for males, 3 for joint female+male. Composition columns (Comp_1, Comp_2, …) can be raw counts or proportions; Rceattle normalizes internally.

With no composition data, leave simData$comp_data unset; clean_data() fills it with an empty data.frame.

comp_matrix <- matrix(abs(rnorm(nyrs * nspp * nages * 2)),
                      nrow = nyrs * nspp * 2, ncol = nages)
colnames(comp_matrix) <- paste0("Comp_", 1:nages)

simData$comp_data <- cbind(
  data.frame(
    Fleet_name   = c(rep(paste("Survey Species",  1:nspp), each = nyrs),
                     rep(paste("Fishery Species", 1:nspp), each = nyrs)),
    Fleet_code   = rep(c(seq(1, nspp * 2, 2), seq(2, nspp * 2, 2)), each = nyrs),
    Species      = c(rep(1:nspp, each = nyrs), rep(1:nspp, each = nyrs)),
    Sex          = 0,
    Age0_Length1 = 0,
    Year         = rep(years, 2 * nspp),
    Month        = 0,
    Sample_size  = 200
  ),
  comp_matrix
)

6. Conditional age-at-length (CAAL) data (optional)

CAAL data are observed age frequencies within each length bin, one row per fleet-sex-year-length bin. caal_data is required when growth is estimated internally (any(growth_model > 0); see ?build_growth and vignette("growth-estimation")); otherwise it can be omitted.

caal_matrix <- matrix(abs(rnorm(nyrs * nspp * nages * 2 * nlengths)),
                      nrow = nyrs * nspp * 2 * nlengths, ncol = nages)
colnames(caal_matrix) <- paste0("CAAL_", 1:nages)

simData$caal_data <- cbind(
  data.frame(
    Fleet_name  = c(rep(paste("Survey Species",  1:nspp), each = nyrs * nlengths),
                    rep(paste("Fishery Species", 1:nspp), each = nyrs * nlengths)),
    Fleet_code  = rep(c(seq(1, nspp * 2, 2), seq(2, nspp * 2, 2)),
                      each = nyrs * nlengths),
    Species     = c(rep(1:nspp, each = nyrs * nlengths),
                    rep(1:nspp, each = nyrs * nlengths)),
    Sex         = 0,
    Year        = rep(years, 2 * nspp * nlengths),
    Length      = rep(1:nlengths, 2 * nspp * nyrs),
    Sample_size = 200
  ),
  caal_matrix
)

7. Biological inputs

Age-to-length transition matrix

The probability that a fish of age a is observed in length bin l. Required when fitting length compositions or estimating growth internally. Each row must sum to 1. The placeholder below is an identity matrix (age a maps exactly to length bin a); replace it with an empirical or model-based growth matrix.

age_trans_list <- lapply(1:nspp, function(sp) {
  tmp <- matrix(0, nrow = nages, ncol = nlengths)
  diag(tmp[1:min(nages, nlengths), 1:min(nages, nlengths)]) <- 1
  colnames(tmp) <- paste0("Length_", 1:nlengths)
  cbind(data.frame(Age_transition_name  = paste("Species", sp),
                   Age_transition_index = sp,
                   Species              = sp,
                   Sex                  = 0,
                   Age                  = 1:nages), tmp)
})
simData$age_trans_matrix <- do.call(rbind, age_trans_list)

Ageing error matrix

The probability that a fish of true age t is read as observed age o. The identity matrix below means no ageing error; a matrix from, e.g., the AgeingError package can be substituted.

age_error_list <- lapply(1:nspp, function(sp) {
  tmp <- as.data.frame(diag(1, nages))
  colnames(tmp) <- paste0("Obs_age", 1:nages)
  cbind(data.frame(Species = sp, True_age = 1:nages), tmp)
})
simData$age_error <- do.call(rbind, age_error_list)

Weight-at-age

Mean weight (kg) at each age. Year = 0 applies the same schedule to all years (time-invariant); rows for different years give time-varying weight-at-age.

weight_matrix <- matrix((1:nages / nages)^3 * 0.01,
                        nrow = nspp, ncol = nages, byrow = TRUE)
colnames(weight_matrix) <- paste0("Age", 1:nages)

simData$weight <- cbind(
  data.frame(Wt_name  = paste("Species", 1:nspp),
             Wt_index = 1:nspp,
             Species  = 1:nspp,
             Sex      = 0,
             Year     = 0),   # Year = 0 → time-invariant
  weight_matrix
)

Maturity-at-age

Proportion mature at each age (0 to 1), used to compute SSB. For sex-structured models (nsex = 2) it is the proportion of females that are mature.

mat_matrix <- matrix(1, nrow = nspp, ncol = nages)
colnames(mat_matrix) <- paste0("Age", 1:nages)
simData$maturity <- cbind(data.frame(Species = 1:nspp), mat_matrix)

Sex ratio at age

Proportion female at each age. Used in combined-sex models (nsex = 1) to weight spawning biomass contributions. In two-sex models (nsex = 2) this is the proportion female at recruitment.

sex_matrix <- matrix(0.5, nrow = nspp, ncol = nages)
colnames(sex_matrix) <- paste0("Age", 1:nages)
simData$sex_ratio <- cbind(data.frame(Species = 1:nspp), sex_matrix)

Where species have different numbers of age bins, maturity and sex_ratio are as wide as the longest-lived species, and each row must be filled across its own species’ nages. Columns past that are padding and may be NA.

A maturity gap leaves SSB NA for any species, and a sex_ratio gap does the same for a one-sex species. On a two-sex species sex_ratio is read only at the first age (minage), to split recruitment by sex. data_check() names the table, the species and the missing ages.

Rows are read by position, so row i must be species i.

Fixed selectivity (optional)

Selectivity-at-age for fleets whose selectivity is fixed (not estimated). Required when any fleet has Selectivity = "Fixed"; skip it if every fleet estimates its own selectivity, as here. The table looks like:

# One fleet whose selectivity is fixed at the supplied row of values
emp_sel <- data.frame(
  Fleet_name = "Survey Species 1",
  Fleet_code = 1,
  Species    = 1,
  Sex        = 0,
  Year       = 0,                       # 0 = applied to every year
  t(matrix(c(0.1, 0.5, 1, rep(1, nages - 3)), ncol = 1,
           dimnames = list(paste0("Comp_", 1:nages), NULL)))
)
simData$emp_sel <- NULL

Fixed numbers-at-age (optional)

Required when any(estDynamics > 0):

  • 1 = numbers-at-age fixed exactly to these values
  • 2 = as 1, times a per-species scalar estimated if msmMode > 0

Skip it when estimating population dynamics (the default estDynamics = 0). The table has columns Species_name, Species, Sex, Year, then Age1 ... Age<nages> for the fixed numbers-at-age.

Natural mortality (M1 base)

Residual natural mortality-at-age, excluding predation. In single-species mode M = M1; in multi-species mode M = M1 + M2, where M2 is predation mortality estimated from the bioenergetics model. When switching to multi-species mode, reduce M1 accordingly (see vignette("single-vs-multispecies")).

m_matrix <- matrix(0.2, nrow = nspp, ncol = nages)
colnames(m_matrix) <- paste0("Age", 1:nages)
simData$M1_base <- cbind(data.frame(Species = 1:nspp, Sex = 0), m_matrix)

M1 can also be estimated rather than fixed. See ?build_M1 for options including estimating a single scalar, an age-specific vector, or a temperature-dependent function.

Environmental covariate data (optional)

An optional time series for environmental effects on recruitment, M1, catchability or growth. A linkage formula names its covariate (~ temp); a linkage refuses a fixed-effect covariate with a missing year, and gives years after the last row a zero offset; the switch-based paths (Catchability = 5, bioenergetics Cindex) read columns by position after Year and fill missing years with the column mean.

Skip this if no environmental covariates are used: clean_data() falls back to a Year-only data.frame with no indices, and validation complains only when a feature needs one (env-q catchability, a consumption equation that reads a temperature, Ceq 1, 2 or 3, or any env linkage). With no index to read, consumption uses the constant fT = 1 of Ceq = 4: an error under msmMode > 0, where consumption drives predation mortality, and a warning under single-species, where it reaches only the reported ration.

simData$env_data <- data.frame(
  Year    = 1:nyrs,
  EnvData = 1       # constant = no environmental effect (placeholder)
)

8. Multi-species bioenergetics parameters (optional in single-species mode)

These parameters govern the Wisconsin bioenergetics model used to compute predation mortality (M2) in multi-species mode. In single-species mode they reach only the reported ration and consumption_at_age, never the objective, and can be omitted; Rceattle fills any missing scalars with safe defaults (Ceq = 4, the constant form that reads no environmental index).

In multi-species mode (msmMode > 0) all of Ceq, Cindex, Pvalue, fday, CA, CB, Qc, Tco, Tcm, Tcl, CK1, CK4 must be supplied as length-nspp vectors, and data_check() lists any that are missing or wrong-length. diet_data and ration_data are also required.

See “Consumption” in vignette("model-parameterizations") for each parameter.

# Ceq: consumption (bioenergetics) equation form for each species:
#   1 = Exponential (Stewart et al. 1983)
#   2 = Warm-water temperature dependence (Kitchell et al. 1977)
#   3 = Cool/cold-water temperature dependence (Thornton & Lessem 1978)
#   4 = bypass bioenergetics; ration_data is annual ration per predator (kg)
simData$Ceq    <- rep(4,  nspp)

simData$Cindex <- rep(1,  nspp)   # which env_data covariate column drives it, counting from 1
simData$Pvalue <- rep(1,  nspp)   # proportion of maximum consumption realised
simData$fday   <- rep(1,  nspp)   # foraging days per year

# Wisconsin model coefficients (CA, CB) and temperature dependence parameters
simData$CA  <- rep(1,  nspp)
simData$CB  <- rep(-1, nspp)
simData$Qc  <- rep(1,  nspp)
simData$Tco <- rep(1,  nspp)
simData$Tcm <- rep(1,  nspp)
simData$Tcl <- rep(1,  nspp)
simData$CK1 <- rep(1,  nspp)
simData$CK4 <- rep(1,  nspp)

# Diet composition likelihood for each predator species
# 0 = Multinomial, 1 = Dirichlet-multinomial
simData$Diet_distribution      <- rep(0, nspp)
simData$Diet_comp_weights <- rep(1, nspp)

# Ration data: observed mean ration-at-age from bioenergetics studies.
# Required when msmMode > 0; skip in single-species mode.
# Columns: Species, Sex, Year, Age1, ..., Age<nages>.

# Diet composition data: observed stomach content proportions (predator-prey pairs).
# Required when msmMode > 0; skip in single-species mode.
# Columns: Pred, Prey, Pred_sex, Prey_sex, Pred_age, Prey_age, Year,
# Sample_size, Stomach_proportion_by_weight.

9. Validate and fit

plot_data() plots a timeline of the data.

plot_data(simData)
# Key fit_mod() arguments:
#
# estimateMode: 0 = full fit (hindcast + projection)
#               1 = hindcast only
#               2 = projection only (fix parameters, run HCR)
#               3 = build the objective only (no optimisation), useful for debugging
#
# msmMode:      0 = single-species, 1 = Type II MSVPA, 2 = Type III MSVPA
#
# initMode:     0 = freely estimated initial N-at-age
#               1 = equilibrium, F_init = 0, no init deviations
#               2 = equilibrium, F_init = 0, with init deviations (default)
#               3 = non-equilibrium: F_init estimated, init devs included
#               4 = non-equilibrium: F_init scales R0
#               5 = equilibrium, F_init = 0, seeded by R_init displaced by the
#                   year-1 recruitment deviation, no init deviations
#               6 = non-equilibrium: F_init weighted by fishery selectivity at
#                   age (SS3's InitF convention); the only mode that reads an
#                   initial equilibrium catch at styr - 1
#
# phase:        TRUE = use parameter phasing for improved convergence (recommended)

sim_run <- fit_mod(
  data_list    = simData,
  # simData carries caal_data, which is predicted from growth, so it needs a
  # parametric growth model.
  growthFun    = build_growth(fun = "vonBertalanffy"),
  estimateMode = 3,    # change to 0 for a real fit
  msmMode      = 0,
  initMode     = 2,
  random_rec   = FALSE,
  fit_control = fit_control(
    phase        = TRUE,
    verbose      = 1))

10. Export back to Excel (optional)

write_data() exports the data list to an Excel workbook, to edit and re-read with read_data().

write_data(simData, file = tempfile(fileext = ".xlsx"))

11. Persist and share a run configuration (optional)

write_data() stores the data; the model structure and estimation controls live in the fit_mod() call (or in a model_config() slot). save_config() writes that run configuration (the model_config() structure plus the estimation controls and fit_control() bundle) to a YAML file that diffs cleanly between runs and can be archived with the data. load_config() reads it back, and fit_mod(config = ...) reproduces the fit, filling only the arguments you did not pass. The structure is overlaid field by field: a field the config leaves at its default keeps what the data object holds (so linkages attached with build_data(model_config = ) survive), and a field both set differently is taken from the config, with a warning:

cfg_file <- tempfile(fileext = ".yaml")
save_config(model_config(msmMode = 1, initMode = "OffsetEquilibrium"), cfg_file)
cfg <- load_config(cfg_file)
# fit_mod(simData, config = cfg)   # applies the stored structure + controls

Every fit also records the configuration it used in fit$run_config, so save_config(fit, "run.yaml") archives exactly what produced a result.

References

  • Kitchell, J.F., Stewart, D.J., Weininger, D. (1977). Applications of a bioenergetics model to yellow perch (Perca flavescens) and walleye (Stizostedion vitreum vitreum). Journal of the Fisheries Research Board of Canada, 34, 1922-1935.
  • Stewart, D.J., Weininger, D., Rottiers, D.V., Edsall, T.A. (1983). An energetics model for lake trout, Salvelinus namaycush: application to the Lake Michigan population. Canadian Journal of Fisheries and Aquatic Sciences, 40, 681-698.
  • Taylor, I.G., Grandin, C., Hicks, A.C., Taylor, N., Cox, S. (2015). Status of the Pacific hake (whiting) stock in U.S. and Canadian waters in 2015. Joint Technical Committee of the U.S. and Canada Pacific Hake/Whiting Agreement; National Marine Fisheries Service; Fisheries and Oceans Canada.
  • Thornton, K.W., Lessem, A.S. (1978). A temperature algorithm for modifying biological rates. Transactions of the American Fisheries Society, 107, 284-287.
  • Walters, C., Ludwig, D. (1994). Calculation of Bayes posterior probability distributions for key population parameters. Canadian Journal of Fisheries and Aquatic Sciences, 51, 713-722.