Skip to contents

Fits the compiled REMA model using TMB::MakeADFun and stats::nlminb. Source code and documentation modified from wham::fit_wham.

Usage

fit_rema(
  input,
  n.newton = 0,
  do.sdrep = TRUE,
  model = NULL,
  do.check = FALSE,
  MakeADFun.silent = TRUE,
  do.fit = TRUE,
  save.sdrep = TRUE
)

Arguments

input

Named list output from prepare_rema_input, which includes the following components needed to fit model using TMB::MakeADFun:

$data

Data, a list of data objects for model fitting or specification (e.g., user-defined pentalties, index pointers, etc.). A required input to MakeADFun.

$par

Parameters, a list of all random and fixed effects parameter objects. A required input to MakeADFun.

$map

Map, a mechanism for collecting and fixing parameters in TMB. An input to MakeADFun.

$random

Character vector defining the parameters to treat as random effects. An input to MakeADFun.

$model_name

Character, name of the model, e.g. "GOA shortraker with LLS by depth strata". Useful for model comparison.

n.newton

integer, number of additional Newton steps after optimization. Not an option that is currently needed, but is passed to fit_tmb. Default = 0.

do.sdrep

T/F, calculate standard deviations of model parameters? See sdreport. Default = TRUE.

model

(optional), a previously fit rema model.

do.check

T/F, check if model parameters are identifiable? Passed to fit_tmb. Runs internal function check_estimability, originally provided by https://github.com/kaskr/TMB_contrib_R/TMBhelper. Default = TRUE.

MakeADFun.silent

T/F, Passed to silent argument of TMB::MakeADFun. Default = TRUE.

do.fit

T/F, fit the model using fit_tmb. Default = TRUE.

save.sdrep

T/F, save the full TMB::sdreport object? If FALSE, only save summary.sdreport to reduce model object file size. Default = TRUE.

Value

a fit TMB model with additional output if specified:

$rep

List of derived quantity estimates (e.g. estimated biomass)

$sdrep

Parameter estimates (and standard errors if do.sdrep = TRUE)

Details

Future development: Implement one-step-ahead (OSA) residuals for evaluating model goodness-of-fit TMB::oneStepPredict). OSA residuals are more appropriate than standard residuals for models with random effects (Thygeson et al. (2017). See wham for an example of OSA implementation and additional OSA residual options (e.g. full Gaussian approximation instead of the (default) generic method using osa.opts=list(method="fullGaussian").

Examples

if (FALSE) { # \dontrun{
# place holder for example code
} # }