Empirical distribution function (source code)

= Empirical distribution function
{title2=$F_n$}
{wiki}

The <empirical distribution function> counts the fraction of observations at or below a threshold. For a <statistical sample> of $n\geq1$ real observations $X_1,\ldots,X_n$, define
$$
F_n(x)=\frac{\#\{i:X_i\leq x\}}n=\frac1n\sum_{i=1}^n\mathbf1_{\{X_i\leq x\}}.
$$
Each <indicator function> contributes one exactly when its observation is counted. Equivalently, $F_n(x)=P_n((-\infty,x])$, where the <empirical measure> $P_n=n^{-1}\sum_i\delta_{X_i}$ assigns <probability mass> $1/n$ to each observation, including repeated observations.<All of Nonparametric Statistics by Larry Wasserman>[§2.1, printed p. 13, Definition 2.1 and equation (2.2); §2.4, printed p. 21, equation (2.37)]{ref}

Choose the illustrative <statistical sample> $[1,1,2,4,6]$. Its <empirical distribution function> is
$$
F_5(x)=\begin{cases}
0&x<1,\\
2/5&1\leq x<2,\\
3/5&2\leq x<4,\\
4/5&4\leq x<6,\\
1&6\leq x.
\end{cases}
$$
For example, $F_5(1)=2/5$ counts both observations equal to $1$, $F_5(3)=3/5$, and $F_5(4)=4/5$. There is no observation at $3$, so there is no jump there. The five observations produce only four distinct jump locations.

\Image[/empirical-distribution-step-construction.png]
{title=Building an <empirical distribution function> by counting observations}
{description=The chosen <statistical sample> is $[1,1,2,4,6]$. Stacked marks retain the two observations at $1$. Open circles show excluded heights and filled circles show the value at each jump of the <right-continuous> <step function>. The right axis gives the cumulative count, five times the <empirical distribution function>.}

The convention $X_i\leq x$ makes the <empirical distribution function> <right-continuous>: once a threshold reaches an observation, that observation remains counted immediately to its right. For a finite <statistical sample>, the count is constant from any $x$ up to the next larger observed value, proving <right continuity>. Its left-hand <limit> $F_n(x^-)$ counts observations strictly below $x$, so
$$
F_n(x)-F_n(x^-)=\frac{\#\{i:X_i=x\}}n.
$$
A value occurring $m$ times causes one jump of size $m/n$. At $1$ the jump is $2/5$; at $2$, $4$, and $6$ each jump is $1/5$. All jumps sum to one. Thus the <empirical distribution function> is a <nondecreasing> <step function> with limits zero and one, and is itself a valid <cumulative distribution function>.

This turns many questions about data into simple <cumulative distribution function> operations. The observed fraction in $(a,b]$ is $F_n(b)-F_n(a)$: for $(1,4]$ it is $4/5-2/5=2/5$, counting $2$ and $4$ but excluding both $1$s. Including the left endpoint gives $F_n(4)-F_n(1^-)=4/5$. A <sample quantile> reads the same staircase in reverse: the smallest threshold reaching $1/2$ is $2$. Unlike a <histogram>, this representation requires no choice of bins; its jumps retain every observation and its multiplicity.

The exact description of a finite <statistical sample> must be distinguished from a <statistical model> for how it was obtained. The <empirical distribution function> is defined for any finite list, with no <independence> assumption. Once the list is observed, its counts are fixed. For <statistical inference>, one often models $X_1,\ldots,X_n$ as <independent and identically distributed random variables> with an unknown population <cumulative distribution function> $F(x)=\mathbb P(X_i\leq x)$. Then $F$ describes the sampling law, while $F_n$ varies across repeated <statistical samples>. The value $F_5(1)=0.4$ is an observed fraction and an estimate of $F(1)$; it does not establish that the population <probability> is $0.4$. Even when $F$ is continuous, every finite $F_n$ is discrete.

For any threshold $x$ fixed before sampling, the <indicator functions> are <independent> <Bernoulli random variables> with success <probability> $F(x)$. Therefore the count has a <binomial distribution> and
$$
nF_n(x)\sim\operatorname{Binomial}(n,F(x)),\qquad
\mathbb E[F_n(x)]=F(x),\qquad
\operatorname{Var}(F_n(x))=\frac{F(x)(1-F(x))}{n}.
$$
The <expected value> follows by adding the <expected values> of the <indicator functions>; the <variance> follows by adding their <variances> using <independence> and dividing by $n^2$. Thus $F_n(x)$ is an <unbiased estimator> of $F(x)$ at a fixed threshold. Controlling the error at every threshold at once requires more than a fixed-threshold calculation: the <DKW inequality> supplies such control, and the <Glivenko-Cantelli theorem> describes its <uniform convergence> <almost surely> as $n$ grows.

Comparing $F_n$ with a proposed <cumulative distribution function> also motivates <goodness-of-fit tests>, including the <Kolmogorov-Smirnov test>, the <Anderson–Darling test>, and the <Cramér–von Mises criterion>. A standard <Kolmogorov-Smirnov test> calibration assumes a fully specified continuous population law; fitting its <statistical parameters> from the same <statistical sample> changes that calibration.<NIST and SEMATECH e-Handbook of Statistical Methods/1.3.5.16. Kolmogorov-Smirnov Goodness-of-Fit Test>[NIST and SEMATECH e-Handbook of Statistical Methods; Characteristics and Limitations, items 1 and 3; Definition, test statistic and fully specified distribution requirement]{ref}