## Importing mortality data from the USA available on the Human Mortality Database (HMD):
data(USA)
## Selecting the exposure and the death count of the year 2010, ranging from 0 to 90 years old:
USA2010 = USA[USA$Year == 2010,]
x = 0:90
Ex = USA2010$Ex.Male[x+1]
Dx = USA2010$Dx.Male[x+1]
## Fitting a lognormal HP model:
fit = hp(x = x, Ex = Ex, Dx = Dx, model = "lognormal",
M = 1000, bn = 0, thin = 10)
## Applying the closing function with different methods:
close1 = hp_close(fit, method = "hp", x0 = 90)
close2 = hp_close(fit, method = "plateau", x0 = 90)
close3 = hp_close(fit, method = "linear", x0 = 80,
new_Ex = USA2010$Ex.Male[82:101],
new_Dx = USA2010$Dx.Male[82:101])
close4 = hp_close(fit, method = "gompertz", x0 = 70,
new_Ex = USA2010$Ex.Male[72:101],
new_Dx = USA2010$Dx.Male[72:101],
k = 5, max_age = 120)
#### Using the other functions available in the package with the 'ClosedHP' object:
## qx estimation (See "?fitted.HP" in the BayesMortalityPlus package for more options):
fitted(close2)
## life expectancy (See "?expectancy.HP" for more options)
expectancy(close3, age = 0:110)
## plotting (See "?plot.HP" in the BayesMortalityPlus package for more options):
plot(close4)
g <- plot(list(close4, fit),
colors = c("seagreen", "blue"),
labels = c("Closed", "Model"))
# plotly::ggplotly(g)
Run the code above in your browser using DataLab