chjackson / flexsurv

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

rmst predictions with orthogonalised spline basis #194

Closed irtimmins closed 1 month ago

irtimmins commented 1 month ago

Hi Chris, currently getting error messages when trying to evaluate rmst/mean survival time estimates (type = "rmst" or "response") using predict() with the new spline = "splines2ns" option. Hazard/cumulative hazards and survival probabilities work fine I think.

test_ns <- flexsurvspline(Surv(futime, fustat)~age, 
                               data = ovarian, 
                               k = 6,
                               spline="splines2ns")

predict(test_ns, type = "surv", times = 500, newdata = tibble(age = 50))
# A tibble: 1 × 2
  .eval_time .pred_survival
       <dbl>          <dbl>
1        500          0.876

predict(test_ns, type = "rmst", times = 500, newdata = tibble(age = 50))

Error in dbase.survspline(q = q, gamma = gamma, knots = knots, scale = scale,  : 
  matrix knots not supported with spline="splines2ns"

Thanks, Iain

chjackson commented 1 month ago

I think this should now be fixed in https://github.com/chjackson/flexsurv/commit/d9027980ad6eb1d638672ccdd2e9b58ef16cfcf1 .

Fitting and predicting from the splines2ns models is currently slower than the Royston-Parmar version, as the latter are implemented in Rcpp, but that could be remedied in the future with a bit of work.

irtimmins commented 1 month ago

Many thanks! 😃