## Importing mortality data from the USA available on the Human Mortality Database (HMD):
data(USA)
## Selecting the exposure and death count of the 2010 male population 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 binomial model
fit = hp(x = x, Ex = Ex, Dx = Dx)
print(fit)
fit$summary
fit$info
## Fitting lognormal model
## Specifying number of iterations, burn-in, thinning and the initial value of sigma2
fit = hp(x = x, Ex = Ex, Dx = Dx, model = "lognormal",
M = 1000, bn = 0, thin = 10, sigma2 = 0.1)
summary(fit)
## Fitting poisson model
## Specifying the prior distribution parameters for B and E and fixing K as 0.
fit = hp(x = x, Ex = Ex, Dx = Dx, model = "poisson",
m = c(NA, 0.08, NA, NA, 9, NA, NA, NA),
v = c(NA, 1e-4, NA, NA, 0.1, NA, NA, NA), K = 0)
summary(fit)
## Using other functions available in the package:
## plotting (See "?plot.HP" in the BayesMortalityPlus package for more options):
plot(fit)
## qx estimation (See "?fitted.HP" in the BayesMortalityPlus package for more options):
fitted(fit)
## chain's plot (See "?plot_chain" for more options):
plot_chain(fit)
Run the code above in your browser using DataLab