On this page

Simulate survey datasets from a fit, with the fitted population (conditional) or with new process deviations (resample); each dataset is an input bundle ready to refit.

Usage

simulate_fit(
  fit,
  nsim = 1,
  seed = NULL,
  process = c("conditional", "resample"),
  preserve_missing = TRUE,
  allow_failed_fit = FALSE
)

Arguments

ArgumentDefaultDescription
fitrequired

An ACL or ALSCL fit with its report and its complete inputs and fitting settings, or a saved fit read with read_assessment().

nsim1

Positive integer number of simulated datasets.

seedNULL

Optional nonnegative integer seed. A given seed restores the random-number generator and state of the caller after the call; NULL draws from the current stream.

processc("conditional", "resample")

"conditional" keeps the fitted population and adds only observation errors; "resample" draws new recruitment, F and initial-number deviations at the fitted scalar parameter values. Letter case does not matter.

preserve_missingTRUE

Logical. TRUE keeps NA observations as NA and excluded zeros as zero; FALSE gives every cell a positive draw.

allow_failed_fitFALSE

Logical. FALSE (default) rejects a fit known to have failed its numerical checks; TRUE accepts it with a warning.

Value

simulations contains named replicates, each with x (an input bundle ready to fit), observations (length bin by time step) and truth; metadata records the process, the seed and random-number generator, the coordinates, the mask of the original observations, the numerical status of the source fit and parameter_uncertainty = "none". truth holds the years, the population quantities, F of the groups of the model (age classes for ACL, length bins for ALSCL), the scalar parameters, the process deviations and the expected index.

Details

The conditional mode keeps the fitted states and varies only the lognormal observation errors. The resample mode draws recruitment deviations from a stationary AR(1) process, F deviations from the fitted stationary AR(1) process that is separable over groups and time (over time only with F_structure = "year"), and new normal deviations of the initial log numbers at age in the form of the fit (structure$initial_deviations), accumulated over ages for "cumulative" (default) or one per age for "independent". The C++ population model then computes the trajectory without optimization. The process scales are marginal SDs. Both modes keep the scalar parameters, biology and survey catchability fixed and add no parameter uncertainty. The resample mode rejects a map that fixes or ties process deviations. A given seed restores the random-number state of the caller; NA and zero cells stay in place by default. A fit known to have failed needs allow_failed_fit = TRUE and gives a warning. Saved fits read with read_assessment() work too.

Each returned input bundle stores the fixed scalar values that the source fit used, including a mean_log_R derived from the data and then fixed, so a refit keeps these values when the observations change. Free parameters keep the starting-value settings of the source fit. For ALSCL, the conditional truth contains dev_log_N0, also after saving and reading; when the report has no dev_log_N0, it is NULL.

Additional details from R help

Both modes hold scalar parameters, biology and survey catchability fixed. Neither includes parameter-estimation uncertainty. In resample mode, recruitment follows a stationary AR(1), fishing mortality follows the fitted stationary separable group-by-time AR(1) (or one time series for F_structure = "year"), and the initial numbers at age have new independent normal deviations on the log scale in the form of the fit (structure$initial_deviations), accumulated over ages for "cumulative", the default, or one per age for "independent". The process scales are marginal SDs; AR(1) innovation SDs are the marginal SD multiplied by sqrt(1 - phi^2). Recruitment and F use exp(mean_log + deviation), without a lognormal mean correction.

Resampling evaluates the C++ population model of the package without optimization. Maps that fix or tie random effects are rejected in this mode, because the package does not draw from the conditional distribution of such processes; maps of scalar parameters are accepted. Conditional simulation accepts both. Observations are exp(Elog_index + normal error), so exp(Elog_index) is their conditional median, and expected_index = exp(Elog_index + sigma^2 / 2) is their conditional arithmetic mean. Numeric overflow or underflow to zero gives an error, so the distribution and the mask of the observations are never changed.

Each returned x keeps the fitting settings of the same model. The values of the fixed scalar parameters are written into parameters, including values that were derived from the source data, so a refit to other observations keeps these assumptions. The estimated scalar parameters keep their original starting values. The session settings output, ncores and silent are chosen when the bundle is fitted with run_acl(x) or run_alscl(x). The function does not refit the model (self_test() does) and computes no bootstrap intervals.

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
fit <- run_acl(YTF_example, silent = TRUE)
simulated <- simulate_fit(fit, nsim = 3, seed = 42, process = "resample")
refitted <- run_acl(simulated$simulations[[1]]$x, silent = TRUE)
simulated$simulations[[1]]$truth$SSB
Example figure
Example figure: simulate_fit(fit, nsim = 3, seed = 42, process = "resample")

See also

Search documentation