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

     ## S3 method for class 'ecdf':
     print(x, digits= getOption("digits") - 2, ...)

_A_r_g_u_m_e_n_t_s:

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

     ...: arguments to be passed to subsequent methods, i.e.,
          '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'.

  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 jump 1/n at each observation (possibly with
     multiple jumps at one place if there are ties).  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.

_A_u_t_h_o_r(_s):

     Martin Maechler, maechler@stat.math.ethz.ch.

_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:
     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))

