%% Convert the Life Table dx Series After Fitting and Generating the Life Table Series
% Load the life table data file.

load us_lifetable_2009

%
% Calibrate life table from survival data with the default Heligman-Pollard parametric model.

a = lifetablefit(x,lx)

%
% Generate life table series from the calibrated mortality model.

qx = lifetablegen((0:120),a);
display(qx(1:20,:))

%
% Convert life table series into life tables with forced termination.

[~,~,dx] = lifetableconv((0:120),qx,'qx');
display(dx(1:20,:))

%
% Plot the dx series and display the legend. The series dx is the number of people who die out of 100,000 alive at birth between age x and the next age in the series.

plot((0:119),dx(1:end-1,:));
legend(series, 'location', 'northwest');
title('\bfLife Table Yearly Decrements');
xlabel('Age');
ylabel('Number Dying within a Given Year');

% Copyright 2015 The MathWorks, Inc.