## Importing mortality data from the USA available on the Human Mortality Database (HMD):
data(USA)
## Selecting the log mortality rate of the 1990 male population ranging from 0 to 100 years old
USA1990 = USA[USA$Year == 1990,]
x = 0:90
Ex = USA1990$Ex.Male[x+1]
Dx = USA1990$Dx.Male[x+1]
y = log(Dx/Ex)
## Fit poisson and lognormal HP model and DLM
fit = hp(x = x, Ex = Ex, Dx = Dx, model = "poisson",
M = 2000, bn = 1000, thin = 1)
fit2 = dlm(y, M = 100)
## Plot multiples life tables
plot(list(fit, fit2),
age = 0:110, Ex = USA1990$Ex.Male,
plotIC = FALSE, colors = c("red", "blue"),
labels = c("HP Poisson", "DLM"))
## Plot ClosedHP and ClosedDLM objects
close1 = hp_close(fit, method = "hp", x0 = 90)
close2 = dlm_close(fit2, method = "plateau")
plot(list(fit, fit2, close1, close2),
plotIC = FALSE, colors = c("red", "blue", "green", "purple"),
labels = c("HP", "DLM", "ClosedHP", "ClosedDLM"))
Run the code above in your browser using DataLab