Hexa Scholar

Quantiles and empirical distributions

Twelve wooden bars with gold caps stand in one row on a navy tabletop, sorted from the shortest on the left to the tallest on the right, so their tops rise like an uneven staircase. All bars have the same width and color.
Twelve bars sorted from shortest to tallest, like a sample sorted from smallest to largest. A sample quantile is the value found at a chosen place in such a row.

The question

A daily loss X is 0, 1, 2, 4 or 7, with P(X ≤ 4) = 0.92. Which value is its 95% quantile, when P(X ≤ x) never equals 0.95?

Stage 1 lets you place it on the CDF and checks your answer.

  1. 1 SeePlace three quantiles on a staircase CDF.
  2. 2 TryDraw samples and watch their quantiles.
  3. 3 ProveBuild the proof, line by line.
  4. 4 ApplyService calls, trading losses and insurance claims.
Before you start · 3 quick checks on step CDFs, jumps and the infimum of a set, about 4 min

Two ideas before you start

2 ideas

Read a quantile off the CDF

Figure: the CDF F(x) = x² on [0, 1], with a dashed path from the chosen level p across to the curve and down to Q(p) = √p. It needs JavaScript.

p =

F(x) = x² = 0.25 at x = √0.25 = 0.5

Go across from the level p to the graph of F, then down: that x is the p-quantile Q(p). Here F(x) = x² for 0 ≤ x ≤ 1, the CDF of the larger of two independent numbers drawn uniformly from [0, 1], so Q(p) = √p.

Exact definition

Quantiles. Let \(X\) be a random variable with CDF \(F(x) = P(X \le x)\). For a level \(p\) with \(0 \lt p \lt 1\), the \(p\)-quantile of \(X\) is

\[Q(p) = \inf\{x : F(x) \ge p\},\]

the smallest \(x\) with \(F(x) \ge p\); stage 3 proves that this smallest \(x\) exists. \(Q\) is also called the quantile function or the generalized inverse of \(F\), and is often written \(F^{-1}\). When \(F\) is continuous and strictly increasing, \(Q(p)\) is the one \(x\) with \(F(x) = p\). When \(F\) jumps over \(p\) or is flat at height \(p\), no \(x\) or many \(x\) have \(F(x) = p\), and the definition still picks one point; stage 1 shows which. \(Q(0.5)\) is the smallest median of \(X\), in the sense of the lesson on PMF, PDF and CDF, and \(Q(0.95)\) is also called the 95th percentile.

The empirical CDF counts data

Figure: the empirical CDF of the five values 1.2, 2, 2, 3.5 and 4.1, a staircase that jumps by 1/5 at each value and by 2/5 at the repeated value 2, with a dashed line at the chosen x. It needs JavaScript.

x =

F₅(2) = #{values ≤ 2} / 5 = 3/5 = 0.6

For data x₁, …, xₙ, Fₙ(x) is the fraction of the values at or below x. It is a staircase that jumps by 1/n at each value, and by 2/n at a value that occurs twice.

Exact definition

Empirical CDF. For a whole number \(n \ge 1\) and real numbers \(x_1, \ldots, x_n\), the empirical CDF is

