Fit a MARSS model with TMB + optimization. TMB does fast computation of the likelihood gradients and this is used with stats::nlminb() or stats::optim() to optimize the likelihood. The former is much faster than the later and is the default.

MARSS.tmb(
  y,
  model = NULL,
  inits = NULL,
  miss.value = as.numeric(NA),
  method = "TMB",
  form = "dfa",
  fit = TRUE,
  silent = FALSE,
  control = NULL,
  ...
)

Arguments

y

Vector of observations n x T.

model

list with

  • R "diagonal and equal", "unconstrained", "diagonal and unequal"

  • m the number of states (factors). default is 1

inits

list of initial conditions

method

to pass to optim call; ignored for fun="nlminb"

form

The equation form used in the marssTMB() call. The default is "dfa".

fit

Whether to fit the model.

silent

Show TMB output when fitting

control

list for the optimization function. stats::nlminb() or stats::optim(), control$fun.opt allows you to choose optim or nlminb as the optimization function. control$optim.method allows you to choose method for optim().

Value

A list with Optimization, Estimates, Fits, and AIC

Details

Note. Goal is to have the user call with the MARSS package as MARSS(y, method="tmb"), which then calls MARSStmb(). This is the mimics the behavior of method="BFGS" and method="kem" in MARSS::MARSS() which looks for a fitting function called MARSSxyz, where xyz is the method. Further arguments for the optimization method can be passed into control.

Author

Eli Holmes

Examples

library(MARSS)
data(lakeWAplankton, package = "MARSS")
phytoplankton <- c("Cryptomonas", "Diatoms", "Greens", "Unicells", "Other.algae")
dat <- as.data.frame(lakeWAplanktonTrans) |>
  subset(Year >= 1980 & Year <= 1989) |>
  subset(select=phytoplankton) |>
  t() |>
  MARSS::zscore()

#fit with MARSS
fit <- MARSS.tmb(dat, model=list(m=3))