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

Age as the time-scale #140

Closed Xueke1001 closed 1 year ago

Xueke1001 commented 1 year ago

Hi Chris,

I worked with flexsurvspline and tried to figure out incident rate using age as time-scale.

I used brcancer data and coded as following:

flexsurvspline(Surv(age_in,age_out,censrec)~hormon,type="interval2",data=brcancer,k=3) then I got a warning "Error in optim(type = "interval2", method = "BFGS", par = c(gamma0 = 0, : initial value in 'vmmin' is not finite"

I did similar analysis with flexsurvreg and it worked. flexsurvreg(Surv(age_in,age_out,censrec)~hormon,data=brcancer,dist="gompertz")

Can this be attained by flexsurvspline?

Thanks in advance

XK

chjackson commented 1 year ago

It is difficult to determine initial values for Royston-Parmar models sometimes. If this error happens you will have to specify the inits argument to flexsurvspline by hand, and try to identify initial values which will give a non-zero likelihood (i.e. a finite log likelihood).

You could fit a Weibull model as a starting point, since the flexsurvspline model with k=0 is equivalent to a Weibull. Then determine what gamma0 and gamma1 should be in terms of the Weibull shape and scale (see help(flexsurvspline)). That should get you a working flexsurvspline model with k=0.

Then try to build up the spline complexity bit by bit, starting with k=1 say with those initial values for gamma0 and gamma1, and setting gamma2=0, etc... The covariate effects should not be very different for different k.

Xueke1001 commented 1 year ago

Thank you, that's very helpful