R/estimate_marss.R
estimate_marss.Rd
This model is in the general "marss" vectorized form. The diagonals and offdiagonals of R and Q are split apart like Tim Cline did. In estimate_marss2()
, I use instead the approach in MARSS::MARSSoptim()
where I just use the chol()
of these matrices. Technically there are 2 equal solutions since the diagonals appear as the square so -a and a are the same. But I have not observed that this affects the behavior of optim().
estimate_marss(
MLEobj,
method = c("TMB", "nlminb_TMB", "BFGS_TMB"),
opt.control = NULL,
...
)
A properly formatted MARSS model as output by MARSS()
Normally passed in as MLEobj$method, but allows user to pass in a new method if they want to use MLEobj with another method. Allowed values are "TMB", "nlminb.TMB", "BFGS.TMB".
Normally this is passed in as MLEobj$control, but if the MLEobj was set up using a different method, then you will need to set the opt.control options. See details.
not used
A list with the objective and optimization objects.
obj
is the raw output from the TMB::MakeADFun()
call.
op
is the raw output from the optimization call (optim or nlminb). Note that the function is minimizing the negative log-likelihood so the sign will be opposite of the log-likelihood reported by MARSS()
opt.control
is the controls sent to the optimization function.
method
method used for optimization
Minimal error checking is done in this function.
Normal calling function is MARSS::MARSS()
with method="TMB"
.
The main thing this does is
collapse the 3D fixed and free matrices into 2D
separate out the diag and offdiag parameter elements of R and Q
Restrictions
V0 fixed (not estimated)
Q and R cannot be time-varying (at the moment)
opt.control
is what is passed to the control argument in nlminb()
or optim()
. If you use MARSS(x, method="TMB")
, this will be set to appropriate defaults which you can see via MLEobj$control
. But if you call estimate_marss()
with a MLEobj from a call such as MARSS(x, method="kem")
(so not a TMB method), you will need to set opt.control
if you want values different from the base defaults for those functions. Note as a shortcut for nlminb()
, you can set both eval.max
, iter.max
to the same value with opt.control=list(maxit=1000)
. Note, if you pass in opt.control
, this will replace all values currently in MLEobj$control
that are associated with the optimizer function.
The defaults set in MARSS::MARSS()
are
nlminb
: eval.max = 5000
, iter.max = 5000
and trace = 0
.
optim
: maxit = 5000
and trace = 0
All other controls for the optimization function are left at NULL.
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()
# set-up the model
mod <- MARSS(dat, model=list(m=3, tinitx=1), form="dfa", fit=FALSE, silent=TRUE)
# fit
fit <- estimate_marss(mod)
#> MARSSfit.TMB: The method in the marssMLE object is not TMB. Setting to nlminb_TMB for fitting.