timriffe / DemoTools

Tools for the evaluation, adjustment, and standardization of demographic data
https://timriffe.github.io/DemoTools
Other
59 stars 31 forks source link

Extending w/ Gompertz #263

Closed IvanWilli closed 2 years ago

IvanWilli commented 2 years ago

Hi! When trying to extend a set of rates to 100+ using a Gompertz or Makeham law, the last rate in the OAG seems too low. What I see debugging is that ~line 112 in #lt_abridged, the extension works ok in an exponential way, but then in the conditional workflow to determinate the M(OAG) there is a restriction, trying e(OAG)~2.5 in the cases I saw. In past months this function worked ok in these situations, maybe something added recently?

Thanks!

Here an example:

library(DemoTools)
nMx <- c(0.143053494102448, 0.0273092042963039, 0.00580804, 0.00343971, 
          0.00468458, 0.00584242, 0.00653677, 0.00697978, 0.00752011, 0.00822754, 
          0.00961052, 0.01265554, 0.01839948, 0.02909286, 0.04703128, 0.07747985, 
          0.12649477, 0.20138711, 0.31355304)
Age <- c(0L, 1L, 5L, 10L, 15L, 20L, 25L, 30L, 35L, 40L, 45L, 50L, 55L, 
          60L, 65L, 70L, 75L, 80L, 85L)
fit_nMx <- lt_abridged(nMx = nMx,
            Age = Age,
            Sex = "f",
            extrapLaw = "gompertz",
            extrapFrom = 80,
            extrapFit = c(60,65,70,75, 80),
            OAnew = 100,
            OAG=F)
plot(Age, nMx,xlim=c(0,100),ylim=c(0,1.5),col=2)
points(fit_nMx$Age, fit_nMx$nMx)
timriffe commented 2 years ago

My take is that this is due to using the midpoint rule for nAx, which doesn't go well when extrapolated rates get very high. In this case a Gompertz extrap out to age 130 will give very high rates, but paired with nAx = 2.5. axmethod is "pas" by default. If you set it to "un" this problem goes away. Is this sufficient on your end?