On this page

Simulate data sets from a fitted ACL or ALSCL model, refit the same model with the same settings to each, and report how well the estimates recover the values used to simulate them.

Usage

self_test(
  fit,
  nsim = 20,
  seed = NULL,
  process = c("conditional", "resample"),
  start = c("original", "estimates"),
  nstarts = NULL,
  ncores = 1,
  quantities = c("SSB", "Rec", "F"),
  F_summary = c("mean", "apical"),
  conf_level = 0.95,
  interval = c("lognormal", "wald"),
  preserve_missing = TRUE,
  silent = TRUE,
  save_fits = FALSE
)

Arguments

ArgumentDefaultDescription
fitrequired

An ACL or ALSCL fit with its complete inputs and fitting settings, or a saved fit read with read_assessment(); it must pass the numerical checks (fit$diagnostics$numerical_ok).

nsim20

Positive integer number of simulated datasets.

seedNULL

Nonnegative integer seed of the simulation, see simulate_fit(); the refits are deterministic, so a seed makes the whole self-test repeatable.

processc("conditional", "resample")

"conditional" keeps the fitted population and draws observation errors only; "resample" also draws recruitment, F and initial-number deviations from their estimated distribution. Letter case does not matter.

startc("original", "estimates")

"original" starts from the starting values of the source fit, with its number of starts; "estimates" starts at the values used to simulate (the estimates of the source fit). Letter case does not matter.

nstartsNULL

NULL uses the number of starts of the source fit; a positive integer sets it for every refit.

ncores1

Maximum number of socket workers; each fits one data set at a time, and the starts of a refit run one after another.

quantitiesc("SSB", "Rec", "F")

Time series to compare, from SSB, Rec, F, B and N. Letter case does not matter.

F_summaryc("mean", "apical")

Summary of F over ages (ACL) or length bins (ALSCL) at each time step, "mean" (default) for the unweighted mean or "apical" for the maximum, as in fit_scenarios(). Letter case does not matter.

conf_level0.95

Nominal confidence level of the intervals whose coverage is reported, strictly between zero and one.

intervalc("lognormal", "wald")

Form of the interval of a time series. "lognormal" (default) is exp(log(estimate) +/- z * SE / estimate), as in the plots and extract_estimates(); "wald" is estimate +/- z * SE. Letter case does not matter.

preserve_missingTRUE

Passed to simulate_fit(); keeps missing and zero survey cells as they are.

silentTRUE

Suppress fitting progress messages.

save_fitsFALSE

Keep the refits, without the TMB object, in the result.

Value

An alscl_self_test object with replicates (numerical checks, time, error and warnings of each refit), series and parameters (truth, estimate, standard error, interval, error, relative error and coverage for each replicate and quantity and time step, or parameter), by_year, series_summary and parameter_summary (median relative error, 10th and 90th percentiles, median absolute relative error and coverage over the refits that pass the checks), screen (the share that pass), failures, settings, simulation (the metadata of simulate_fit()) and fits. print() and summary() show the summaries; plot_self_test() draws the relative errors.

Details

With "conditional", the truth of every replicate is the population of the source fit; with "resample", each replicate has its own population, computed by the model from the new deviations, and the test also covers the estimated process variances. The truth of a scalar parameter is its estimate in the source fit, in both modes. In the conditional mode the deviations are the fitted values and their arithmetic mean need not be zero, but at the estimate the mean parameter of an AR(1) process (mean_log_F, mean_log_R) is close to a weighted mean of the fitted process in which the first and last time steps weigh more, and a refit that recovers the process recovers this weighted mean. The level of F and recruitment is measured by the time series, whose truth is the realized process. Parameters that can trade off with the deviations, for example init_Z with the initial deviations, are also better judged by the time series. Fixed parameters, natural mortality, survey catchability, growth and maturity are unchanged in both modes. Each refit uses the model, structure, map, bounds, fixed values and fixed inputs of the source fit. With "original", a refit that stops at a local optimum counts as an error, as it would with real data; "estimates" is faster but can hide local optima and parameters that the data do not determine. The relative error is (estimate - truth) / |truth|, so a positive value is an overestimate for any sign of the truth; it is undefined for a zero truth and large for a truth near zero (t0, or a correlation near zero), where error is the measure to read. Coverage is computed for series with standard errors (SSB, recruitment, total biomass and abundance, not the summary of F) and for the estimated parameters, with the interval of extract_parameters().

