GithubHelp home page GithubHelp logo

Comments (5)

helske avatar helske commented on August 20, 2024

It seems that the Gaussian approximation fails silently with exact diffuse initialization (using P1inf) combined with your model structure. First of all, if you switch away from the exact diffuse initialization you get negative likelihood:

P1 <- matrix(0, ncol = 9, nrow = 9)
diag(P1)[1:3] <- 10000
m2<- SSModel(y ~ -1+SSMcustom(Z = Zt, T = Tt, R = Rt, Q = Qt, a1 = a1, P1 = P1), data = dat, distribution = 'binomial', u=u)
logLik(m2) # -12.7887

Let's simplify your model a bit by removing the constant states and reducing number of observations:

Tt <- diag(c(0.4434,0.9962,0.9996))
Qt <- diag(rep(3.3576,3))
P1inf <- matrix(0, ncol = 3, nrow = 3)
diag(P1inf)[1:3] <- 1
Zt <- matrix(c(1.2670, 1.2729, 0.5930), nrow = 1)
Rt <- diag(3)
a1 <- matrix(c(0, 0, 0), ncol = 1)

dat <- data.frame(y = c(0, 1, 1, 0))
u <- matrix(1, nrow = NROW(dat), ncol = 1)
m3 <- SSModel(y ~ -1+SSMcustom(Z = Zt, T = Tt, R = Rt, Q = Qt, a1 = a1, P1inf = P1inf), data = dat, distribution = 'binomial', u=u)
logLik(m3) # 42.27624

Still failing. Checking at the Gaussian approximation shows "convergence" to some extreme case:

> c(approxSSM(m3,tol=1e-16)$H)
[1] 7.954668e+16 7.319107e+25 1.705125e+16 3.266442e+16
> c(approxSSM(m3,tol=1e-16)$y)
[1] -39.91512   0.00000  42.00000 -39.02506

So essentially the Gaussian approximation suggests zero signal-to-noise ratio.

Without exact initialization things look quite different:

> m4 <- m3
> m4$P1inf[]<-0
> m4$P1[]<-diag(1e5, 3)
> c(approxSSM(m4)$H)
[1] 12.906387  7.094437  7.710829  5.496582
> c(approxSSM(m4)$y)
[1] -3.473307  2.791681  2.891019 -2.471853

So the diffuse initialization causes the Gaussian approximation to fail here. Even this simplified model is borderline nonidentifiable though given that the linear predictor Zalpha_t is a linear combination of multiple AR(1) processes, and second and third states are both almost random walks, and the observations are just ones and zeros, so essentially there isn't much information to be gained from the series compared to the very flexible three-state model without any knowledge of their initial values (i.e. diffuse initialization).

from kfas.

zjph602xtc avatar zjph602xtc commented on August 20, 2024

Thank you!
When I tried to use optim to maximize the likelihood, then sometimes I will get these wired parameter that provide large (but wrong) likelihood.
Then my question is:

  1. Is there a way to determine whether the approximation fails or not? Since the logLik function does not give any warnings in this case. Maybe that approxSSM(model)$H is too large indicates the failure?
  2. If I want to estimate some parameters using optim(fn=-logLik), are there any suggestions to make it get the right result? I tried different initial values (which provide correct and good likelihood) but it will stop at positive likelihood.
    Thank you!

from kfas.

helske avatar helske commented on August 20, 2024

Yeah you probably need to check if the values of approxSSM(model)$H are very large. My initial though was to just check min(approxSSM(model)$H) but that doesn't seem to work as some of the variances at the beginning are still ok in your example. Not sure if the maximum is too strict, probably not.

So, I would probably make a custom objective function for optim, where you have something like

# create model
model <- ...
if(max(approxSSM(model)$H) > 1e100) {
  Inf
} else {
  -logLik
}

And yes you typically need to start with multiple initial values and pick the best, as the likelihood surface often contains multiple local optimums.

from kfas.

helske avatar helske commented on August 20, 2024

I now added an additional parameter for logLik etc called H_tol, which can be used to automatically detect overly large values of H of the approximating model. If the largest variance of the model is bigger than the tolerance, logLik returns -.Machine$double.xmax^0.75. The updated version can be installed from the GitHub, and later this month from CRAN.

from kfas.

zjph602xtc avatar zjph602xtc commented on August 20, 2024

That works for me!! Thank you

from kfas.

Related Issues (20)

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.