ecdf                  package:stats                  R Documentation

_E_m_p_i_r_i_c_a_l _C_u_m_u_l_a_t_i_v_e _D_i_s_t_r_i_b_u_t_i_o_n _F_u_n_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Compute or plot an empirical cumulative distribution function.

_U_s_a_g_e:

     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, ...)

_A_r_g_u_m_e_n_t_s:

x, object: numeric vector of the observations for 'ecdf';  for the
          methods, an object inheriting from class '"ecdf"'.

     ...: arguments to be passed to subsequent methods, e.g.,
          'plot.stepfun' for the 'plot' method.

    ylab: label for the y-axis.

verticals: see 'plot.stepfun'.

col.01line: numeric or character specifying the color of the horizontal
          lines at y = 0 and 1, see 'colors'.

     pch: plotting character.

  digits: number of significant digits to use, see 'print'.

_D_e_t_a_i_l_s:

     The e.c.d.f. (empirical cumulative distribution function) Fn is a
     step function with jumps i/n at observation values, where i is the
     number of tied observations at that value.  Missing values are
     ignored.

     For observations 'x'= (x1,x2, ... xn), Fn is the fraction of
     observations less or equal to t, i.e.,

    Fn(t) = #{x_i <= t} / n  =  1/n sum(i=1,n) Indicator(xi <= t).


     The function 'plot.ecdf' which implements the 'plot' method for
     'ecdf' objects, is implemented via a call to 'plot.stepfun'; see
     its documentation.

_V_a_l_u_e:

     For 'ecdf', a function of class '"ecdf"', inheriting from the
     '"stepfun"' class.

     For the 'summary' method, a summary of the knots of 'object' with
     a '"header"' attribute.

_A_u_t_h_o_r(_s):

     Martin Maechler, maechler@stat.math.ethz.ch.
      Corrections by R-core.

_S_e_e _A_l_s_o:

     'stepfun', the more general class of step functions, 'approxfun'
     and 'splinefun'.

_E_x_a_m_p_l_e_s:

     ##-- 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?
     print(ls.Fn12 <- ls(environment(Fn12)))
     ##[1] "f"  "method"  "n"  "x"  "y"  "yleft"  "yright"
     utils::ls.str(environment(Fn12))

     ###----------------- 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)

