Run a simulation self-test of a fitted RTMB estimation model
simulation_self_test.RdValidates model performance by: (1) generating n_sims new datasets
from the fitted model parameters using Simulate_Pop_Static,
(2) re-fitting the estimation model to each simulated dataset, and (3)
storing user-specified report quantities for comparison against true values.
Supports sequential or parallel execution via
future/future.apply. Likelihood weights from the original fit
are propagated into the simulation (e.g., ISS scaled by
Wt_FishAgeComps; ObsSrvIdx_SE divided by
sqrt(Wt_SrvIdx)); all weights are reset to 1 when re-fitting.
Failed replicates are silently stored as NA.
Usage
simulation_self_test(
data,
parameters,
mapping,
random,
rep,
sd_rep,
n_sims,
newton_loops = 3,
do_sdrep = FALSE,
do_par = FALSE,
n_cores = NULL,
output_path = NULL,
what = c("SSB", "Rec")
)Arguments
- data
Named list of model data from a fitted RTMB object (
$data).- parameters
Named list of fitted parameter values (
$paror equivalent).- mapping
Named list of parameter factor maps (
$map).- random
Character vector of random effect names passed to RTMB.
- rep
Named list of report values from the fitted model (
obj$rep).- sd_rep
sdreportobject from the fitted model, used to extract optimised parameter values in list format viaget_optim_param_list.- n_sims
Integer. Number of simulation replicates.
- newton_loops
Integer. Number of Newton refinement steps applied during re-fitting. Default
3.- do_sdrep
Logical. Whether to compute
sdreportfor each fitted replicate. Results stored as$sd_repin the output list; failedsdreportcalls stored asNA. DefaultFALSE.- do_par
Logical. Whether to run replicates in parallel via
future::multisession. DefaultFALSE.- n_cores
Integer. Number of parallel workers. If
NULL(default),parallel::detectCores() - 1is used.- output_path
Character string. Path to save the simulated dataset RDS file. Passed to
Simulate_Pop_Static. DefaultNULL.- what
Character vector. Names of report elements (keys of
rep) to extract and store from each replicate. An error is raised if any name is not found inrep. Defaultc("SSB", "Rec").
Value
Named list with one element per entry in what, each an
array with the last dimension indexing simulation replicates (via
simplify2array). If do_sdrep = TRUE, an additional element
"sd_rep" contains a list of sdreport objects (or NA
for failed replicates).