Quantiles and empirical distributions
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 SeePlace three quantiles on a staircase CDF.
- 2 TryDraw samples and watch their quantiles.
- 3 ProveBuild the proof, line by line.
- 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 ideasRead 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.
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.
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.
Place the quantile on a staircase
- Move Your x with the slider or type it; it moves in steps of 0.5.
- Press Check. The round locks, and the page grades your x with the definition.
- Three rounds, three levels. A summary opens after the third.
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.
Sampler: draws of the loss X
Each draw is a value of the loss \(X\) from stage 1, drawn independently of the others. The page draws a number \(U\) uniform on \((0, 1)\) and returns \(Q(U)\); stage 3 proves that this has CDF \(F\). Draw values and compare the empirical CDF \(F_n\) of the draws with \(F\).
Goals
Many samples at once
Check the second question by simulation: the button below draws 1,000 fresh samples of 20 values each and counts how often their sample 0.95-quantile is 7.
The smallest point exists, and Q(U) has CDF F
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.
- 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.
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.
Further reading
- J. K. Blitzstein and J. Hwang, Introduction to Probability, 2nd ed. (CRC Press, 2019), ch. 5, "Continuous Random Variables," section 5.3 on the universality of the uniform.
- A. W. van der Vaart, Asymptotic Statistics (Cambridge University Press, 1998), ch. 21, "Quantiles and Order Statistics."
- J. C. Hull, Options, Futures, and Other Derivatives, 10th ed. (Pearson, 2018), ch. 22, "Value at Risk and Expected Shortfall," on historical simulation.