Skip to content

numerical overflow in calculating likelihood #5

Open

Description

sppb.msm <-msm(state_1 ~ days, subject = symbol, data = data,

  •            qmatrix = qmat0, death = 3, method = "BFGS", 
    
  •            control = list(fnscale = 4000, maxit = 10000),
    
  •            covariates = ~ PB)
    

Error in Ccall.msm(params, do.what = "lik", ...) :
numerical overflow in calculating likelihood

Activity

  1. chjackson commented on Feb 18, 2017

    @chjackson
    Owner

    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.

  2. AlexKram commented on Jun 9, 2018

    @AlexKram

    Have the same problem with different data sets. You can get a reproducible example even with provided cav data set:

    > cavsex.msm <- msm(state ~ years, subject=PTNUM, data=cav, qmatrix=Q, deathexact=4, covariates = ~age)
    Error in Ccall.msm(params, do.what = "lik", ...) : 
      numerical overflow in calculating likelihood
    
  3. chjackson commented on Jun 10, 2018

    @chjackson
    Owner

    Try setting control=list(fnscale=4000) in the call to msm. Since the -2 log likelihood is around 4000 in this example, this normalises the -2 log-likelihood during optimisation to a scale of around 1, so that overflow is less likely to occur.

  4. chjackson commented on Jun 10, 2018

    @chjackson
    Owner

    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.

  5. hbg26 commented on Nov 2, 2018

    @hbg26

    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.

  6. chjackson commented on Nov 2, 2018

    @chjackson
    Owner

    Could you give a reproducible example please @hbg26

  7. hbg26 commented on Nov 2, 2018

    @hbg26

    Using the cav dataset:

    cav.age.msm <- msm( state ~ years, subject=PTNUM, data = cav, qmatrix = Q, deathexact = 4, covariates = ~age, obstype = 1, control=list(fnscale=4000))

    I tried using different values for fnscale and maxit but didn't work.

  8. chjackson commented on Nov 2, 2018

    @chjackson
    Owner

    That works for me, using

    Q<-rbind(c(0,0.25,0,0.25), c(0.166,0,0.166,0.166),c(0,0.25,0.25,0), c(0,0,0,0))

    and the latest CRAN msm, R 3.4.4 on Linux. If it hadn't worked I would have tried rescaling the covariate:

    age10 <- (cav$age - mean(cav$age))/10

  9. 28sophiesworld commented on Jan 19, 2019

    @28sophiesworld

    The code to set the allowable transitions has proven essential for me. Try playing with those numbers, e.g. change the values within
    Q<-rbind

  10. seairis commented on Mar 1, 2019

    @seairis

    Great. The code of control=list(fnscale=4000) solved my problem of numerical overflow and control =list(reltol = 1e-16) solved false convergence.

  11. Heart-wang commented on Dec 2, 2019

    @Heart-wang

    numerical overflow in calculating likelihood,,, How can i correct it?

  12. Heart-wang commented on Dec 4, 2019

    @Heart-wang

    wsex.msm<-msm(state~years,subject=id,data=w,qmatrix=Q,covariates=~sex,method="BFGS",control=list(fnscale=4000,maxit = 10000))
    Warning message:
    In msm(state ~ years, subject = id, data = w, qmatrix = Q, covariates = ~sex, :
    Optimisation has probably not converged to the maximum likelihood - Hessian is not positive definite.

  13. chjackson commented on Dec 4, 2019

    @chjackson
    Owner

    @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

  14. Heart-wang commented on Jan 7, 2020

    @Heart-wang

    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?

  15. joseph-rickert commented on Jun 2, 2020

    @joseph-rickert

    The text file contains some code that generates synthetic data to reproduce the msm error
    Error in Ccall.msm(params, do.what = "lik", ...) : numerical overflow in calculating likelihood
    repex_msm_0verflow.txt

  16. 9 remaining items

  17. chjackson commented on Nov 15, 2023

    @chjackson
    Owner

    @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.

  18. yinglittxs commented on Sep 29, 2025

    @yinglittxs

    When I apply msm package to my model ,with adjusted age, sex, area, the different cohorts, cholestrol and family history and body round index, it goes wrong: error in ccall.msm(params,do.what="lik",...)numeric overflow in calculating likelihood. So, I would like to trouble if you could help me figure out how to solve this problem.

  19. chjackson commented on Sep 29, 2025

    @chjackson
    Owner

    @yinglittxs (a) Check that the transition structure you have specified is appropriate for the process you are modelling in continuous time - see the course notes. (b) Start the model small, with no covariates, check it works, then build it up. (c) Check there is sufficient data in each covariate category to be able to identify the covariate effects. (d) Optimisation tuning may help. See the user guide section 2.12.

  20. yinglittxs commented on Sep 29, 2025

    @yinglittxs

    Thank you for your reply. I have checked the covariates, found that when the msm model include continous variables like BMI will go wrong: : error in ccall.msm(params,do.what="lik",...)numeric overflow in calculating likelihood. While the categorical variables not. This is strange and I do not know how to handle with it. And after your reply, I have checked the Q matrix, the transitions of 1 to 3 and 3 to 1 was permitted which may be another cause.

  21. yinglittxs commented on Oct 8, 2025

    @yinglittxs

    @chjackson Dear Professor Chris Jackson: I found that even when I set the transition matrix to disallow transitions between states 1 and 3 (both 1→3 and 3→1), the estimated transition probabilities still show some probability for 1→3 and 3→1 transitions. Is it because the risk of moving from the initial state 1 to the final state 3 (e.g., diabetes) is obtained by the cumulative effect of the intermediate transitions (1→2→3)? I will appreciate it if you could help me.

  22. chjackson commented on Oct 8, 2025

    @chjackson
    Owner

    @yinglittxs Yes - this is probably the commonest confusion about msm. msm fits continuous-time models, which are defined from transition intensities, not transition probabilities. When you "disallow transitions" by setting the qmatrix in your call to msm(), you are saying which transition intensities are zero. Your "estimated transition probabilities" were presumably produced by pmatrix.msm, which gives the probability of making a transition over an interval of time (say $t$ to $t+u$). You have disallowed a direct transition from 1 to 3, but a person can still go from state 1 at time $t$ to state 3 at time $t+u$, no matter how small $u$ is, because they can still go through state 2.

  23. yinglittxs commented on Oct 10, 2025

    @yinglittxs

    @chjackson Dear Professor Chris Jackson: Thank you very much for your reply quickly. I still have one more question. In the multi-state model, is the hazard ratio (HR) calculated as the ratio of transition intensities between different levels of a covariate?

  24. chjackson commented on Oct 10, 2025

    @chjackson
    Owner

    @yinglittxs Yes. The words "intensity", "hazard" and "rate" are often used interchangeably.

  25. yinglittxs commented on Oct 10, 2025

    @yinglittxs

    @chjackson Dear Professor Chris Jackson: Thank you very much for your careful and patient response. This has been of great help to my studies.

  26. yinglittxs commented on Oct 12, 2025

    @yinglittxs

    @chjackson Dear Professor Chris Jackson: I would like to seek your advice on how to plot restricted cubic spline (RCS) curves based on a multi-state model (MSM) to explore the relationship between a covariate and different transition pathways, including point estimates and 95% confidence intervals. Could you please advise whether there is a convenient way to implement this based on MSM results, or share any relevant codes, methods or references that you would recommend? Your guidance would be greatly appreciated.
    Thank you very much for your time and help.
    Best regards

  27. chjackson commented on Oct 13, 2025

    @chjackson
    Owner

    @yinglittxs I don't know of any tutorial or worked example that covers what you want. I'd suggest you try to implement something, and then if something doesn't work, or you have a question that is not answered by the documentation, then consider posting an issue. But I'm more likely to reply to clear, precise questions, ideally with minimal reproducible examples.

    Also can we keep posts on this thread relevant to the original topic of "numerical overflow" - and start a new issue if necessary.

  28. pinned this issue on Oct 13, 2025
  29. unpinned this issue on Oct 13, 2025
  30. chjackson commented on Oct 13, 2025

    @chjackson
    Owner

    I'm now locking this issue, as it has turned into a general "msm help" thread, which wasn't intended.

  31. Repository owner locked as off topic and limited conversation to collaborators on Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions