To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time. 4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds # Empirical distribution function

The green curve, which asymptotically approaches heights of 0 and 1 without reaching them, is the true cumulative distribution function of the standard normal distribution. The grey hash marks represent the observations in a particular sample drawn from that distribution, and the horizontal steps of the blue step function (including the leftmost point in each step but not including the rightmost point) form the empirical distribution function of that sample. (Click here to load a new graph.)

In statistics, an empirical distribution function is the distribution function associated with the empirical measure of a sample. This cumulative distribution function is a step function that jumps up by 1/n at each of the n data points. Its value at any specified value of the measured variable is the fraction of observations of the measured variable that are less than or equal to the specified value.

The empirical distribution function is an estimate of the cumulative distribution function that generated the points in the sample. It converges with probability 1 to that underlying distribution, according to the Glivenko–Cantelli theorem. A number of results exist to quantify the rate of convergence of the empirical distribution function to the underlying cumulative distribution function.

## Definition

Let (X1, …, Xn) be independent, identically distributed real random variables with the common cumulative distribution function F(t). Then the empirical distribution function is defined as

${\widehat {F}}_{n}(t)={\frac {{\mbox{number of elements in the sample}}\leq t}{n}}={\frac {1}{n}}\sum _{i=1}^{n}\mathbf {1} _{X_{i}\leq t},$ where $\mathbf {1} _{A}$ is the indicator of event A. For a fixed t, the indicator $\mathbf {1} _{X_{i}\leq t}$ is a Bernoulli random variable with parameter p = F(t); hence $n{\widehat {F}}_{n}(t)$ is a binomial random variable with mean nF(t) and variance nF(t)(1 − F(t)). This implies that ${\widehat {F}}_{n}(t)$ is an unbiased estimator for F(t).

However, in some textbooks, the definition is given as ${\widehat {F}}_{n}(t)={\frac {1}{n+1}}\sum _{i=1}^{n}\mathbf {1} _{X_{i}\leq t}$ ## Mean

The mean of the empirical distribution is an unbiased estimator of the mean of the population distribution.

$E_{n}(X)={\frac {1}{n}}\left(\sum _{i=1}^{n}{x_{i}}\right)$ which is more commonly denoted ${\bar {x}}$ ## Variance

The variance of the empirical distribution times ${\tfrac {n}{n-1}}$ is an unbiased estimator of the variance of the population distribution.

{\begin{aligned}\operatorname {Var} (X)&=\operatorname {E} \left[(X-\operatorname {E} [X])^{2}\right]\\[4pt]&=\operatorname {E} \left[(X-{\bar {x}})^{2}\right]\\[4pt]&={\frac {1}{n}}\left(\sum _{i=1}^{n}{(x_{i}-{\bar {x}})^{2}}\right)\end{aligned}} ## Mean squared error

The mean squared error for the empirical distribution is as follows.

{\begin{aligned}\operatorname {MSE} &={\frac {1}{n}}\sum _{i=1}^{n}(Y_{i}-{\hat {Y_{i}}})^{2}\\[4pt]&=\operatorname {Var} _{\hat {\theta }}({\hat {\theta }})+\operatorname {Bias} ({\hat {\theta }},\theta )^{2}\end{aligned}} Where ${\hat {\theta }}$ is estimator and $\theta$ a unknown parameter

## Quantiles

For any real number $a$ the notation $\lceil {a}\rceil$ (read “ceiling of a”) denotes the least integer greater than or equal to $a$ . For any real number a, the notation $\lfloor {a}\rfloor$ (read “floor of a”) denotes the greatest integer less than or equal to $a$ .

If $nq$ is not an integer, then the $q$ -th quantile is unique and is equal to $x_{(\lceil {nq}\rceil )}$ If $nq$ is an integer, then the $q$ -th quantile is not unique and is any real number $x$ such that

$x_{({nq})} ## Empirical median

If $n$ is odd, then the empirical median is the number

${\tilde {x}}=x_{(\lceil {n/2}\rceil )}$ If $n$ is even, then the empirical median is the number

${\tilde {x}}={\frac {x_{n/2}+x_{n/2+1}}{2}}$ ## Asymptotic properties

