%Actuarial (LifeTable Estimator)
%
%Data set from Gehan 1969 
%2418 males with Angina Pectoris
close all

t=0:15; %intervals [0,1), [1, 2), ..., [15, 16)
li = [0 39 22 23 24 107 133 102 68 64 45 53 33 27 23 0]; %censored
di = [456 226 152 171 135 125 83 74 51 42 43 34 18 9 6 0]; %failed
entering(1)=2418; %entering at time 0
for i = 2:16
    entering(i)= entering(i-1) - li(i-1) - di(i-1); %entering subsequant intervals
end
for i = 1:16
    atrisk(i)= entering(i)-li(i)/2;  %at risk adjusted by censored data
end
prosurv = [1 (atrisk - di)./atrisk];
shat = cumprod(prosurv);
stairs([t 16],shat)

table=[t' li' di' entering' atrisk']  

table2=[t' prosurv(1:16)' shat(1:16)']