

ecdf {stepfun}                               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 an empirical cumulative distribution function.

_U_s_a_g_e_:

     ecdf(x)
     plot(ecdf(x), verticals = FALSE, col.01line = "gray70", ...)

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

       x: numeric vector with the ``observations''.

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

     The e.c.d.f. (empirical cumulative distribution func-
     tion) Fn is a step function with jump 1/n at each
     observation (possibly with multiple jumps at one place
     if there are ties).

     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'.

_V_a_l_u_e_:

     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 where 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 = F)

     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=T, col.p='blue', col.h='red',col.v='bisque')
     par(op)

     ##-- this works too (automatic call to  ecdf(.)):
     plot.ecdf(rnorm(24))

