robjhyndman / demography

demography package for R
https://pkg.robjhyndman.com/demography
73 stars 25 forks source link

Unable to use lca for mortality information coming from Switzerland #43

Closed ANUGAR closed 4 years ago

ANUGAR commented 4 years ago

Hello, I'm trying to use the lca function for an analysis with information for the case of Switzerland. I start by downloading the data with the command Mortality_info<-hmd.mx("CHE","username","password","CHE") (at this point I get a message saying something about NAs introduced for some convertion, but I get the message for other countries as well and I have no further issue.)

Later I just leave out older ages to avoid issues with nas/mortality errors through the command Info_n<-extract.ages(Mortality_info,ages=0:90)

Then I try to run the function by using res<-lca(Info_n,series="male",adjust="e0",years=1950:max(Info_n$year)) but I get the message: Error in svd(clogrates) : infinite or missing values in 'x'

No matter if I do it for males or females or even if I change other parameters like years or ages, the function returns the same error though I see no missing values. I have tried to solve the problem unsuccessfully, and I do not really know what to do to be able to run the function properly. Do you have any ideas of why this is happening and how to solve it? It's really important.
Thanks in advance.

robjhyndman commented 4 years ago

There are some zero mortality rates in the data, and lca() is based on log rates. Set interpolate=TRUE and these zeros will be replaced by estimated rates.

ANUGAR commented 4 years ago

Hello, I don't seem to be able to see where the zero rates are in the info, but it certainly solved the problem. Thanks a lot!

On Sat, May 23, 2020 at 8:34 AM Rob J Hyndman notifications@github.com wrote:

There are some zero mortality rates in the data, and lca() is based on log rates. Set interpolate=TRUE and these zeros will be replaced by estimated rates.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/robjhyndman/demography/issues/43#issuecomment-632995148, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANW3Q6X3M5AKG4KIEGIEFPTRS5U6RANCNFSM4NIBTCGA .

-- "Not all who wander are lost"- J. R. R. Tolkien

robjhyndman commented 4 years ago

To find the zeros:

library(tidyverse)
as.data.frame(Mortality_info$rate$male) %>%
  rownames_to_column("age") %>%
  pivot_longer(-age, names_to = "year", values_to = "mxt") %>%
  filter(mxt==0)
#> # A tibble: 174 x 3
#>    age   year    mxt
#>    <chr> <chr> <dbl>
#>  1 3     2016      0
#>  2 9     2012      0
#>  3 11    2006      0
#>  4 95    1887      0
#>  5 96    1877      0
#>  6 97    1878      0
#>  7 97    1883      0
#>  8 97    1885      0
#>  9 97    1886      0
#> 10 97    1890      0
#> # … with 164 more rows

Created on 2020-05-24 by the reprex package (v0.3.0)