chjackson / flexsurv

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

Improve dbase.survspline performance #109

Closed ndunnewind closed 2 years ago

ndunnewind commented 2 years ago

Calculating the CI of e.g. the median of a flexsurvpline model takes quite some time.

library(flexsurv)
spl <- flexsurvspline(Surv(recyrs, censrec) ~ group, data = bc, k = 1, scale = "odds")
system.time(summary(spl, type = "median"))

This takes around 11 seconds on my system.

   user  system elapsed 
  11.01    0.01   11.04

This PR improves the performance of the matrix replications in dbase.survspline (based on https://stackoverflow.com/a/13035504), after which the summary call takes around 7 seconds.

   user  system elapsed 
   7.16    0.00    7.15
ndunnewind commented 2 years ago

I thought nret was passed to rep as times instead of length in the original implementation. I just fixed my suggestion, which still significantly improves performance.

   user  system elapsed 
   8.17    0.00    8.16
chjackson commented 2 years ago

Thanks, merged!