GithubHelp home page GithubHelp logo

atsa-es / marsstmb Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 34.7 MB

Companion package for MARSS that allows you to use TMB to fit MARSS models

Home Page: https://atsa-es.github.io/marssTMB/

R 39.50% C++ 10.04% HTML 50.46%
marss multivariate-timeseries r-package state-space-model time-series tmb

marsstmb's People

Contributors

eeholmes avatar ericward-noaa avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

marsstmb's Issues

to do

  • add tinitx so x0 can be at 0
  • estimate_marss2() is slow. Try logging the diagonal and then Q.diagonal() = Q.diagonal().exp(); https://stackoverflow.com/questions/33834873/modify-eigen-matrix-diagonal. vector diag_exp = Q.diagonal().array().exp();` Q.diagonal().array() = diag.exp;
  • Not handling convergence messages from nlminb
  • add Q estimation (diag or unconstrained)
  • nlminb not picking up maxit? check might have been the print issue that I fixed
  • check tinitx = 0 and V0 not zero
  • allow zeros on diagonal of R and Q
  • add D estimation; cutting out all the extraneous stuff to make just like MARSS
  • add C estimation
  • fix the print out. something is off with metadata
  • I bet CRAN will complain re ::: what to do?
  • Add in test for marssTMB being installed and loaded if method="TMB"
  • Revamp the vignettes
  • Add vignette for model comparisons/testing

LATER

  • Add G and H to allow zeros on the diagonal of Q and R
  • Test time-varying Q and R
  • look into how to do equal var cov; the diag splitting didn't work.

MARSS

  • add method="TMB"
  • fix the error with iterations for optim. should be counts[2]
  • need Rd file for MARSS::MARSSfit

something wrong with LL calc

Running into numerical problems but not really reporting that.

Should put in the option to compute the chol of the var-cov matrix the way I did for MARSSoptim(). Something is off with the separation method.

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()
modlist = list(U="zero", A="zero", Q="unconstrained")
a = MARSS(dat[,14:22], method="BFGS_TMB", model=modlist, control=list(trace=1))

LL much lower than

a = MARSS(dat[,14:22], method="BFGS_TMB")

also LL doesn't match. The LL output is from the KF but within the opt output is the LL coming from TMB. Should match.

a$iter.record$opt.output$value

model with LL diff

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

TMB function to do A %*% x ?

@ericward-noaa

I think one the first tasks is to write a generic TMB function that does:

A %*% x

So rather than writing code for Bx, and Cc, and Dd. We have a function for mult(A, x). Maybe you have something like that already?

Idea is to have maps for all the MARSS parameters and then code to do

x(t) - Bx(t-1) + u + Cc(t) ~ MVN(0, Q)

and

y(t) - Zx(t) + a + Dd(t) = MVN(0, R)

Seems pretty straight forward from Tim's code, but that mult(A, x) function would make the code cleaner.

fix par element

par should be in marss form

> names(m1.em$par)
 [1] "Z"  "A"  "R"  "B"  "U"  "Q"  "x0" "V0" "G"  "H"  "L" 
> names(m1.tmb2$par)
 [1] "Z"  "A"  "R"  "B"  "U"  "Q"  "x0" "V0" "D"  "C"  "d"  "c"  "G"  "H"  "L" 
> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.