chjackson / flexsurv

The flexsurv R package for flexible parametric survival and multi-state modelling
http://chjackson.github.io/flexsurv/
55 stars 27 forks source link

simulate.flexsurvreg appears to simulate survival times before left-truncation (start) times #192

Closed mikesweeting closed 2 weeks ago

mikesweeting commented 5 months ago

Hi,

I'm trying to simulate survival times for a bunch of individuals conditional on them surviving up to their (individual-specific) censoring time. I'm using simulate.flexsurvreg() passing a vector of left-truncation times to the start argument. But some of the simulated times that are returned are before the left-truncation times.

Here is a reproducible example that shows the issue (I'm using version 2.3). Please let me know if I'm doing something wrong. Thanks!

library(flexsurv)
fit <- flexsurvreg(formula = Surv(futime, fustat) ~ rx, data = ovarian, dist="weibull")
nd <- ovarian
sim <- simulate(fit, seed=1002, newdata=nd, nsim = 2, start = nd$futime)

## Not all the simulated times are greater than the left trunction (start) times
sim$time_1 >= nd$futime
sim$time_2 >= nd$futime

## The same thing occurs with tidy = T
sim2 <- simulate(fit, seed=1002, newdata=nd, nsim = 2, start = nd$futime, tidy = T)
## Not all the simulated times are greater than the left trunction (start) times
sim2$time >= sim2$futime
chjackson commented 5 months ago

Thanks for spotting this - I think it is now fixed in https://github.com/chjackson/flexsurv/commit/353aad2497ef35db69425a9b2b06dcaeadf37df4 .

mikesweeting commented 4 months ago

Thanks for fixing this! Do you know when this will get passed on to the next CRAN release?

chjackson commented 4 months ago

Just a couple of open issues to resolve, then I'm happy to push a bug fix release to CRAN.