fitTMB: Optimize TMB models and package results, modularly

fitTMBR Documentation

Optimize TMB models and package results, modularly

Description

These functions (called internally by glmmTMB) perform the actual model optimization, after all of the appropriate structures have been set up (fitTMB), and finalize the model after optimization (finalizeTMB). It can be useful to run glmmTMB with doFit=FALSE, adjust the components as required, and then finish the fitting process with fitTMB (however, it is the user's responsibility to make sure that any modifications create an internally consistent final fitted object).

Usage

fitTMB(TMBStruc, doOptim = TRUE)

finalizeTMB(TMBStruc, obj, fit, h = NULL, data.tmb.old = NULL)

Arguments

TMBStruc

a list containing lots of stuff ...

doOptim

logical; do optimization? If FALSE, return TMB object

obj

object created by fitTMB(., doOptim = FALSE)

fit

a fitted object returned from nlminb, or more generally a similar list (i.e. containing elements par, objective, convergence, message, iterations, evaluations)

h

Hessian matrix for fit, if computed in previous step

data.tmb.old

stored TMB data, if computed in previous step

Examples

## regular (non-modular) model fit
m0 <- glmmTMB(count ~ mined + (1|site),
             family=poisson, data=Salamanders)
## construct model structures
m1 <- update(m0, doFit=FALSE)
names(m0)
m2 <- fitTMB(m1, doOptim = FALSE)
## could modify the components of m1$env$data at this point ...
## rebuild TMB structure (*may* be necessary)
m2 <- with(m2$env,
               TMB::MakeADFun(data,
                               parameters,
                               map = map,
                               random = random,
                               silent = silent,
                               DLL = "glmmTMB"))
m3 <- with(m2, nlminb(par, objective = fn, gr = gr))
m4 <- finalizeTMB(m1, m2, m3)

glmmTMB documentation built on Oct. 7, 2023, 5:07 p.m.