| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
[f,x] = ecdf(y)
[f,x,flo,fup] = ecdf(y)
ecdf(...)
ecdf(ax,...)
[...] = ecdf(y,param1,val1,param2,val2,...)
[f,x] = ecdf(y) calculates the Kaplan-Meier estimate of the cumulative distribution function (cdf), also known as the empirical cdf. y is a vector of data values. f is a vector of values of the empirical cdf evaluated at x.
[f,x,flo,fup] = ecdf(y) also returns lower and upper confidence bounds for the cdf. These bounds are calculated using Greenwood's formula, and are not simultaneous confidence bounds.
ecdf(...) without output arguments produces a plot of the empirical cdf.
ecdf(ax,...) plots into axes ax instead of gca.
[...] = ecdf(y,param1,val1,param2,val2,...) specifies additional parameter/value pairs chosen from the following:
| Parameter | Value |
|---|---|
| 'censoring' | Boolean vector of the same size as x. Elements are 1 for observations that are right-censored and 0 for observations that are observed exactly. Default is all observations observed exactly. |
| 'frequency' | Vector of the same size as x containing nonnegative integer counts. The jth element of this vector gives the number of times the jth element of x was observed. Default is 1 observation per element of x. |
| 'alpha' | Value between 0 and 1 for a confidence level of 100(1-alpha)%. Default is alpha=0.05 for 95% confidence. |
| 'function' | Type of function returned as the f output argument, chosen from 'cdf' (default), 'survivor', or 'cumulative hazard'. |
| 'bounds' | Either 'on' to include bounds, or 'off' (the default) to omit them. Used only for plotting. |
Generate random failure times and random censoring times, and compare the empirical cdf with the known true cdf:
y = exprnd(10,50,1); % Random failure times exponential(10)
d = exprnd(20,50,1); % Drop-out times exponential(20)
t = min(y,d); % Observe the minimum of these times
censored = (y>d); % Observe whether the subject failed
% Calculate and plot empirical cdf and confidence bounds
[f,x,flo,fup] = ecdf(t,'censoring',censored);
stairs(x,f,'LineWidth',2)
hold on
stairs(x,flo,'r:','LineWidth',2)
stairs(x,fup,'r:','LineWidth',2)
% Superimpose a plot of the known population cdf
xx = 0:.1:max(t);
yy = 1-exp(-xx/10);
plot(xx,yy,'g-','LineWidth',2)
legend('Empirical','LCB','UCB','Population',...
'Location','SE')
hold off

[1] Cox, D. R., and D. Oakes. Analysis of Survival Data. London: Chapman & Hall, 1984.
![]() | dwtest | ecdfhist | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |