ecdf
Empirical (Kaplan-Meier) cumulative distribution function.
[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 existing axes ax.
[…] = ecdf (y, name, value, …)
specifies
additional parameter name/value pairs chosen from the following:
name | value |
---|---|
"censoring" | A boolean vector of the same size as Y that is 1 for observations that are right-censored and 0 for observations that are observed exactly. Default is all observations observed exactly. |
"frequency" | A vector of the same size as Y containing non-negative integer counts. The jth element of this vector gives the number of times the jth element of Y was observed. Default is 1 observation per Y element. |
"alpha" | A value alpha between 0 and 1 specifying the significance level. Default is 0.05 for 5% significance. |
"function" | The type of function returned as the F output argument, chosen from "cdf" (the default), "survivor", or "cumulative hazard". |
"bounds" | Either "on" to include bounds or "off" (the default) to omit them. Used only for plotting. |
Type demo ecdf
to see examples of usage.
See also: cdfplot, ecdfhist
Source Code: ecdf
y = exprnd (10, 50, 1); ## random failure times are exponential(10) d = exprnd (20, 50, 1); ## drop-out times are exponential(20) t = min (y, d); ## we observe the minimum of these times censored = (y > d); ## we also observe whether the subject failed ## Calculate and plot the empirical cdf and confidence bounds [f, x, flo, fup] = ecdf (t, "censoring", censored); stairs (x, f); hold on; stairs (x, flo, "r:"); stairs (x, fup, "r:"); ## Superimpose a plot of the known true cdf xx = 0:.1:max (t); yy = 1 - exp (-xx / 10); plot (xx, yy, "g-"); hold off; |
R = wblrnd (100, 2, 100, 1); ecdf (R, "Function", "survivor", "Alpha", 0.01, "Bounds", "on"); hold on x = 1:1:250; wblsurv = 1 - cdf ("weibull", x, 100, 2); plot (x, wblsurv, "g-", "LineWidth", 2) legend ("Empirical survivor function", "Lower confidence bound", ... "Upper confidence bound", "Weibull survivor function", ... "Location", "northeast"); hold off |