## Importing mortality data from the USA available on the Human Mortality Database (HMD):
data(USA)
## Selecting the exposure and death count of the 2010 and 2013 male populations 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]
USA2013 = USA[USA$Year == 2013,]
Ex2 = USA2013$Ex.Male[x+1]
Dx2 = USA2013$Dx.Male[x+1]
## Fitting HP model for 2010 data and calculating the mortality rates of 2013
fit = hp(x = x, Ex = Ex, Dx = Dx,
M = 1000, bn = 0, thin = 10)
tx_2013 = 1 - exp(-Dx2/Ex2)
## Mixing fitted model and mortality rates of 2013:
mix <- hp_mix(fit, tx_2013, x0_prior = 0, x0_post = 0, mix_age = c(50,90),
max_age = 90)
## Obtaining the new estimated mortality table (after mixture):
qx_mix<- apply(mix$qx, 2, median, na.rm = TRUE)
qx_mix
Run the code above in your browser using DataLab