aphp / heemod

Markov Models for Health Economic Evaluations
https://aphp.github.io/heemod/
GNU General Public License v3.0
12 stars 1 forks source link

Transition probabilities from survival curves -> undefined parameters #14

Closed cbr13032024 closed 7 months ago

cbr13032024 commented 7 months ago

Hi,

I want to estimate time-inhomogenous transition probabilities from survival curves. Fitting survival curves with flexsurvreg using different distributions works, but this returns undefined (negative) parameters for some distributions (e.g. log-normal, generalized gamma), which cannot be used afterwards to build user-defined parametric distributions for extrapolation.

I tought this might have to do with different parametrizations across packages (so that I would need to transform the parameters before using them together with heemod comands), but as heemod uses flexsurv for survival, I am unsure if/how I have to transform the coefficients/parameters given by flexsurvreg, so that define_surv_dist works?

I would very much appreciate any help or directing me to the appropiate forum. Thanks in advance, CB

Detailed explanation: For a time-inhomogenous cDTSTM, I use published Kaplan Meier curves to reconstruct individual patient data, then use this data to fit survival curves (for transition probabilities). I try several distributions (weibull, exp, gamma, lnorm, llogis, gompertz, generalized gamma) for the fitting with flexsurvreg (to see which fits best) and plot each fit with the observed data (ggsurvplot, the plots look good). This works well, e.g. for generalized gamma:

fit_pfs_CAB_gengamma <- flexsurvreg(Surv(pfs_time, pfs_status) ~ 1,data = CAB_PFS,dist = "gengamma") 

ggsurvplot(fit_pfs_CAB_gengamma, data = CAB_PFS, break.time.by = 2, ggtheme = theme)

For this example, the flexsurvreg-given parameters of the generalized gamma are: mu=2.113, sigma: -0.799, Q=2.514. IPD data is available for 12 months, so I would like to use the generalized gamma distribution to extrapolate (model horizon: 60 months). To do this, I would use the parameters estimated with flexsurvreg to define my parametric distribution, e.g.:

dist_pfs_CAB_gengamma_temp <- flexsurvreg(Surv(pfs_time, pfs_status) ~ 1,data = CAB_PFS,dist = "gengamma")

dist_pfs_CAB_gengamma <- define_surv_dist(
  distribution = "gengamma", 
  mu=dist_pfs_CAB_gengamma_temp[["coefficients"]][["mu"]], 
  sigma=dist_pfs_CAB_gengamma_temp[["coefficients"]][["sigma"]], 
  Q=dist_pfs_CAB_gengamma_temp[["coefficients"]][["Q"]]
)

Plotting this, the dist_pfs_CAB_gengamma appears to be empty. I also cannot use this in the command _defineparameters afterwards for the transition probabilities. A negative sigma is not defined, although plotting the flexsurvreg fit before is successful. I have observed this issue with other distributions that would (potentially) provide a better fit, e.g. with log-normal (negative sdlog). Any help is appreciated.

KZARCA commented 7 months ago

Hi, did you try to add the times parameter ? plot(dist_pfs_CAB_gengamma, times = c(0:1000))

cbr13032024 commented 7 months ago

Thank you for the help. Yes, using the timesparameter still results in the plot being empty. Warnings are issued for each time point, e.g.:

1: In pgengamma_work(q, mu, sigma, Q, lower.tail, log.p) : Negative scale parameter "sigma" 2: In pgengamma_work(q, mu, sigma, Q, lower.tail, log.p) : Negative scale parameter "sigma"

etc. Plotting the defined distribution is more of a check for me - but hints at the undefined parameters creating an issue for heemod, although they are working fine with flexsurv. I am more concerned that I cannot use this defined distribution later in the model itself (run_model). That returns the error:

error in if (!all(rowSums(posC, dims = 2) <= 1)) { : missing value, where TRUE/FALSE is needed

(Might not be these exact words, because I had to translate the error message into English.)

Do you have any idea how I could avoid this?

KZARCA commented 7 months ago

Your scale parameter cannot be negative: from documentation of flexsurv::pgengamma

Vector of “scale” parameters. Note the inconsistent meanings of the term “scale” - this parameter is analogous to the (log-scale) standard deviation of the log-normal distribution, “sdlog” in dlnorm, rather than the “scale” parameter of the gamma distribution dgamma. Constrained to be positive.

I guess you must exponentiate sigma, as done by flexsurv:::print.flexsurvreg