A self-test in which the estimates recover the truth shows that the model can estimate its parameters from data like these when its assumptions hold (Deroba et al. 2015). It says nothing about the bias from a wrong natural mortality rate, survey catchability or growth form; testing those needs simulations from an operating model with different assumptions (sim_model()). The number of workers does not change the results.

Additional details from R help

What is simulated

With process = "conditional" every data set keeps the fitted population (the estimated recruitment, fishing mortality and initial deviations) and only the observation error is drawn again, so the truth, the estimates of the source fit, is the same population in every replicate. This tests the observation model and the numerical behaviour of the estimation for that one population. With process = "resample" new recruitment, F and initial deviations are drawn from their estimated distribution (variances and correlations) before the observations are drawn, so each replicate has its own population, computed by the model, and the truth of a time series differs between replicates. This also tests whether the variances of the process deviations can be estimated. Fixed parameters, the natural mortality rate, survey catchability, growth and maturity stay as in the source fit in both modes. Relative errors are computed against the truth of each replicate.

Truth of the scalar parameters

The truth of a scalar parameter is its estimate in the source fit, in both modes. In conditional mode the deviations are the fitted values, not a draw from their distribution, and their arithmetic mean need not be zero. The truth of mean_log_F (log fishing mortality rate) and mean_log_R (log recruitment) is still the source estimate, because at the estimate the mean parameter of an AR(1) process is close to the weighted mean of the fitted process that the AR(1) density implies, in which the first and last time steps (and groups) weigh more, not its arithmetic mean, and a refit that recovers the process recovers this weighted mean. The level of F and recruitment is measured by the time series, whose truth is the realized process. Parameters that can trade off with the deviations, for example init_Z with the mean of the initial deviations, are also better judged by the time series.

Refits

Each refit uses the model, structure, map, bounds, fixed values and fixed inputs of the source fit, from its recipe. With start = "original" it also uses the starting values and the number of starts of the source fit, so that the refits search for the optimum as the source fit did; a refit that stops at a local optimum then counts as an error of the estimates, as it would with real data. With start = "estimates" each refit starts at the values used to simulate. This is the usual setting of a self-test and is faster, but it can hide local optima and parameters that the data do not determine, because the optimizer starts near the answer. Comparing the two shows whether the starting values matter.

Summaries

Bias is the median relative error over the replicates that pass the numerical checks, as in Stock and Miller (2021), and the median absolute relative error measures the size of the errors. Refits that fail the checks stay in replicates, series and parameters but not in the summaries; read screen and failures with them. Coverage is the share of the intervals that contain the truth, for the series with standard errors (SSB, recruitment, total biomass and abundance; not the summary of F) and for the scalar parameters, whose interval is that of extract_parameters(). A relative error is not defined when the truth is zero and is large when the truth is near zero, as for t0 or a correlation near zero; error gives the absolute error.

Interpretation

A self-test in which the estimates recover the truth shows that the model can estimate its parameters from data like these when its assumptions hold (Deroba et al. 2015). It says nothing about the bias from a wrong natural mortality rate, survey catchability or growth form, which for fits to a survey index alone are the main sources of error; testing those needs simulations from an operating model with different assumptions (sim_model()).

Replicates run on socket workers when ncores is greater than 1, as in fit_scenarios(); the results are the same for any number of workers. Reported studies commonly use 100 data sets (Deroba et al. 2015).

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
a <- run_acl(x, silent = TRUE)
b <- run_alscl(x, silent = TRUE)
st <- self_test(a, nsim = 5, seed = 1)
st
head(st$by_year)
summary(st)$parameter_summary
Example figure
Example figure: plot_self_test(self_test(a, nsim = 5, seed = 20261101))

See also

Search documentation