Bundle the optimizer / sdreport / phasing controls for fit_mod()
Source: R/0-fit_control.R
fit_control.Rdfit_mod() carries roughly a dozen optimizer- and reporting-related
arguments (bias.correct, getsd, loopnum, newtonsteps, ...).
That is a lot of surface area when the user mostly cares about
"what model am I fitting" rather than "how is it being fit."
fit_control() collects those knobs into a single object so calls
to fit_mod() can stay focused on the model spec:
Usage
fit_control(
bias.correct = FALSE,
getsd = TRUE,
getJointPrecision = TRUE,
getReportCovariance = FALSE,
projection_uncertainty = 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. If
TRUE, applies bias correction viaTMB::sdreport(). DefaultFALSE.- getsd
logical. If
TRUE, runTMB::sdreport()after optimization. DefaultTRUE.- getJointPrecision
logical. Return the full Hessian of fixed and random effects. Default
TRUE(matchesfit_mod()default).- getReportCovariance
logical. Return the variance-covariance of
ADREPORTvariables. DefaultFALSE.- projection_uncertainty
logical. If
TRUE, accounts for hindcast parameter uncertainty in projections when using an HCR (refits with all hindcast and biological-reference-point parameters turned on). DefaultFALSEfor speed.- comp_offset
Numeric or
NULL. Small proportion offset added to the observed and predicted age/length composition and conditional-age-at-length (caal) bins before the multinomial / Dirichlet-multinomial likelihood (to avoidlog(0)for empty bins). Stored ondata_listso the fitted likelihood and the OSA observation vector use the same offset, and so internal re-fits inherit it.NULL(the default) inheritsdata_list$comp_offsetif set, otherwise1e-5; a number overrides it. Does not apply to diet (stomach-content) compositions.- bias_adjust_obs
logical with default TRUE. Whether to apply a bias adjustment (mean-sd^2/2) to lognormal data likelihoods
- bias_adjust_proc
logical with default TRUE. Whether to apply a bias adjustment (mean-sd^2/2) to lognormal process likelihoods
- use_gradient
logical. Use the analytic gradient during phasing. Default
TRUE.- rel_tol
Numeric tolerance used to flag discontinuous likelihood warnings (compares the TMB and
nlminbobjectives). Default1.- loopnum
Integer. Number of times to re-start optimization (
loopnum = 3sometimes achieves a lower final gradient thanloopnum = 1). Default5.- newtonsteps
Integer. Number of extra Newton steps to take after optimization (alternative to
loopnum). Default0.- phase
TRUE/FALSEor a list. IfFALSE, the model is not phased. IfTRUE, default phasing is used. Can also accept a list of parameter object names with corresponding phase. DefaultFALSE.- TMBfilename
Optional character. Path (without
.cpp) to an alternate TMB template for development. DefaultNULL(use the bundledceattle_v01_11).- verbose
0= silent,1= print updates of model fit,2= print updates of model fit and TMB estimation progress. Default1.- nlminb_control
A list of control parameters passed to
stats::nlminb(). See?nlminb. Defaultlist(eval.max = 1e9, iter.max = 1e9, trace = 0).
Details
fit <- fit_mod(
data_list = BS2017SS,
msmMode = 0,
fit_control = fit_control(loopnum = 1, getsd = FALSE)
)Pass the result via the fit_control argument to fit_mod(). When
supplied, the values in the fit_control object override the
corresponding individual arguments to fit_mod(). Individual
arguments are kept for backward compatibility.