EVOLUTION-MANAGER
Edit File: ecdf.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Empirical Cumulative Distribution Function</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for ecdf {stats}"><tr><td>ecdf {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Empirical Cumulative Distribution Function</h2> <h3>Description</h3> <p>Compute an empirical cumulative distribution function, with several methods for plotting, printing and computing with such an “ecdf” object. </p> <h3>Usage</h3> <pre> ecdf(x) ## S3 method for class 'ecdf' plot(x, ..., ylab="Fn(x)", verticals = FALSE, col.01line = "gray70", pch = 19) ## S3 method for class 'ecdf' print(x, digits= getOption("digits") - 2, ...) ## S3 method for class 'ecdf' summary(object, ...) ## S3 method for class 'ecdf' quantile(x, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, object</code></td> <td> <p>numeric vector of the observations for <code>ecdf</code>; for the methods, an object inheriting from class <code>"ecdf"</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments to be passed to subsequent methods, e.g., <code><a href="plot.stepfun.html">plot.stepfun</a></code> for the <code>plot</code> method.</p> </td></tr> <tr valign="top"><td><code>ylab</code></td> <td> <p>label for the y-axis.</p> </td></tr> <tr valign="top"><td><code>verticals</code></td> <td> <p>see <code><a href="plot.stepfun.html">plot.stepfun</a></code>.</p> </td></tr> <tr valign="top"><td><code>col.01line</code></td> <td> <p>numeric or character specifying the color of the horizontal lines at y = 0 and 1, see <code><a href="../../grDevices/html/colors.html">colors</a></code>.</p> </td></tr> <tr valign="top"><td><code>pch</code></td> <td> <p>plotting character.</p> </td></tr> <tr valign="top"><td><code>digits</code></td> <td> <p>number of significant digits to use, see <code><a href="../../base/html/print.html">print</a></code>.</p> </td></tr> </table> <h3>Details</h3> <p>The e.c.d.f. (empirical cumulative distribution function) <i>Fn</i> is a step function with jumps <i>i/n</i> at observation values, where <i>i</i> is the number of tied observations at that value. Missing values are ignored. </p> <p>For observations <code>x</code><i>= (</i><i>x1,x2</i>, ... <i>xn)</i>, <i>Fn</i> is the fraction of observations less or equal to <i>t</i>, i.e., </p> <p style="text-align: center;"><i> Fn(t) = #{xi <= t}/n = 1/n sum(i=1,n) Indicator(xi <= t).</i></p> <p>The function <code>plot.ecdf</code> which implements the <code><a href="../../graphics/html/plot.html">plot</a></code> method for <code>ecdf</code> objects, is implemented via a call to <code><a href="plot.stepfun.html">plot.stepfun</a></code>; see its documentation. </p> <h3>Value</h3> <p>For <code>ecdf</code>, a function of class <code>"ecdf"</code>, inheriting from the <code>"<a href="stepfun.html">stepfun</a>"</code> class, and hence inheriting a <code><a href="stepfun.html">knots</a>()</code> method. </p> <p>For the <code>summary</code> method, a summary of the knots of <code>object</code> with a <code>"header"</code> attribute. </p> <p>The <code><a href="quantile.html">quantile</a>(obj, ...)</code> method computes the same quantiles as <code>quantile(x, ...)</code> would where <code>x</code> is the original sample. </p> <h3>Note</h3> <p>The objects of class <code>"ecdf"</code> are not intended to be used for permanent storage and may change structure between versions of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> (and did at <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 3.0.0). They can usually be re-created by </p> <pre> eval(attr(old_obj, "call"), environment(old_obj))</pre> <p>since the data used is stored as part of the object's environment. </p> <h3>Author(s)</h3> <p>Martin Maechler; fixes and new features by other R-core members. </p> <h3>See Also</h3> <p><code><a href="stepfun.html">stepfun</a></code>, the more general class of step functions, <code><a href="approxfun.html">approxfun</a></code> and <code><a href="splinefun.html">splinefun</a></code>. </p> <h3>Examples</h3> <pre> ##-- Simple didactical ecdf example : x <- rnorm(12) Fn <- ecdf(x) Fn # a *function* Fn(x) # returns the percentiles for x tt <- seq(-2, 2, by = 0.1) 12 * Fn(tt) # Fn is a 'simple' function {with values k/12} summary(Fn) ##--> see below for graphics knots(Fn) # the unique data values {12 of them if there were no ties} y <- round(rnorm(12), 1); y[3] <- y[1] Fn12 <- ecdf(y) Fn12 knots(Fn12) # unique values (always less than 12!) summary(Fn12) summary.stepfun(Fn12) ## Advanced: What's inside the function closure? ls(environment(Fn12)) ##[1] "f" "method" "n" "x" "y" "yleft" "yright" utils::ls.str(environment(Fn12)) stopifnot(all.equal(quantile(Fn12), quantile(y))) ###----------------- Plotting -------------------------- require(graphics) 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.points = FALSE) plot(Fn12 , lwd = 2) ; mtext("lwd = 2", adj = 1) 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 = "o", cex = .1) #- plot.default {ugly} plot(Fn12, col.hor = "red", add = TRUE) #- plot method abline(v = knots(Fn12), lty = 2, col = "gray70") ## luxury plot plot(Fn12, verticals = TRUE, col.points = "blue", col.hor = "red", col.vert = "bisque") ##-- this works too (automatic call to ecdf(.)): plot.ecdf(rnorm(24)) title("via simple plot.ecdf(x)", adj = 1) par(op) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>