## Selecting the log mortality rate of the 1990 male population ranging from 0 to 100 years old
USA1990 = USA[USA$Year == 1990,]
x = 0:100
Ex = USA1990$Ex.Male[x+1]
Dx = USA1990$Dx.Male[x+1]
y = log(Dx/Ex)
## Fitting DLM
fit = dlm(y, ages = 0:100, M = 100)
## Plotting the life tables:
plot(fit)
## Now we are starting from 20 years
# \donttest{
fit2 = dlm(y[21:101], Ft = 1, Gt = 1, ages = 20:100, M = 100)
plot(fit2, plotIC = FALSE)
## To plot multiples life tables see ?plot.list
plot(list(fit, fit2), age = 20:100,
plotData = FALSE,
colors = c("red", "blue"),
labels = c("1", "2"))
# }
Run the code above in your browser using DataLab