\[F_n(x) = \frac{\#\{i : x_i \le x\}}{n}\]

for every real \(x\). It is the CDF of a random variable that picks one of the \(n\) values, each with probability \(\tfrac{1}{n}\), so it is a step function that jumps by \(\tfrac{k}{n}\) at a value that occurs \(k\) times. The sorted values are written \(x_{(1)} \le x_{(2)} \le \cdots \le x_{(n)}\). The sample quantile is the quantile of \(F_n\): \(Q_n(p) = \inf\{x : F_n(x) \ge p\}\) for \(0 \lt p \lt 1\).

Fine print: right-continuity and left limits

Every CDF is nondecreasing and right-continuous: as \(x\) comes down to a point \(a\) from the right, \(F(x)\) tends to \(F(a)\). The limit from the left is written \(F(a^-)\); it equals \(P(X \lt a)\), and the jump \(F(a) - F(a^-)\) is \(P(X = a)\). Also \(F(x) \to 0\) as \(x \to -\infty\) and \(F(x) \to 1\) as \(x \to \infty\). The lesson on PMF, PDF and CDF shows these facts with filled and open dots.

1 See

Place the quantile on a staircase

2 Try

Quantiles of a sample

Two questions first. The sampler below them opens once both are answered.

The sampler opens when you have answered the two questions above.

3 Prove

The smallest point exists, and Q(U) has CDF F

Theorem

Assumptions. \(F\) is a CDF: it is nondecreasing, right-continuous, \(F(x) \to 0\) as \(x \to -\infty\) and \(F(x) \to 1\) as \(x \to \infty\). It may jump and it may be flat. Fix \(p\) with \(0 \lt p \lt 1\), let \(S_p = \{x : F(x) \ge p\}\), and let \(Q(p) = \inf S_p\). \(U\) is a random variable uniform on \((0, 1)\).

Conclusion. \(Q(p)\) is a real number with \(F(Q(p)) \ge p\), so it is the smallest point of \(S_p\), and for every real \(x\),

\[Q(p) \le x \iff p \le F(x).\]

Consequently \(P(Q(U) \le x) = F(x)\) for every real \(x\): the random variable \(Q(U)\) has CDF \(F\).

Facts the proof uses.

  • a nonempty set of real numbers that is bounded below has a greatest lower bound, its infimum;
  • the four properties of a CDF listed above;
  • for every \(u\) in \([0, 1]\), \(P(U \le u) = u\).

Each option is a statement about the \(F\), \(p\), \(S_p\) and \(Q(p)\) of the theorem. Pick the one that is true for every CDF \(F\) and every \(p\) with \(0 \lt p \lt 1\), including CDFs that jump, are flat or are continuous.

What else follows
  • Sample quantiles are sorted values. Apply the theorem to \(F_n\). With sorted data \(x_{(1)} \le \cdots \le x_{(n)}\), \(F_n(x) \ge p\) means that at least \(np\) of the values are at or below \(x\), that is, at least \(k = \lceil np \rceil\) of them, which happens exactly when \(x \ge x_{(k)}\). So \(Q_n(p) = x_{(k)}\).
  • Simulation. Line 5 is how the sampler of stage 2 draws values of \(X\): it draws \(U\) and returns \(Q(U)\). For the loss \(X\), \(Q(U) = 0\) when \(U \le 0.3\), \(Q(U) = 1\) when \(0.3 \lt U \le 0.5\), and so on.
  • Continuous CDFs. When \(F\) is continuous and strictly increasing, \(Q\) is its ordinary inverse. For a normal \(X\) with mean \(\mu\) and SD \(\sigma\), \(Q(p) = \mu + \sigma z_p\), where \(\Phi(z_p) = p\), as in the lesson on the normal distribution.
  • Value at risk. For a loss \(L\), one common definition of the value at risk at level \(p\) is the quantile \(Q_L(p)\) of the loss. Problem P3 computes a historical version, the sample quantile of past losses.
4 Apply

Problems

Each problem states its model, and has hints and a full solution. Every quantile here is the smallest \(x\) with \(F(x) \ge p\), or with \(F_n(x) \ge p\) for data.

Key point To find \(Q(p)\), find where \(F\) first reaches \(p\): solve \(F(x) = p\) where \(F\) climbs continuously, take the place of the jump when \(F\) jumps over \(p\), and take the left end when \(F\) is flat at \(p\). For data, sort the values and take the \(\lceil np \rceil\)-th smallest.
Level Intro Prerequisites CDFs of discrete and continuous random variables (the lesson on PMF, PDF and CDF), the infimum of a set Time ~35 min

Further reading