Since the ratio (n + 1)/n approaches 1 as n goes to infinity, the asymptotic properties of the two definitions that are given above are the same.

By the strong law of large numbers, the estimator ${\widehat {F}}_{n}(t)$ converges to F(t) as n → ∞ almost surely, for every value of t:

${\widehat {F}}_{n}(t)\ {\xrightarrow {\text{a.s.}}}\ F(t);$ thus the estimator ${\widehat {F}}_{n}(t)$ is consistent. This expression asserts the pointwise convergence of the empirical distribution function to the true cumulative distribution function. There is a stronger result, called the Glivenko–Cantelli theorem, which states that the convergence in fact happens uniformly over t:

$\|{\widehat {F}}_{n}-F\|_{\infty }\equiv \sup _{t\in \mathbb {R} }{\big |}{\widehat {F}}_{n}(t)-F(t){\big |}\ {\xrightarrow {\text{a.s.}}}\ 0.$ The sup-norm in this expression is called the Kolmogorov–Smirnov statistic for testing the goodness-of-fit between the empirical distribution ${\widehat {F}}_{n}(t)$ and the assumed true cumulative distribution function F. Other norm functions may be reasonably used here instead of the sup-norm. For example, the L2-norm gives rise to the Cramér–von Mises statistic.

The asymptotic distribution can be further characterized in several different ways. First, the central limit theorem states that pointwise, ${\widehat {F}}_{n}(t)$ has asymptotically normal distribution with the standard ${\sqrt {n}}$ rate of convergence:

${\sqrt {n}}{\big (}{\widehat {F}}_{n}(t)-F(t){\big )}\ \ {\xrightarrow {d}}\ \ {\mathcal {N}}{\Big (}0,F(t){\big (}1-F(t){\big )}{\Big )}.$ This result is extended by the Donsker’s theorem, which asserts that the empirical process ${\sqrt {n}}({\widehat {F}}_{n}-F)$ , viewed as a function indexed by $t\in \mathbb {R}$ , converges in distribution in the Skorokhod space $D[-\infty ,+\infty ]$ to the mean-zero Gaussian process $G_{F}=B\circ F$ , where B is the standard Brownian bridge. The covariance structure of this Gaussian process is

$\operatorname {E} [\,G_{F}(t_{1})G_{F}(t_{2})\,]=F(t_{1}\wedge t_{2})-F(t_{1})F(t_{2}).$ The uniform rate of convergence in Donsker’s theorem can be quantified by the result known as the Hungarian embedding:

$\limsup _{n\to \infty }{\frac {\sqrt {n}}{\ln ^{2}n}}{\big \|}{\sqrt {n}}({\widehat {F}}_{n}-F)-G_{F,n}{\big \|}_{\infty }<\infty ,\quad {\text{a.s.}}$ Alternatively, the rate of convergence of ${\sqrt {n}}({\widehat {F}}_{n}-F)$ can also be quantified in terms of the asymptotic behavior of the sup-norm of this expression. Number of results exist in this venue, for example the Dvoretzky–Kiefer–Wolfowitz inequality provides bound on the tail probabilities of ${\sqrt {n}}\|{\widehat {F}}_{n}-F\|_{\infty }$ :

$\Pr \!{\Big (}{\sqrt {n}}\|{\widehat {F}}_{n}-F\|_{\infty }>z{\Big )}\leq 2e^{-2z^{2}}.$ In fact, Kolmogorov has shown that if the cumulative distribution function F is continuous, then the expression ${\sqrt {n}}\|{\widehat {F}}_{n}-F\|_{\infty }$ converges in distribution to $\|B\|_{\infty }$ , which has the Kolmogorov distribution that does not depend on the form of F.

Another result, which follows from the law of the iterated logarithm, is that 

$\limsup _{n\to \infty }{\frac {{\sqrt {n}}\|{\widehat {F}}_{n}-F\|_{\infty }}{\sqrt {2\ln \ln n}}}\leq {\frac {1}{2}},\quad {\text{a.s.}}$ and

$\liminf _{n\to \infty }{\sqrt {2n\ln \ln n}}\|{\widehat {F}}_{n}-F\|_{\infty }={\frac {\pi }{2}},\quad {\text{a.s.}}$ ## Confidence intervals

