-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numerical overflow in calculating likelihood #5
Comments
Again, a reproducible example might help (PB isn't in the data you sent me). Have you tried all the tricks in the "convergence failure" section of the PDF manual? Perhaps try rescaling the covariates to have SD around 1, or rescaling the time variable in months instead of years? The error message is not helpful so I'll leave the issue open, but this kind of error message is common and really difficult to prevent in a general case. |
Have the same problem with different data sets. You can get a reproducible example even with provided cav data set:
|
Try setting |
I have experimented with doing this rescaling automatically for all model fits, but it seemed to cause worse convergence for as many examples as it improved. |
I'm facing the same problem when I use continuos covariates. The fnscale option doesn't seem to work with the cav dataset or with others datasets. |
Could you give a reproducible example please @hbg26 |
Using the cav dataset:
I tried using different values for fnscale and maxit but didn't work. |
That works for me, using
and the latest CRAN msm, R 3.4.4 on Linux. If it hadn't worked I would have tried rescaling the covariate:
|
The code to set the allowable transitions has proven essential for me. Try playing with those numbers, e.g. change the values within |
Great. The code of control=list(fnscale=4000) solved my problem of numerical overflow and control =list(reltol = 1e-16) solved false convergence. |
numerical overflow in calculating likelihood,,, How can i correct it? |
wsex.msm<-msm(state~years,subject=id,data=w,qmatrix=Q,covariates=~sex,method="BFGS",control=list(fnscale=4000,maxit = 10000)) |
@Heart-wang A reproducible example would help others to give advice. Though please first try some of the tricks above in the thread, and in the "Convergence failure" section of the PDF manual |
When there are many states of the disease we are studying, such as the progress of the metabolic syndrome , eight states are set according to its diagnostic criteria. How should we set Q properly? |
The text file contains some code that generates synthetic data to reproduce the msm error |
Thanks for the reproducible example. The problem there is that the model is not identifiable. The consequence is that the optimiser is exploring a log-likelihood surface that is a flat function of the parameters. Therefore massive differences in the parameters will produce tiny differences in the likelihood. To try to find the maximum likelihood, it makes massive jumps in the parameter space. At the second iteration it visits log intensity values of 4000 - which results in the intensity overflowing, and the error message. The example looks like it's trying to fit a discrete-time Markov model to discrete-time data. I'm not sure I could add something to the error message, like "Perhaps the model is not identifiable - check, for example, that the transition structure and observation type are appropriate for the data". But I'm not sure whether this is the only (or the dominant) reason that this message would be triggered - if there are other reasons, then the message may be confusing. A wider range of examples would help to clarify this. |
thanks |
Hello Professor Jackson,
Thank you for the quick reply. Yes, I can see that it is an identifiability
problem. In fact, I have observed that constraining the transition matrix
is helpful. It is not too hard to find a small, random, 3X3 birth-death
process, transition matrix that msm() will fit for small synthetic data
sets. For example, here is a TM and Q matrix pair that for 200 rows and 5
columns, msm() may produce results, or terminate with a warning that the
algorithm may not have converged, but for which I have so far not observed
the overflow error.
Setting r to 2000 and c to 10 will generate the overflow error.
This behavior is curious. I did try to look through the msm code to see if
there was a place to determine where things start to go South, but this is
beyond me.
TM_1 <- matrix(c(0.5367896, 0.4632104, 0.0000000,
0.3617935, 0.2929464, 0.3452601,
0.0000000, 0.5953339, 0.4046661), nrow = 3, byrow = TRUE)
Q <- matrix(c(0,1,0,1,0,1,0,1,0),nrow=3,byrow=TRUE)
Also, it seems to be even easier to stumble onto small, random transition
matrices with absorbing states that msm() can handle.
I did not set exacttimes=TRUE because I convinced myself that I was on to a
simple way of simulating the Jump Chain of a continuous time process. I got
this notion from a naive leap of faith after noticing that the methods used
in the ctmcd package only need the raw transition counts or relative counts
to drive them.
My current hypothesis as to why my random data sets are so different from
the several real data sets you provide in the package, is that so far I
have been working with overly simplistic transition times. However, I can
find nothing in the theory of continuous chains to back this up.
Anyway, thank you for your work. msm is an amazing package and I think a
real R treasure.
Best regards,
Joe Rickert
Joseph B. Rickert
RStudio R Community Ambassador
R Consortium Director
Cell: 408.489.0566
…On Wed, Jun 3, 2020 at 3:17 AM Heart-wang ***@***.***> wrote:
thanks
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN22VWQOB73UVSMIXP3F3TRUYPMZANCNFSM4DAPX77A>
.
|
I'm also running into the same issue. It is definitely an identifiability issue as Prof Jackson eloquently described above. I believe I can handle this in an ad hoc manner by collapsing states and reducing covariates. Also, the I'm wondering 2 things:
|
I expect Bayesian approaches would help if the data are weak, but only if you have substantive information to go into the prior. I'm not aware of any package that does continuous-time Markov models. Though Stan is better than WinBUGS for implementing general models. edited April 2024: there is now the msmbayes package which implements some Bayesian continuous-time multistate models, but is not as general as msm. Misclassification models have more parameters than non-hidden Markov models.. |
That makes sense. Also, (facepalm)... of course they have more parameters. Thanks! |
Hi professor Jackson, I try to use msm package for purchasing data that can find behavior and my models is fitting for 7 states and I want to expand on 20 states, I stock in nstates=8 and I got a lot of error even when I increased number of individuals and number of iterations of person who purchasing. and get this error again and again. nstates <- 8 Q8 <- matrix(c(rep(1/nstates, nstates^2)), byrow=TRUE, nrow=nstates) hmodel8 <- list(hmmMV(hmmPois(0.04),hmmPois(0.02)),
Error in Ccall.msm(params, do.what = "lik", ...) : |
@HaniyehDanesh This model is almost certainly not identifiable from the data. You are allowing transitions between every state, assuming the state is intermittently observed, and assuming the states are misclassified. I guess you are confusing discrete and continuous time - see the course notes for an explanation of this issue. Better to start with small, simple models - models that are small enough for you to understand how the data informs them, check the results make sense. Then build them up in stages. When you say your "model is fitting" for 7 states, have you checked that the parameter estimates are realistic? Often the optimiser will claim to converge, but the results are extremely large confidence intervals, hence the estimates are unreliable and the model is not useful. |
Thank you for answering professor. I still misunderstanding about "I guess you are confusing discrete and continuous time", we have purchasing time based on month for example 1,...,24 (this is our time). You mean I should use stateble.msm() or changing my transition matrix and initial values? |
@HaniyehDanesh As I said, please work through the course notes to understand all this better. Consider what transitions in continuous time can happen, and consider what your observations tell you about the state of the process at each point in continuous time. |
sppb.msm <-msm(state_1 ~ days, subject = symbol, data = data,
Error in Ccall.msm(params, do.what = "lik", ...) :
numerical overflow in calculating likelihood
The text was updated successfully, but these errors were encountered: