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

Warnings during model fitting #91

Closed chjackson closed 7 months ago

chjackson commented 3 years ago

Occasionally flexsurvreg will print a warning "NaNs produced" while fitting a model. This can result from evaluating the "p" or "d" function for a distribution when parameters visited during optimisation are on the boundary of the parameter space. This is confusing to users, so should be guarded against somehow.

Not sure about using suppressWarnings. This might get rid of helpful warnings.

Instead, flexsurvreg could detect parameters that are on the boundary of the parameter space before calling these functions. Then what to do? Could return a likelihood of zero, which will force the optimiser to move on. But that might misrepresent the behaviour of the likelihood near the boundary. Or it could assume smoothness, and replace, e.g. a zero rate with a small number .Machine$double.eps?

chjackson commented 3 years ago

In 8bb7c96 this now silences all warnings matching "NaNs produced" from calling PDF and CDF functions while evaluating the likelihood. I'll leave this issue open, in case anyone familiar with this kind of problem has a better suggestion.

anniekellner commented 3 years ago

Using method = Nelder-Mead helped me reduce the warnings and gave me slightly better estimates