optim
function. This allows access to R's quasi-Newton algorithms available via the optim
function. The MARSSoptim
is called when MARSS
is called with method="BFGS"
. This is a base function in the MARSS-package
. neglogLik
is a helper function for MARSSoptim
that returns the negative log-likelihood given a vector of the estimated parameters and a marssMLE
object. When possible, the Kalman filter and smoother functions from the KFAS R package are used.MARSSoptim(MLEobj)
neglogLik(x, MLEobj)
marssMLE
.MARSSvectorizeparam
.marssMLE
object which was passed in, with additional components:MLEobj$control$trace = TRUE
, then this is the $message
value from optim
.MARSSparamCIs
but if you use parametric or non-parametric bootstrapping with this function, it will use the EM algorithm to compute the bootstrap parameter estimates! The quasi-Newton estimates are too fragile for the bootstrap routine since one often needs to search to find a set of initial conditions that work (i.e. don't lead to numerical errors).
Estimates from MARSSoptim
(which come from optim
) should be checked against estimates from the EM algorithm. If the quasi-Newton algorithm works, it will tend to find parameters with higher likelihood faster than the EM algorithm. However, the MARSS likelihood surface can be multimodal with sharp peaks at degenerate solutions where a Q or R diagonal element equals 0. The quasi-Newton algorithm sometimes gets stuck on these peaks even when they are not the maximum. Neither an initial conditions search nor starting near the known maximum (or from the parameters estimates after the EM algorithm) will necessarily solve this problem. Thus it is wise to check against EM estimates to ensure that the BFGS estimates are close to the MLE estimates (and vis-a-versa, it's wise to rerun with method="BFGS" after using method="kem").
Note this is mainly a problem if the time series are short or very gappy. If the time series are long, then the likelihood surface should be nice with a single interior peak. In this case, the quasi-Newton algorithm works well but it can still be sensitive (and slow) if not started with a good initial condition. Thus starting it with the estimates from the EM algorithm is often desirable.
One should be aware that the prior set on the variance of the initial states at t=0 or t=1 can have catastrophic effects on one's estimates if the presumed prior covariance structure conflicts with the structure implied by the MARSS model. For example, if you use a diagonal variance-covariance matrix for the prior but the model implies a matrix with non-zero covariances, your MLE estimates can be strongly influenced by the prior variance-covariance matrix. Setting a diffuse prior does not help because the diffuse prior still has the correlation structure specified by V0. One way to detect priors effects is to compare the BFGS estimates to the EM estimates. Persistent differences typically signify a problem with the correlation structure in the prior conflicting with the implied correlation structure in the MARSS model. If this is the case, using V0=0 and estimating the x0 elements (with control$kf.x0="x10") can often help.marssMLE
may be built from scratch but are easier to construct using MARSS
with MARSS(..., fit=FALSE, method="BFGS")
.
Options for optim
are passed in using MLEobj$control
. See optim
for a list of that function's control options. If lower
and upper
for optim
need to be passed in, they should be passed in as part of control
as control$lower
and control$upper
. Additional control
arguments affect printing and initial conditions.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]MARSS
MARSSkem
marssMLE
optim
dat = t(harborSealWA)
dat = dat[2:4,] #remove the year row
#fit a model with EM and then use that fit as the start for BFGS
#fit a model with 1 hidden state where obs errors are iid
#R="diagonal and equal" is the default so not specified
#Q is fixed
kemfit = MARSS(dat, model=list(Z=factor(c(1,1,1)),Q=matrix(.01)))
bfgsfit = MARSS(dat, model=list(Z=factor(c(1,1,1)),Q=matrix(.01)),
inits=kemfit$par, method="BFGS")
Run the code above in your browser using DataLab