\HeaderA{ecdf}{Empirical Cumulative Distribution Function}{ecdf}
\aliasA{plot.ecdf}{ecdf}{plot.ecdf}
\aliasA{print.ecdf}{ecdf}{print.ecdf}
\keyword{dplot}{ecdf}
\keyword{hplot}{ecdf}
\begin{Description}\relax
Compute or plot an empirical cumulative distribution function.
\end{Description}
\begin{Usage}
\begin{verbatim}
ecdf(x)

## S3 method for class 'ecdf':
plot(x, ..., ylab="Fn(x)", verticals = FALSE,
     col.01line = "gray70")

## S3 method for class 'ecdf':
print(x, digits= getOption("digits") - 2, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] numeric vector of \dQuote{observations} in \code{ecdf};  for
the methods, an object of class \code{"ecdf"}, typically.
\item[\code{...}] arguments to be passed to subsequent methods, i.e.,
\code{\LinkA{plot.stepfun}{plot.stepfun}} for the \code{plot} method.
\item[\code{ylab}] label for the y-axis.
\item[\code{verticals}] see \code{\LinkA{plot.stepfun}{plot.stepfun}}.
\item[\code{col.01line}] numeric or character specifying the color of the
horizontal lines at y = 0 and 1, see \code{\LinkA{colors}{colors}}.
\item[\code{digits}] number of significant digits to use, see
\code{\LinkA{print}{print}}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The e.c.d.f. (empirical cumulative distribution function)
\eqn{F_n}{Fn} is a step function with jumps \eqn{i/n}{} at
observation values, where \eqn{i}{} is the number of tied observations
at that value.  Missing values are ignored.

For observations
\code{x}\eqn{= (}{}\eqn{x_1,x_2}{x1,x2}, \ldots \eqn{x_n)}{xn)},
\eqn{F_n}{Fn} is the fraction of observations less or equal to \eqn{t}{},
i.e.,
\deqn{F_n(t) = \#\{x_i\le t\}\ / n
= \frac1 n\sum_{i=1}^n \mathbf{1}_{[x_i \le t]}.}{Fn(t) = #\{x_i \le t\} / n  =  1/n sum(i=1,n) Indicator(xi <= t).}

The function \code{plot.ecdf} which implements the \code{\LinkA{plot}{plot}}
method for \code{ecdf} objects, is implemented via a call to
\code{\LinkA{plot.stepfun}{plot.stepfun}}; see its documentation.
\end{Details}
\begin{Value}
For \code{ecdf}, a function of class \code{"ecdf"}, inheriting from the
\code{"\LinkA{stepfun}{stepfun}"} class.
\end{Value}
\begin{Section}{Warning}
Prior to \R{} 2.1.0, \code{ecdf} treated ties differently, so had
multiple jumps of size \eqn{1/n}{} at tied observations.  This was not
the most common definition, and could be very slow for large datasets
with many ties.
\end{Section}
\begin{Author}\relax
Martin Maechler, \email{maechler@stat.math.ethz.ch}.\\
Corrections by R-core.
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{stepfun}{stepfun}}, the more general class of step functions,
\code{\LinkA{approxfun}{approxfun}} and \code{\LinkA{splinefun}{splinefun}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
##-- Simple didactical  ecdf  example:
Fn <- ecdf(rnorm(12))
Fn; summary(Fn)
12*Fn(knots(Fn)) == 1:12 ## == 1:12  if and only if there are no ties !

y <- round(rnorm(12),1); y[3] <- y[1]
Fn12 <- ecdf(y)
Fn12
print(knots(Fn12), dig=2)
12*Fn12(knots(Fn12)) ## ~= 1:12  if there were no ties

summary(Fn12)
summary.stepfun(Fn12)
print(ls.Fn12 <- ls(env= environment(Fn12)))
##[1] "f"  "method"  "n"  "x"  "y"  "yleft"  "yright"

12 * Fn12((-20:20)/10)

###----------------- Plotting --------------------------

op <- par(mfrow=c(3,1), mgp=c(1.5, 0.8,0), mar= .1+c(3,3,2,1))

F10 <- ecdf(rnorm(10))
summary(F10)

plot(F10)
plot(F10, verticals= TRUE, do.p = FALSE)

plot(Fn12)# , lwd=2) dis-regarded
xx <- unique(sort(c(seq(-3,2, length=201), knots(Fn12))))
lines(xx, Fn12(xx), col='blue')
abline(v=knots(Fn12),lty=2,col='gray70')

plot(xx, Fn12(xx), type='b', cex=.1)#- plot.default
plot(Fn12, col.h='red', add= TRUE)  #- plot method
abline(v=knots(Fn12),lty=2,col='gray70')
plot(Fn12, verticals=TRUE, col.p='blue', col.h='red',col.v='bisque')
par(op)

##-- this works too (automatic call to  ecdf(.)):
plot.ecdf(rnorm(24))
\end{ExampleCode}
\end{Examples}

