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

qgengamma() with Q = 0 #53

Closed dincerti closed 6 years ago

dincerti commented 6 years ago

There may be a bug with the quantile function for the generalized gamma distribution with Q = 0. For example, the code

qgengamma(pgengamma(.5, mu = 2, sigma = 2, Q = 0), mu = 2, sigma = 2, Q = 0)

does not return 0.5. This may be related to line 210 in GenGamma.R:

ret[ind][Q==0] <- qlnorm(p[Q==0], mu[Q==0], 1/sigma[Q==0]^2)

oliver-diaz commented 6 years ago

The function pgengamma with Q=0 does coincide with plnorm. The function qgenamma with Q=0, mu=mu and sigma=sigma corresponds to qlnorm with meanlog=mean, sdlog = 1/(sigma^2). The following example illustrates the issue:

plot(seq(0.01,.99,.01),qlnorm(seq(0.01,.99,.01),meanlog = 2,sdlog = 2)) lines(seq(0.01,.99,.01),qgengamma(seq(0.01,.99,.01),mu = 2,sigma = sqrt(1/2),Q=0),col="blue")

chjackson commented 6 years ago

Thanks both - fixed in 49dc00f

dincerti commented 6 years ago

Many thanks.