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

pgompertz does not respect asymptote when q is infinite #34

Closed jrdnmdhl closed 7 years ago

jrdnmdhl commented 7 years ago

For the Gompertz distribution, it is possible to have survival probabilities which reach a non-zero asymptote as q -> Inf. However, pgompertz incorrectly will return zero if you pass an infinite value for q.

> pgompertz(9999999,-.02,.02,lower.tail=F)
[1] 0.3678794
> pgompertz(Inf,-.02,.02,lower.tail=F)
[1] 0
jrdnmdhl commented 7 years ago

It looks like the tests for pgompertz are actually expecting that S(t) = 0 as t -> Inf. Should that be the case? My expectation is that providing an infinite value for t should return the value of the limit.

test_that("Gompertz with chance of living forever",{
    shape <- -0.6; rate <- 1.8
    x <- c(0.8, 0.9, 0.97, 0.99)
    expect_equal(qgompertz(x, shape=shape, rate=rate), c(1.28150707286845, 2.4316450975351, Inf, Inf))
                                        # qgeneric(pgompertz, p=x, shape=shape, rate=rate) # won't work - needs smoothness
    expect_equal(pgompertz(Inf, shape=shape, rate=rate), 1)
})