You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Reacted by iagogv3, Kevin Cazelles and Yu-Teng Yan
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.
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.
@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 Error in Ccall.msm(params, do.what = "lik", ...) : numerical overflow in calculating likelihood repex_msm_0verflow.txt
@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.
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.
@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.
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.
@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.
@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.
@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?
@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
@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.
Activity
chjackson commentedon Feb 18, 2017
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.
AlexKram commentedon Jun 9, 2018
Have the same problem with different data sets. You can get a reproducible example even with provided cav data set:
chjackson commentedon Jun 10, 2018
Try setting
control=list(fnscale=4000)in the call tomsm. 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.chjackson commentedon Jun 10, 2018
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.
hbg26 commentedon Nov 2, 2018
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.
chjackson commentedon Nov 2, 2018
Could you give a reproducible example please @hbg26
hbg26 commentedon Nov 2, 2018
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.
chjackson commentedon Nov 2, 2018
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))/1028sophiesworld commentedon Jan 19, 2019
The code to set the allowable transitions has proven essential for me. Try playing with those numbers, e.g. change the values within
Q<-rbindseairis commentedon Mar 1, 2019
Great. The code of control=list(fnscale=4000) solved my problem of numerical overflow and control =list(reltol = 1e-16) solved false convergence.
Heart-wang commentedon Dec 2, 2019
numerical overflow in calculating likelihood,,, How can i correct it?
Heart-wang commentedon Dec 4, 2019
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.
chjackson commentedon Dec 4, 2019
@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
Heart-wang commentedon Jan 7, 2020
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?
joseph-rickert commentedon Jun 2, 2020
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
9 remaining items
chjackson commentedon Nov 15, 2023
@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.
yinglittxs commentedon Sep 29, 2025
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.
chjackson commentedon Sep 29, 2025
@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.
yinglittxs commentedon Sep 29, 2025
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.
yinglittxs commentedon Oct 8, 2025
@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.
chjackson commentedon Oct 8, 2025
@yinglittxs Yes - this is probably the commonest confusion about$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.
msm.msmfits continuous-time models, which are defined from transition intensities, not transition probabilities. When you "disallow transitions" by setting theqmatrixin your call tomsm(), you are saying which transition intensities are zero. Your "estimated transition probabilities" were presumably produced bypmatrix.msm, which gives the probability of making a transition over an interval of time (sayyinglittxs commentedon Oct 10, 2025
@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?
chjackson commentedon Oct 10, 2025
@yinglittxs Yes. The words "intensity", "hazard" and "rate" are often used interchangeably.
yinglittxs commentedon Oct 10, 2025
@chjackson Dear Professor Chris Jackson: Thank you very much for your careful and patient response. This has been of great help to my studies.
yinglittxs commentedon Oct 12, 2025
@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
chjackson commentedon Oct 13, 2025
@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.
chjackson commentedon Oct 13, 2025
I'm now locking this issue, as it has turned into a general "msm help" thread, which wasn't intended.