www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EmpiricalHazardFunctionofRightCensoredDataExample.m

    %% Empirical Hazard Function of Right-Censored Data  
% Compute and plot the hazard function of simulated right-censored survival
% data.   

% Copyright 2015 The MathWorks, Inc.


%% 
% Generate failure times from a Birnbaum-Saunders distribution. 
rng default  % for reproducibility
failuretime = random('birnbaumsaunders',0.3,1,100,1);  

%% 
% Assuming that the end of the study is at time 0.9, generate a logical
% array that indicates simulated failure times that are larger than 0.9
% as censored data, and store this information in a vector. 
T = 0.9;
cens = (failuretime>T);  

%% 
% Plot the empirical hazard function for the data. 
ecdf(failuretime,'function','cumulative hazard',...
'censoring',cens,'bounds','on');