## Importing mortality data from the USA available on the Human Mortality Database (HMD):
data(USA)
## Selecting the log mortality rate of the year 2000, ranging from 0 to 100 years old:
USA2000 = USA[USA$Year == 2000,]
x = 0:100
Ex = USA2000$Ex.Total[x+1]
Dx = USA2000$Dx.Total[x+1]
y = log(Dx/Ex)
## Fitting dlm
fit = dlm(y, M = 100)
## Estimating the death probabilities (qx)
fitted(fit)
Run the code above in your browser using DataLab