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

Implementation of optimizers other than those in optim #200

Open colinorourke opened 3 days ago

colinorourke commented 3 days ago

It would be a great enhancement to allow users to access additional optimizers, such as those wrapped by the optimx package, if it is available. This would open the door to a wider array of optimization methods and even enable users to compare the performance of multiple routines, which can be particularly useful for challenging models.

I understand the hesitation to introduce a hard dependency, but optimx could be included as a suggested package. This way, core functionality would remain unaffected for users who don’t need this feature. In my experience, while BFGS and other optim methods often perform adequately, they can struggle in certain scenarios where alternatives might succeed. Allowing access to these tools would enhance the versatility and robustness of flexsurv.

chjackson commented 1 day ago

I agree this would be a beneficial feature, if it were implemented in a clean modular way.

For advanced users who want to might try different optimisation algorithms, it's already feasible to do this with a bit of work. You could define your own objective function using flexsurvreg(...,inits=...,fixedpars=TRUE) to compute (but not maximise) the likelihood given initial values. That could be maximised with any algorithm.

Then to make use of the output summary/prediction functions in flexsurv, you would need to take a model object fitted using one of the built-in algorithms, then substitute the new estimates into the relevant components of the object (see https://chjackson.github.io/flexsurv/reference/flexsurvreg.html#value).