atsa-es / marssTMB

Companion package for MARSS that allows you to use TMB to fit MARSS models
https://atsa-es.github.io/marssTMB/
1 stars 0 forks source link

model with LL diff #14

Open eeholmes opened 1 year ago

eeholmes commented 1 year ago

This is lower with BFGS. Even if. Perhaps has something to do with the NAs in the data. Seems to go away wo the NAs.

library(marssTMB)
U1 <- matrix(0,2,1)
Q1 <- matrix(c("q11","q12","q12","q22"),2,2)
Z1 <- matrix(c(1,0,1,1,1,0),3,2)
A1 <- matrix(list("a1",0,0),3,1)
R1 <- matrix(list("r11",0,0,0,"r",0,0,0,"r"),3,3)
pi1 <- matrix(0,2,1); V1=diag(1,2)
model.list <- list(U=U1, Q=Q1, Z=Z1, A=A1, R=R1, x0=pi1, V0=V1, tinitx=0)
dat <- t(harborSealWA)[2:4, ] # remove the year row
fit1 <- MARSS(dat, model=model.list, method="BFGS")
fit2 <- MARSS(dat, model=model.list, method="TMB", inits=fit1)
dat <- t(harborSealWA); dat <- dat[2:4, ]
modlist = list(U="zero", A="zero", x0="zero", Q="unconstrained")
MARSS(dat[,14:22], method="TMB", silent=TRUE, model=modlist)$logLik
MARSS(dat[,14:22], silent=TRUE, model=modlist)$logLik

maxit not getting set for nlminb

a = MARSS(dat[,14:22], method="TMB", model=modlist, control=list(maxit=20000))

false convergence for nlminb but seems ok

modlist = list(U="zero", A="zero", Q="unconstrained", tinitx=1)
a = MARSS(dat[,14:22], method="TMB", model=modlist)
a = MARSS(dat[,14:22], method="BFGS_TMB", model=modlist)
a = MARSS(dat[,14:22], model=modlist)

false convergence for nlminb and no convergence at 5000+ iter for optim,

modlist = list(U="zero", A="zero", Q="unconstrained", x0="zero", tinitx=1)
a = MARSS(dat[,14:22], method="TMB", model=modlist) # reports false convergence but better LL than EM
a = MARSS(dat[,14:22], method="BFGS_TMB", model=modlist) # not remotely converged
a = MARSS(dat[,14:22], method="BFGS", model=modlist) # bad
a = MARSS(dat[,14:22], model=modlist) 
a = MARSS(dat[,14:22], method="BFGS", model=modlist, inits=a) # good same as TMB

false/no convergence but LL looks ok

modlist = list(U="zero", A="zero", Q="unconstrained")
a = MARSS(dat[,14:22], method="TMB", model=modlist)
a = MARSS(dat[,14:22], method="BFGS_TMB", model=modlist)
a = MARSS(dat[,14:22], model=modlist)

Not handling convergence messages from nlminb