%% Prepare Life Table Data Using the qx Series and Generate the qx Life Table
% Load the life table data file.

load us_lifetable_2009

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

[~, lx] = lifetableconv(x, qx, 'qx');

%
% Calibrate the life table from survival data using the default heligman-pollard parametric model.

a = lifetablefit(x, lx)

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

qx = lifetablegen((0:100), a)

%
% Plot the qx series and display the legend. The series qx is the conditional probability that a person at age x will die between age x and the next age in the series.

plot((0:100), log(qx));
legend(series, 'location', 'southeast');
title('Conditional Probability of Dying within One Year of Current Age');
xlabel('Age');
ylabel('Log Probability');

% Copyright 2015 The MathWorks, Inc.