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

Error in calculating log-hazard under lognormal distribution (hlnorm) #101

Closed harrisonreeder closed 3 years ago

harrisonreeder commented 3 years ago

Hi! I am using the package version 1.1.1 of the flexsurv::hlnorm function, and think there is a conceptual error where the function outputs the same unlogged value whether the 'log' input is set to TRUE or FALSE. When I came here to flag the issue I noticed that recently you changed the method of calculating the hazard in this function, but the change doesn't seem like it would have resolved this issue. Below is a simple reproduction:

`> flexsurv::hlnorm function (x, meanlog = 0, sdlog = 1, log = FALSE) { h <- dbase("lnorm", log = log, x = x, meanlog = meanlog, sdlog = sdlog) for (i in seq_along(h)) assign(names(h)[i], h[[i]]) ret[ind] <- dlnorm(x, meanlog, sdlog)/plnorm(x, meanlog, sdlog, lower.tail = FALSE) ret } <bytecode: 0x7f8e6fad6318>

> flexsurv::hlnorm(1,log=FALSE) [1] 0.7978846 > flexsurv::hlnorm(1,log=TRUE) [1] 0.7978846` Thought you might want to take a look! Thanks for great work, I love this package.
chjackson commented 3 years ago

Silly bug, it was also in Hlnorm , hgamma and Hgamma. Thanks for the report, fixed in https://github.com/chjackson/flexsurv-dev/commit/2b0f6b8f5b52a0029b4a2107b7e749b4a326c623