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

flexsurvspline doesn't work with Surv(type='interval2') data #4

Closed pdmetcalfe closed 9 years ago

pdmetcalfe commented 9 years ago

Using the latest github version.

library("flexsurv")
library("survival")

set.seed(1234)

num.pts <- 100
base.median <- 2 * 28

base.rate   <- log(2) / base.median

times <- rexp(num.pts, base.rate)

before <- 28 * floor(times / 28)
after <- before + 28

got <- data.frame(before=before, after=after)

## this doesn't work
flexsurvspline(Surv(before, after, type='interval2') ~ 1, data=got)

## this doesn't work
flexsurvspline(Surv(before + 0.001, after, type='interval2') ~ 1, data=got)

## this doesn't converge
flexsurvreg(Surv(before + 0.001, after, type='interval2') ~ 1,
            data=got, dist='weibull')

## this works
survreg(Surv(before + 0.001, after, type='interval2') ~ 1,
        data=got, dist='weibull')
chjackson commented 9 years ago

Thanks - I'm on the case. The difficulty with the spline model is that the initial values are chosen by Cox regression, and if all the data are censored, coxph() doesn't work. Until I fix, this can be worked around by setting your own initial values.

The problem with flexsurvreg here is difficulty calculating the Hessian for its preferred Weibull parameterisation. Sometimes this can be fixed by tweaking the optimisation control options, but I can't immediately fix it in this case. Anyway on the todo list it goes.

pdmetcalfe commented 9 years ago

All subjects have an event, though (for the spline question)?

Would using both 1 and 3 as event indicators get good enough initial values, or perhaps when event=3 the midpoint of the interval?

chjackson commented 9 years ago

All subjects have an event, but coxph still doesn't support interval censoring. Imputing an event time at the midpoint would be a good idea, I think. And perhaps if everyone is right-censored, impute event times at the censoring time plus a bit. Probably good enough to get an initial value with a finite log-likelihood.

chjackson commented 9 years ago

I think I've fixed the issue with interval censoring, by imputing event times to get the inits. Plotting the fitted model object still won't work, as survfit won't work, but I'm less bothered about that.