flexsurv-dev icon indicating copy to clipboard operation
flexsurv-dev copied to clipboard

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

Open mikesweeting opened this issue 8 months ago • 3 comments

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

mikesweeting avatar Jun 12 '24 08:06 mikesweeting