Empirical CDF, CDF and Confidence Interval plots for various sample sizes of Normal Distribution

As per Dvoretzky–Kiefer–Wolfowitz inequality the interval that contains the true CDF, $F(x)$ , with probability $1-\alpha$ is specified as

Empirical CDF, CDF and Confidence Interval plots for various sample sizes of Cauchy Distribution

$F_{n}(x)-\varepsilon \leq F(x)\leq F_{n}(x)+\varepsilon \;{\text{ where }}\varepsilon ={\sqrt {\frac {\ln {\frac {2}{\alpha }}}{2n}}}.$ As per the above bounds, we can plot the Empirical CDF, CDF and Confidence intervals for different distributions by using any one of the Statistical implementations. Following is the syntax from Statsmodel for plotting empirical distribution.

Empirical CDF, CDF and Confidence Interval plots for various sample sizes of Triangle Distribution
"""
Empirical CDF Functions
"""
import numpy as np
from scipy.interpolate import interp1d

def _conf_set(F, alpha=0.05):
nobs = len(F)
epsilon = np.sqrt(np.log(2.0 / alpha) / (2 * nobs))
lower = np.clip(F - epsilon, 0, 1)
upper = np.clip(F + epsilon, 0, 1)
return lower, upper

class StepFunction(object):
def __init__(self, x, y, ival=0.0, sorted=False, side="left"):
if side.lower() not in ["right", "left"]:
msg = "side can take the values 'right' or 'left'"
raise ValueError(msg)
self.side = side
_x = np.asarray(x)
_y = np.asarray(y)
if _x.shape != _y.shape:
msg = "x and y do not have the same shape"
raise ValueError(msg)
if len(_x.shape) != 1:
msg = "x and y must be 1-dimensional"
raise ValueError(msg)
self.x = np.r_[-np.inf, _x]
self.y = np.r_[ival, _y]
if not sorted:
asort = np.argsort(self.x)
self.x = np.take(self.x, asort, 0)
self.y = np.take(self.y, asort, 0)
self.n = self.x.shape

def __call__(self, time):
tind = np.searchsorted(self.x, time, self.side) - 1
return self.y[tind]

class ECDF(StepFunction):
def __init__(self, x, side="right"):
x = np.array(x, copy=True)
x.sort()
nobs = len(x)
y = np.linspace(1.0 / nobs, 1, nobs)
super(ECDF, self).__init__(x, y, side=side, sorted=True)

def monotone_fn_inverter(fn, x, vectorized=True, **keywords):
x = np.asarray(x)
if vectorized:
y = fn(x, **keywords)
else:
y = []
for _x in x:
y.append(fn(_x, **keywords))
y = np.array(y)
a = np.argsort(y)
return interp1d(y[a], x[a])

if __name__ == "__main__":
# TODO: Make sure everything is correctly aligned and make a plotting
# function
from urllib.request import urlopen
import matplotlib.pyplot as plt

nerve_data = urlopen("http://www.statsci.org/data/general/nerve.txt")
x = nerve_data / 50.0  # Was in 1/50 seconds
cdf = ECDF(x)
x.sort()
F = cdf(x)
plt.step(x, F, where="post")
lower, upper = _conf_set(F)
plt.step(x, lower, "r", where="post")
plt.step(x, upper, "r", where="post")
plt.xlim(0, 1.5)
plt.ylim(0, 1.05)
plt.vlines(x, 0, 0.05)
plt.show()


## Statistical implementation

A non-exhaustive list of software implementations of Empirical Distribution function includes:

• In R software, we compute an empirical cumulative distribution function, with several methods for plotting, printing and computing with such an “ecdf” object.
• In Mathworks we can use Empirical cumulative distribution function (cdf) plot
• jmp from SAS, the CDF plot creates a plot of the empirical cumulative distribution function.
• Minitab, create an Empirical CDF
• Mathwave, we can fit probability distribution to our data
• Dataplot, we can plot Empirical CDF plot
• Scipy, using scipy.stats we can plot the distribution
• Statsmodels, we can use statsmodels.distributions.empirical_distribution.ECDF
• Matplotlib, we can use histograms to plot a cumulative distribution
• Excel, we can plot Empirical CDF plot