Bundle the optimizer / sdreport / phasing controls for fit_mod()
Source: R/0-fit_control.R
fit_control.RdCollects the optimizer and reporting settings into one object, so a call to
fit_mod() stays about the model rather than how it is fit. Pass the result
through fit_mod()'s fit_control argument, where it overrides the
equivalent individual arguments, which are kept for back-compatibility.
Usage
fit_control(
bias.correct = FALSE,
getsd = TRUE,
getJointPrecision = TRUE,
getReportCovariance = FALSE,
projection_uncertainty = FALSE,
selectivity_se = FALSE,
comp_offset = NULL,
bias_adjust_obs = TRUE,
bias_adjust_proc = TRUE,
use_gradient = TRUE,
rel_tol = 1,
loopnum = 5,
newtonsteps = 0,
phase = FALSE,
TMBfilename = NULL,
verbose = 1,
nlminb_control = list(eval.max = 1e+09, iter.max = 1e+09, trace = 0)
)Arguments
- bias.correct
Logical (
FALSEby default): apply TMB's epsilon bias correction (Thorson and Kristensen 2016) inTMB::sdreport(), as distinct from the lognormal bias adjustment ofbias_adjust_obs/bias_adjust_proc.- getsd
logical. Run
TMB::sdreport()after optimization. DefaultTRUE.- getJointPrecision
logical. Return the full Hessian of fixed and random effects. Default
TRUE.- getReportCovariance
logical. Return the variance-covariance of
ADREPORTvariables. DefaultFALSE.- projection_uncertainty
logical. Carry hindcast parameter uncertainty into an HCR projection, by refitting with the hindcast and biological-reference-point parameters turned on. Default
FALSEfor speed.- selectivity_se
logical. Also return a standard error for log selectivity-at-age. Default
FALSE; see Details.- comp_offset
Numeric or
NULL. Small proportion added to the observed and predicted composition and CAAL bins before the multinomial / Dirichlet-multinomial likelihood, so an empty bin is notlog(0). Stored ondata_list, so the fitted likelihood, the OSA observation vector and any internal refit share it.NULL(default) inheritsdata_list$comp_offsetif set, else1e-5. Diet compositions take the same offset.- bias_adjust_obs
logical, default
TRUE. Apply a bias adjustment (mean - sd^2/2) to lognormal data likelihoods.- bias_adjust_proc
logical, default
TRUE. Shift lognormal process likelihoods, lognormal priors and the Ianelli stock-recruit penalty by-sd^2/2on the log scale, making each prior value or curve a mean rather than a median. A value between 0 and 1 scales the shift.- use_gradient
logical. Use the analytic gradient during phasing. Default
TRUE.- rel_tol
Numeric tolerance for flagging a discontinuous likelihood, comparing
nlminb's objective with a fresh evaluation at the estimates (undernewtonsteps > 0the reported objective is that evaluation, so nothing is flagged). Default1.- loopnum
Integer. Times to restart optimization;
3sometimes reaches a lower final gradient than1. Default5.- newtonsteps
Integer. Extra unconstrained Newton steps after optimization, an alternative to
loopnum; a singular Hessian (usually a parameter the data do not inform) ends them with a warning, and with TMBhelper installed the fit is redone without Newton steps. Default0.- phase
TRUE/FALSE, or a list of parameter names with their phases. DefaultFALSE.- TMBfilename
Optional path (without
.cpp) to an alternate TMB template for development. DefaultNULLuses the bundledceattle.- verbose
0silent,1model-fit updates,2model-fit and TMB progress. Default1.- nlminb_control
Control parameters passed to
stats::nlminb(); see?nlminb. Defaultlist(eval.max = 1e9, iter.max = 1e9, trace = 0).
Selectivity standard errors
selectivity_se needs getsd = TRUE, and reports the error belonging to
whichever sdreport the fit ends on. Under estimateMode = "Estimate" with
an HCR that re-optimizes, that is the projection fit, where every
selectivity parameter is mapped off, so every error comes back exactly 0;
"Projection" estimates no selectivity at all. Use "Hindcast", or
"Estimate" with projection_uncertainty = TRUE, to get an error from a fit
that estimated the curve. fit_mod() warns in each of these cases.
It is off by default because the delta method forms a Jacobian of every
reported value against every parameter, so the cost is their product: on
Atka2022, 1,012 values against 584 parameters. The error is on the log
scale rather than the logit, because the non-parametric forms normalize to
mean selectivity 1 instead of a maximum of 1 – 58% of Atka2022's
sel_at_age exceeds 1, up to 3.06 – so a logit is undefined over most of
the array.
Rows cover estimated, age-based lead fleets only, starting at each fleet's
first selected age (Age_first_selected, or a deprecated Bin_first_selected).
Four kinds of cell are a structural zero (a Fixed fleet's empirical curve, a
length-based fleet's growth-matrix projection, an age below the first selected
age, and array padding), and one log(0) = -Inf on the tape turns every quantity in the
sdreport to NaN, biomass and SSB included. All four are identified from
the data, so the reported set never depends on a parameter value, and a value
that underflows to zero is floored so it cannot reintroduce the -Inf. See
plot_selectivity(), which draws the interval.