fit_scenarios()
View source ↗On this page
Fit one model under several named sets of assumptions to the same observations and collect the status and estimates of each scenario, serially or on socket workers.
Usage
fit_scenarios(
x,
scenarios,
model = c("acl", "alscl"),
ncores = 1,
F_summary = c("mean", "apical"),
...
)
Arguments
| Argument | Default | Description |
|---|---|---|
x | required | An input bundle accepted by |
scenarios | required | A nonempty named list; each element is a named list of fitting arguments that replace the common settings (a |
model | c("acl", "alscl") | Character. Model to fit, "acl" (default) or "alscl". Letter case does not matter. |
ncores | 1 | Maximum number of socket workers; each scenario is fitted by one worker. With ncores greater than 1 each worker computes standard errors on one core, and with ncores = 1 the standard errors use the session setting of |
F_summary | c("mean", "apical") | "mean" (default) gives the unweighted mean of F over age classes (ACL) or length bins (ALSCL) in each time step, and "apical" the maximum. F stays a rate per model time step. Letter case does not matter. |
... | … | Fitting arguments common to all scenarios, applied before the settings of each scenario. A |
Value
A list with fits (one fit per scenario without the TMB object, or an error record of class alscl_fit_error), settings (the arguments of each fit), status (one row per scenario with run time, process ID, error, warnings and numerical checks), elapsed (run time of the whole batch), estimates (a long table of SSB, Rec and F by scenario and time step, with the F summary and numerical_ok), model, F_summary and workers (the number of socket workers used).
Details
Warnings are recorded in status, and scenarios that fail the numerical checks stay in status and estimates; the scenarios are not ranked. Each scenario runs the nstarts of the bundle or of the call, or one start when neither sets it, as in hindcast_model() and retro_model(). The fits do not hold the TMB object; refit_model() fits a scenario again when one is needed. An interrupted call cannot be resumed.
Additional details from R help
Each scenario is fitted by one worker. When scenarios run on parallel workers (ncores greater than 1), each worker computes standard errors on one core. With ncores = 1 the standard errors use the session setting of alscl_speed(); the results are identical. Each scenario runs the nstarts of the bundle or of the call; when neither sets it, one start is used, the rule of hindcast_model() and retro_model(). Warnings are recorded in status. The fits do not keep the TMB object of the session, also when they run one after the other; use refit_model() when the TMB object is needed.
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)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
x <- YTF_example
z <- fit_scenarios(x, list(reference = list(), low_M = list(M = 0.15),
common_F = list(F_structure = "year")), model = "alscl", ncores = 2,
F_summary = "mean", silent = TRUE)
z$status
z$estimates

fit_scenarios(x, list(reference = list(), low_M = list(M = 0.15), high_M = list(M = 0.25)), model = "acl")