Example: Life Tables

This example is taken from Chiang (1968). The cohort life table has thirteen equally spaced intervals, so age[0] is set to -5.0. Similarly, the probabilities of death prior to the middle of the interval are all taken to be 0.5, so a[0] is set to -1.0.
using System;
using Imsl.Stat;
using PrintMatrix = Imsl.Math.PrintMatrix;
using PrintMatrixFormat = Imsl.Math.PrintMatrixFormat;

public class LifeTablesEx1
{
    public static void  Main(String[] args)
    {
        int[] nCohort = {270, 268, 264, 261, 254, 251, 248, 232,
            166, 130, 76, 34, 13};
        double[] age = new double[nCohort.Length + 1];
        double[] a = new double[nCohort.Length];
        
        age[0] = - 5.0;
        a[0] = - 1.0;
        
        LifeTables lt = new LifeTables(nCohort, age, a);
        double[,] table = lt.GetLifeTable();
        
        PrintMatrixFormat pmf = new PrintMatrixFormat();
        String[] cols = {"Age", "PDHALF", "Alive",
            "Deaths", "Death Rate", "P(D)", "Std(P(D))", "P(S)", "Std(P(S))",
            "Lifetime", "Std(Life)", "Time Units"};
        pmf.SetColumnLabels(cols);
        pmf.NumberFormat = "0.0####";
        PrintMatrix pm = new PrintMatrix("Life Table");
        pm.SetPageWidth(40);
        pm.Print(pmf, table);
    }
}

Output

           Life Table
    Age   PDHALF  Alive  Deaths  
 0  0.0    0.5    270.0   2.0    
 1  5.0    0.5    268.0   4.0    
 2  10.0   0.5    264.0   3.0    
 3  15.0   0.5    261.0   7.0    
 4  20.0   0.5    254.0   3.0    
 5  25.0   0.5    251.0   3.0    
 6  30.0   0.5    248.0   16.0   
 7  35.0   0.5    232.0   66.0   
 8  40.0   0.5    166.0   36.0   
 9  45.0   0.5    130.0   54.0   
10  50.0   0.5    76.0    42.0   
11  55.0   0.5    34.0    21.0   
12  60.0   0.5    13.0    13.0   

    Death Rate   P(D)    Std(P(D))   P(S)    
 0     NaN      0.00741   0.00522   1.0      
 1     NaN      0.01493   0.00741   0.99259  
 2     NaN      0.01136   0.00652   0.97778  
 3     NaN      0.02682   0.01      0.96667  
 4     NaN      0.01181   0.00678   0.94074  
 5     NaN      0.01195   0.00686   0.92963  
 6     NaN      0.06452   0.0156    0.91852  
 7     NaN      0.28448   0.02962   0.85926  
 8     NaN      0.21687   0.03199   0.61481  
 9     NaN      0.41538   0.04322   0.48148  
10     NaN      0.55263   0.05704   0.28148  
11     NaN      0.61765   0.08334   0.12593  
12     NaN      1.0       0.0       0.04815  

    Std(P(S))  Lifetime  Std(Life)  Time Units  
 0   0.0       43.18519   0.69929     1345.0    
 1   0.00522   38.48881   0.67074     1330.0    
 2   0.00897   34.03409   0.62303     1312.5    
 3   0.01092   29.39655   0.59401     1287.5    
 4   0.01437   25.1378    0.54028     1262.5    
 5   0.01557   20.40837   0.52367     1247.5    
 6   0.01665   15.625     0.51485     1200.0    
 7   0.02116   11.53017   0.49815     995.0     
 8   0.02962   10.12048   0.46017     740.0     
 9   0.03041   7.23077    0.4328      515.0     
10   0.02737   5.59211    0.43607     275.0     
11   0.02019   4.41176    0.41671     117.5     
12   0.01303   2.5        0.0         32.5      


Link to C# source.