## Example of transforming the dataset to fit the function:
## Importing mortality data from the USA available on the Human Mortality Database (HMD):
data(USA)
## Calculating the mortality rates for the general population:
require(dplyr)
require(tidyr)
require(magrittr)
USA %>% mutate(mx = USA$Dx.Total/USA$Ex.Total) -> data
data %>%
filter(Age %in% 18:80 & Year %in% 2000:2015) %>%
mutate(logmx = log(mx)) %>%
dplyr::select(Year,Age,logmx) %>%
pivot_wider(names_from = Year, values_from = logmx) %>%
dplyr::select(-Age) %>%
as.matrix() %>%
magrittr::set_rownames(18:80) -> Y
## Fitting the model
fit = blc(Y = Y, M = 100, bn = 20)
print(fit)
## Viewing the results
plot(fit, ages = 18:80)
plot(fit, parameter = "beta", ages=18:80)
improvement(fit)
Run the code above in your browser using DataLab