Example: Kaplan Meier Empirical CDF

This example illustrates the K-M procedure. Assume 20 units are on life test and 6 failures occur at the following times: 10, 32, 56, 98, 122, and 181 hours. There were 4 working units removed from the test for other experiments at the following times: 50, 100, 125, and 150 hours. The remaining 10 working units were removed from the test at 200 hours. The K-M estimates for this life test are:

R(10) = 19/20
R(32) = 19/20 x 18/19
R(56) = 19/20 x 18/19 x 16/17
R(98) = 19/20 x 18/19 x 16/17 x 15/16
R(122) = 19/20 x 18/19 x 16/17 x 15/16 x 13/14
R(181) = 19/20 x 18/19 x 16/17 x 15/16 x 13/14 x 10/11

using System;
using Imsl.Stat;
using Imsl.Math;

public class KaplanMeierECDFEx1
{

    public static void  Main(String[] args)
    {
        double[] y = {10.0, 32.0, 56.0, 98.0, 
                      122.0, 181.0, 50.0, 100.0, 
                      125.0, 150.0, 200.0
                   };
        int[] freq = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10};
        int[] censor = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1};
        
        KaplanMeierECDF km = new KaplanMeierECDF(y);
        km.SetFrequency(freq);
        km.SetCensor(censor);
        double[] fx = km.EvaluateCDF();
        
        int ntimes = km.NumberOfPoints;
        Console.Out.WriteLine("Number of points = " + ntimes);
        
        double[] x = km.GetTimes();
        PrintMatrix p = 
         new PrintMatrix("CDF = 1 - survival of life test subjects");
        p.Print(fx);
        p.SetTitle("Times of change in CDF");
        p.Print(x);
    }
}

Output

Number of points = 6
CDF = 1 - survival of life test subjects
           0          
0  0.05               
1  0.1                
2  0.152941176470588  
3  0.205882352941177  
4  0.262605042016807  
5  0.329640947288006  

Times of change in CDF
    0   
0   10  
1   32  
2   56  
3   98  
4  122  
5  181  


Link to C# source.