Skip to contents

fit_tmb runs a TMB model and generates standard diagnostics

Usage

fit_tmb(
  obj,
  fn = obj$fn,
  gr = obj$gr,
  startpar = NULL,
  lower = -Inf,
  upper = Inf,
  getsd = TRUE,
  control = list(eval.max = 10000, iter.max = 10000, trace = 1),
  bias.correct = FALSE,
  bias.correct.control = list(sd = FALSE, split = NULL, nsplit = NULL, vars_to_correct =
    NULL),
  savedir = NULL,
  loopnum = 2,
  newtonsteps = 0,
  n = Inf,
  getReportCovariance = FALSE,
  getJointPrecision = FALSE,
  getHessian = FALSE,
  quiet = FALSE,
  start_time_elapsed = as.difftime("0:0:0"),
  ...
)

Arguments

obj

The compiled TMB object

startpar

Starting values for fixed effects (default NULL uses obj$par)

lower, upper

vectors of lower and upper bounds, replicated to be as long as start. If unspecified, all parameters are assumed to be unconstrained.

getsd

Boolean indicating whether to run standard error calculation; see sdreport for details

control

A list of control parameters. For details see nlminb

bias.correct

Boolean indicating whether to do epsilon bias-correction; see sdreport and fit_tmbfor details

bias.correct.control

tagged list of options for epsilon bias-correction, where vars_to_correct is a character-vector of ADREPORT variables that should be bias-corrected

savedir

directory to save results (if savedir=NULL, then results aren't saved)

loopnum

number of times to re-start optimization (where loopnum=3 sometimes achieves a lower final gradient than loopnum=1)

newtonsteps

Integer specifying the number of extra newton steps to take after optimization (alternative to loopnum). Each newtonstep requires calculating the Hessian matrix and is therefore slow. But for well-behaved models, each Newton step will typically decrease the maximum gradient of the loglikelihood with respect to each fixed effect, and therefore this option can be used to achieve an arbitrarily low final gradient given sufficient time for well-behaved models. However, this option will also perform strangely or have unexpected consequences for poorly-behaved models, e.g., when fixed effects are at upper or lower bounds.

n

sample sizes (if n!=Inf then n is used to calculate BIC and AICc)

getReportCovariance

Get full covariance matrix of ADREPORTed variables?

getJointPrecision

Optional. Return full joint precision matrix of random effects and parameters?

getHessian

return Hessian for usage in later code

quiet

Boolean whether to print additional messages results to terminal

start_time_elapsed

how much time has elapsed prior to calling fit_tmb, for use, e.g., when calling fit_tmb multiple times in sequence, where start_time_elapsed = opt_previous$time_for_run

...

list of settings to pass to sdreport

Value

the standard output from nlminb, except with additional diagnostics and timing info, and a new slot containing the output from sdreport

References

For more details see https://doi.org/10.1016/j.fishres.2015.11.016