Cumulative Distribution Functions
The cumulative distribution function (CDF) of a random variable X is F(x) = P(X ≤ x), the probability that X is at most x. For a continuous variable, F(x) = \int_{-\infty}^{x} f(t)\,dt, so P(a ≤ X ≤ b) = F(b) − F(a). F rises from 0 to 1, and its derivative is the density f.
Before this lesson: Probability Density Functions, Fundamental Theorem of Calculus Part 1 and Discrete Random Variables
A running total of probability
A density f shows where probability is concentrated. The CDF keeps a running total: F(x) is all the area under f to the left of x. Far to the left, no area has been collected yet, so F is near 0. Far to the right, all of it has, so F is near 1.
The CDF is useful because one subtraction answers any interval question. Once you know F, you don’t need to integrate again: P(a ≤ X ≤ b) = F(b) − F(a). Percentiles come from the CDF too, because the 75th percentile is the value where F reaches 0.75.
Cumulative distribution function formulas
For any random variable, F(x) = P(X ≤ x). For a continuous random variable with density f,
F(x) = \int_{-\infty}^{x} f(t)\,dt, \qquad F'(x) = f(x)The second formula is the fundamental theorem of calculus: the derivative of an accumulated area is the height of the curve. Every CDF has these properties:
- F never decreases as x increases.
- F(x) approaches 0 as x goes to −∞ and approaches 1 as x goes to ∞.
- P(a ≤ X ≤ b) = F(b) − F(a) for a continuous variable.
- P(X \gt a) = 1 - F(a).
Steps to find a CDF from a density
- Split the number line where the formula for f changes.
- On each piece, add the area collected on earlier pieces to the integral of f from the start of the piece to x.
- Write F(x) = 0 to the left of where f starts and F(x) = 1 to the right of where it ends.
- Check that F is continuous and reaches 1.
Cumulative distribution function examples
Example 1: CDF from a density
X has density f(x) = x²/9 for 0 ≤ x ≤ 3, and 0 elsewhere. Find the CDF, and use it to find P(1 ≤ X ≤ 2).
F(x) = \int_0^x \dfrac{t^2}{9}\,dtFor 0 ≤ x ≤ 3, add up the area from 0 to x; f is 0 below 0.
F(x) = \left[\dfrac{t^3}{27}\right]_0^x = \dfrac{x^3}{27}Integrate with the power rule (see antiderivatives) and evaluate at the limits.
F(3) = \dfrac{27}{27} = 1Check that F reaches 1 at the right end.
P(1 \le X \le 2) = F(2) - F(1)
Subtract CDF values.
P(1 \le X \le 2) = \dfrac{8}{27} - \dfrac{1}{27} = \dfrac{7}{27}Substitute x = 2 and x = 1.
F(x) = \begin{cases} 0, & x \lt 0 \\ \dfrac{x^3}{27}, & 0 \le x \le 3 \\ 1, & x \gt 3 \end{cases}Answer: the CDF is shown above, and P(1 ≤ X ≤ 2) = 7/27 ≈ 0.259, the same area found in the density lesson.
Example 2: A piecewise density and a percentile
The distance X, in kilometers, from a store to a delivery address has density f(x) = 0.3 for 0 ≤ x ≤ 2 and f(x) = 0.1 for 2 ≤ x ≤ 6, and 0 elsewhere. Find the CDF and the 75th percentile.
F(x) = \int_0^x 0.3\,dt = 0.3x
For 0 ≤ x ≤ 2.
F(2) = 0.3(2) = 0.6
Area collected by x = 2.
F(x) = 0.6 + \int_2^x 0.1\,dt = 0.6 + 0.1(x - 2)
For 2 ≤ x ≤ 6, add the area past 2.
F(x) = 0.4 + 0.1x
Distribute and combine like terms.
F(6) = 0.4 + 0.6 = 1
Check the right end.
0.4 + 0.1x = 0.75
The 75th percentile has F(x) = 0.75, which is above F(2) = 0.6, so it is on the second piece.
0.1x = 0.35
Subtract 0.4 from both sides.
x = 3.5
Divide both sides by 0.1.
Answer: F(x) = 0 for x below 0, 0.3x on [0, 2], 0.4 + 0.1x on [2, 6] and 1 after 6. The 75th percentile is 3.5 km.
Example 3: Density from a CDF
X has CDF F(x) = 1 − 1/x² for x ≥ 1, and F(x) = 0 for x below 1. Find the density, P(X \gt 3) and the median.
f(x) = F'(x) = \dfrac{d}{dx}\left(1 - x^{-2}\right)The density is the derivative of the CDF.
f(x) = 2x^{-3} = \dfrac{2}{x^3}Use the power rule, for x ≥ 1.
P(X \gt 3) = 1 - F(3)
Complement rule.
P(X \gt 3) = 1 - \left(1 - \dfrac{1}{9}\right) = \dfrac{1}{9}Substitute F(3) and simplify.
1 - \dfrac{1}{m^2} = \dfrac{1}{2}The median m has F(m) = 1/2.
\dfrac{1}{m^2} = \dfrac{1}{2}Rearrange: subtract 1/2 from both sides and add 1/m².
m^2 = 2
Take reciprocals.
m = \sqrt{2} \approx 1.414Take the positive square root.
Answer: f(x) = 2/x³ for x ≥ 1 (the density from Example 3 of the density lesson), P(X \gt 3) = 1/9 and the median is √2 ≈ 1.414.
Example 4: Battery life (word problem)
The lifetime T, in years, of a phone battery has CDF F(t) = 1 − e^(−t/4) for t ≥ 0. Find the probability that a battery lasts at most 2 years, more than 6 years, and between 2 and 6 years. Then find the median lifetime.
P(T \le 2) = F(2) = 1 - e^{-2/4} = 1 - e^{-0.5}Substitute t = 2.
P(T \le 2) \approx 1 - 0.6065 = 0.3935
Use a calculator for the exponential, then subtract.
P(T \gt 6) = 1 - F(6) = e^{-1.5} \approx 0.2231Complement rule.
P(2 \lt T \le 6) = F(6) - F(2) = e^{-0.5} - e^{-1.5}Subtract CDF values; the 1s cancel.
P(2 \lt T \le 6) \approx 0.6065 - 0.2231 = 0.3834
Subtract.
1 - e^{-t/4} = \dfrac{1}{2}The median solves F(t) = 1/2.
e^{-t/4} = \dfrac{1}{2}Rearrange.
-\dfrac{t}{4} = \ln \dfrac{1}{2} = -\ln 2Take the natural log of both sides (see solving exponential equations).
t = 4\ln 2 \approx 2.77
Multiply both sides by −4.
Answer: about 0.3935, 0.2231 and 0.3834, and the median lifetime is about 2.77 years. The three probabilities add to 1, as they should.
Example 5: The CDF of a discrete variable
X is the number of heads in 3 tosses of a fair coin. Find its CDF, F(1.5) and P(1 ≤ X ≤ 2).
P(X = 0) = \tfrac{1}{8},\ P(X = 1) = \tfrac{3}{8},\ P(X = 2) = \tfrac{3}{8},\ P(X = 3) = \tfrac{1}{8}Binomial distribution with n = 3 and p = 1/2.
F(0) = \tfrac{1}{8},\ F(1) = \tfrac{4}{8},\ F(2) = \tfrac{7}{8},\ F(3) = 1Keep a running total.
F(1.5) = F(1) = \tfrac{1}{2}F stays flat between the possible values.
P(1 \le X \le 2) = F(2) - F(0)
Subtract F just below 1, which is F(0), so that X = 1 is kept.
P(1 \le X \le 2) = \tfrac{7}{8} - \tfrac{1}{8} = \tfrac{3}{4}Substitute and subtract.
Answer: F is a step function: 0 below 0, then 1/8 on [0, 1), 1/2 on [1, 2), 7/8 on [2, 3) and 1 from 3 on. F(1.5) = 1/2 and P(1 ≤ X ≤ 2) = 3/4. For a discrete variable, F(2) − F(1) = 3/8 would leave out X = 1.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Using the middle formula for every x | Writing F(5) = 125/27 in Example 1 | F can never be more than 1. F(x) = 1 for x ≥ 3 and 0 for x below 0. |
| Starting each piece over at 0 | Writing F(x) = 0.1(x − 2) on [2, 6] in Example 2 | Add the area already collected: F(x) = 0.6 + 0.1(x − 2). |
| Confusing F with f | Saying P(X ≤ 2) = f(2) = 4/9 in Example 1 | P(X ≤ 2) = F(2) = 8/27. The density f is a height, not a probability. |
| Using F(a) for a right tail | Writing P(T ≥ 6) = F(6) ≈ 0.7769 in Example 4 | Use the complement: 1 − F(6) ≈ 0.2231. |
| Ignoring jumps in a discrete CDF | Writing P(1 ≤ X ≤ 2) = F(2) − F(1) = 3/8 in Example 5 | Subtract the CDF just below the left endpoint: F(2) − F(0) = 3/4. |
Related ideas
The CDF is also the main tool for finding the distribution of a new variable such as Y = X^2; see functions of a random variable.
Percentiles and the quantile function
The pth percentile is the value x with F(x) = p. Solving F(x) = p for x gives the quantile function, the inverse of F. Computers use it to simulate random values: plug a random number between 0 and 1 into the quantile function.
The survival function
In reliability and medicine, S(x) = 1 − F(x) = P(X ≥ x) is called the survival function. In Example 4, S(6) ≈ 0.2231 is the chance a battery survives past 6 years.
Tables are CDFs
A z-table gives the CDF of the standard normal distribution. Every “area to the left” you looked up in Statistics was a CDF value, which is why percentiles and z-scores go together.
Practice problems
- X has density f(x) = 2x for 0 ≤ x ≤ 1, and 0 elsewhere. Find its CDF.
- With the CDF from Problem 1, find P(0.2 ≤ X ≤ 0.5).
- X has CDF F(x) = x³ for 0 ≤ x ≤ 1 (0 below 0 and 1 above 1). Find its density.
- X has CDF F(x) = x²/16 for 0 ≤ x ≤ 4 (0 below 0 and 1 above 4). Find P(X \gt 2).
- With the CDF from Problem 4, find the median.
- X has density f(x) = 1/4 for 2 ≤ x ≤ 6, and 0 elsewhere. Find F(x) on [2, 6] and F(5).
- T has CDF F(t) = 1 − e^(−0.2t) for t ≥ 0. Find P(T ≤ 5).
- With the CDF from Problem 7, find the 90th percentile.
- X is the result of rolling a fair die. Find F(3.7).
- Can H(x) = x(2 − x) for 0 ≤ x ≤ 2, with H(x) = 0 below 0 and 1 above 2, be a CDF? Explain.
Show answers
1.
F(x) = \int_0^x 2t\,dt = \left[t^2\right]_0^x = x^2
Integrate from 0 to x.
Answer: F(x) = 0 for x below 0, x² for 0 ≤ x ≤ 1, and 1 for x above 1
2.
P(0.2 \le X \le 0.5) = F(0.5) - F(0.2)
Subtract CDF values.
P(0.2 \le X \le 0.5) = 0.25 - 0.04 = 0.21
Square each value, then subtract.
Answer: 0.21
3.
f(x) = F'(x) = 3x^2
Differentiate with the power rule.
Answer: f(x) = 3x² for 0 ≤ x ≤ 1, and 0 elsewhere
4.
P(X \gt 2) = 1 - F(2) = 1 - \dfrac{4}{16}Complement rule.
P(X \gt 2) = \dfrac{3}{4}Simplify.
Answer: 3/4
5.
\dfrac{m^2}{16} = \dfrac{1}{2}The median has F(m) = 1/2.
m^2 = 8
Multiply both sides by 16.
m = \sqrt{8} = 2\sqrt{2} \approx 2.828Take the positive square root and simplify (see simplifying square roots).
Answer: about 2.828
6.
F(x) = \int_2^x \tfrac{1}{4}\,dt = \dfrac{x - 2}{4}Integrate from 2 to x.
F(5) = \dfrac{5 - 2}{4} = \dfrac{3}{4}Substitute x = 5.
Answer: F(x) = (x − 2)/4 on [2, 6], and F(5) = 3/4
7.
P(T \le 5) = 1 - e^{-0.2(5)} = 1 - e^{-1}Substitute t = 5.
P(T \le 5) \approx 1 - 0.3679 = 0.6321
Use a calculator, then subtract.
Answer: about 0.6321
8.
1 - e^{-0.2t} = 0.9The 90th percentile has F(t) = 0.9.
e^{-0.2t} = 0.1Rearrange.
-0.2t = \ln 0.1
Take the natural log of both sides.
t = \dfrac{\ln 0.1}{-0.2} = 5\ln 10 \approx 11.51Divide both sides by −0.2.
Answer: about 11.51
9.
F(3.7) = P(X \le 3.7) = P(X \le 3)
The die can’t show a value between 3 and 3.7.
F(3.7) = \dfrac{3}{6} = \dfrac{1}{2}The outcomes 1, 2 and 3.
Answer: 1/2
10.
H(1) = 1(2 - 1) = 1
Evaluate at x = 1.
H(1.5) = 1.5(2 - 1.5) = 0.75
Evaluate at x = 1.5.
Answer: no. H decreases from 1 to 0.75 between x = 1 and x = 1.5, and a CDF can never decrease.
Cumulative distribution function FAQ
What is a cumulative distribution function?
It is the function F(x) = P(X ≤ x), which gives the probability that a random variable is at most x. It starts near 0, never decreases and ends near 1.
How do you find the CDF from a PDF?
Integrate the density from the left end of its interval up to x, piece by piece, adding the area from earlier pieces. Then set F = 0 to the left of the density and F = 1 to the right of it.
How do you find the PDF from a CDF?
Differentiate: f(x) = F′(x) wherever the derivative exists. This is the fundamental theorem of calculus applied to the area under f.
What is the difference between a PDF and a CDF?
The PDF is a height that shows where probability is concentrated, and you integrate it to get probabilities. The CDF is already a probability: the total area to the left of x.
Summary
- The CDF is F(x) = P(X ≤ x), and for a continuous variable it is the area under f to the left of x.
- P(a ≤ X ≤ b) = F(b) − F(a), and P(X ≥ a) = 1 − F(a).
- The density is the derivative of the CDF: f(x) = F′(x).
- A CDF never decreases, starts at 0 and ends at 1; build it piece by piece.
- Percentiles solve F(x) = p, and a discrete CDF is a step function.
Previous lesson: Probability Density Functions
Next lesson: Expected Value of a Continuous Random Variable
Back to the Probability Theory Index