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,
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.- 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.