12
$\begingroup$

Empirical CDF functions are usually estimated by a step function. Is there a reason why this is done in such a way and not by using a linear interpolation? Does the step function has any interesting theoretical properties which make us prefer it?

Here is an example of the two:

ecdf2 <- function (x) {
  x <- sort(x)
  n <- length(x)
  if (n < 1) 
    stop("'x' must have 1 or more non-missing values")
  vals <- unique(x)
  rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/n, 
                    method = "linear", yleft = 0, yright = 1, f = 0, ties = "ordered")
  class(rval) <- c("ecdf", class(rval))
  assign("nobs", n, envir = environment(rval))
  attr(rval, "call") <- sys.call()
  rval
}


set.seed(2016-08-18)
a <- rnorm(10)
a2 <- ecdf(a)
a3 <- ecdf2(a)

par(mfrow = c(1,2))
curve(a2, -2,2, main = "step function ecdf")
curve(a3, -2,2, main = "linear interpolation function ecdf")

enter image description here

$\endgroup$
  • $\begingroup$ Related................................... $\endgroup$ – user128129 Aug 18 '16 at 12:48
  • 8
    $\begingroup$ "...estimated by a step function" belies a subtle misconception: the ECDF is not merely estimated by a step function; it is such a function by definition. It is identical to the CDF of a random variable. Specifically, given any finite sequence of numbers $x_1, x_2, \ldots, x_n$, define a probability space $(\Omega,\mathfrak{S},\mathbb{P})$ with $\Omega=\{1,2,\ldots, n\}$, $\mathfrak{S}$ discrete, and $\mathbb{P}$ uniform. Let $X$ be the random variable assigning $x_i$ to $i$. The ECDF is the CDF of $X$. This enormous conceptual simplification is a compelling argument for the definition. $\endgroup$ – whuber Aug 18 '16 at 13:52
21
$\begingroup$

It's by definition.

The empirical distribution function of a set of observations $(X_n)$ is defined by

$$F_e(t) = \frac{\#\{X_n \mid X_n \le t\}}n$$

Where $\#$ is the set cardinality. This is, by nature, a step function. It converges to the actual CDF almost surely.

Also note that for any distribution with $P(X = x) \ne 0$ for at least two $x$ (especially nondegenerate discrete distributions), your variant of ECDF does not converge to the actual CDF. For example consider a Bernoulli distribution with CDF

$$F_X(x) = p \chi_{x \ge 0} + (1-p) \chi_{x \ge 1}$$ this is a step function whereas ecdf2 will converge to $\chi_{x\ge 0} \cdot (p + (1-p)\min(x, 1))$ (a piecewise linear function connecting $(0,p)$ and $(1,1)$.

$\endgroup$
  • $\begingroup$ Thanks Alex. So is there another name for the function I wrote? (because I would guess it also converges to the actual CDF) $\endgroup$ – Tal Galili Aug 18 '16 at 10:19
  • 5
    $\begingroup$ @TalGalili It doesn't. Consider a Bernoulli distribution. Your ecdf2 will not converge in this case. You could call it a smoothed ecdf. I suspect it will converge to the actual CDF iff the actual CDF has no points with nonzero probability except for extreme points (where you don't smooth) $\endgroup$ – AlexR Aug 18 '16 at 11:02
  • $\begingroup$ @AlexR you could edit your answer to add this comment since discrete distributions are the reason for such definite -- so it answers the "why" question. $\endgroup$ – Tim Aug 18 '16 at 13:02
  • 1
    $\begingroup$ @Tim Done. ${}{}$ $\endgroup$ – AlexR Aug 18 '16 at 14:33
  • $\begingroup$ Thanks. Is there a way to define a continuous empirical function that would converge to the step function but would be fully monotone (i.e.: without any sharp "jumps")? $\endgroup$ – Tal Galili Aug 19 '16 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.