Closed larpSTATGL closed 1 year ago
I passed the error msg by setting zero-death-rates to 0.0001
bexbbdtb <- read.delim2("https://bank.stat.gl:443/sq/d512a451-20e3-4d64-8132-b125095f9468.relational_table") %>% clean_names() %>% select(time,sex=gender,age,measure,value=life_expectancy) %>% filter(measure=="qx" & age>=0 & age<=90) %>% mutate(value=round(as.numeric(value),4)) %>% mutate(value=ifelse(value==0,0.0001,value))
Hi Marius,
I am getting an error message, that I simply cannot figure out, how to solve:
Error in model.LeeCarter(data = mx.data, x = x, y = y, verbose = FALSE) : The input data contains death rates equal to zero at various ages.
I am staying close to your example - on data from the Greenlandic Statbank, and would very much appreciate if you could give me a push in the right direction
best regards
Lars
library(tidyverse) library(MortalityForecast)
bexbbdtb <- read.delim2("https://bank.stat.gl:443/sq/d512a451-20e3-4d64-8132-b125095f9468.relational_table") %>% clean_names() %>% select(time,sex=gender,age,measure,value=life_expectancy) %>% filter(measure=="qx" & age<=90) %>% mutate(value=round(as.numeric(value),4))
x <- 0:90 # Ages y <- 1999:2021 # Years h <- 20 # forecasting horizon
D <- bexbbdtb %>% filter(sex=="m") %>% pivot_wider(names_from = time, values_from = value) %>% select(-sex,-age,-measure) %>% as.matrix() rownames(D)<-c(0:90)
B <- bexbbdtb %>% filter(sex=="f") %>% pivot_wider(names_from = time, values_from = value) %>% select(-sex,-measure,-age) %>% as.matrix() rownames(B)<-c(0:90)
M <- MortalityForecast::do.MortalityModels(data = D, data.B = B, x = x, y = y, data.in = "qx", models = "LeeCarter")