timriffe / DemoTools

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

NAs in nLx for extreme mortality pattern #260

Closed IvanWilli closed 2 years ago

IvanWilli commented 2 years ago

DemoTools! I have this awful rates, sorry for that.

Age <- c(0,1,seq(5,100,5)) nMx <- c(0.186047704353247, 0.0270846648829309, 0.439910705473096, 0.332004589858868, 0.265007871720042,0.29943066631364, 0.109541617697591,0.207610661915444, 0.42505214052481, 1.0546083578387, 1.41116978385487, 0.699306127683709, 0.866759908118877,1.32439400632662,1.76219369745878, 1.29032837217935, 1.06243334664413, 0.828497458361605, 0.69178645362446, 0.577636337776628,0.482323405682125, 0.431198939199844) %>% as.double()

The function lt_abridged stops because last nLx gets NA, and not passes the condition on all(nLx>=0, nLx[-n] < (radix*N)). That´s because Kannisto fails to fit and gives an extended rates of NA for ages greater than OAG. If extrapLaw = "Gompertz" it works.

lt_abridged(nMx=as.double(nMx), Age=Age, Sex = "f", extrapLaw = "Gompertz")

It´s the same when OAG=T or OAG=F.

To consider for future realeases, maybe it can switch with a try, giving a message as return, or something like that.

Thanks!

timriffe commented 2 years ago

Thanks @IvanWilli can you clarify the desired behavior? 1) make it just work for Kannisto, 2) switch to Gompertz on failure, 3) something else?

IvanWilli commented 2 years ago

Hi, I think option 2 is good enough. This situation ocurred in a pattern by age very rare, not common, so I think is a good solution for extreme cases. Best,

timriffe commented 2 years ago

@IvanWilli Can you check the new extrap branch to see if this tiny change behaves as expected for your pathological cases? The example rates you gave here really are one-of-a-kind I hope.