PMF, PDF and CDF
The three ways to describe a distribution, how to convert between them, and why densities are not probabilities.
Assumes you know
PMF, PDF and CDF
Intuition first
There are three standard ways to describe how a random variable spreads its probability, and they carry the same information in different shapes.
For a discrete variable, list the probability of each value. That is the PMF.
For a continuous variable, listing values is hopeless — each has probability zero — so instead describe probability per unit length. That is the PDF, and it is a density, not a probability.
The third option works for both: report the accumulated probability up to each point, . That is the CDF, and because it never decreases and always runs from 0 to 1, it is the most convenient object for computing interval probabilities and quantiles.
| Symbol | Meaning | Read aloud |
|---|---|---|
| p(x) or pₓ(x) | PMF — probability that X equals x (discrete) | p of x |
| f(x) or fₓ(x) | PDF — probability density at x (continuous) | f of x |
| F(x) or Fₓ(x) | CDF — P(X ≤ x), for either kind | big F of x |
| Q(p) or F⁻¹(p) | Quantile function — the inverse of the CDF | quantile |
The probability mass function
For a discrete ,
with two requirements:
The probability density function
For a continuous , probability is obtained by integrating:
with the analogous requirements:
The cumulative distribution function
Defined for every random variable, and always has these properties:
- Non-decreasing — accumulating more can never reduce the total.
- Limits — and .
- Right-continuous — jumps at discrete atoms, with the value at the jump included.
Converting between them
| From | To | Discrete | Continuous |
|---|---|---|---|
| PMF/PDF | CDF | ||
| CDF | PMF/PDF |
Interval probabilities from the CDF
For continuous variables the endpoints are irrelevant. For discrete ones they matter:
Solved problem 1 · A discrete variable, all three functions
has PMF , , . Find the CDF, then , , and .
Step 1 — check it is a valid PMF
Step 2 — accumulate to get the CDF
Note is constant on because no probability mass lies strictly between 2 and 4.
Step 3 — the four probabilities
Step 4 — sanity check by direct summation
Answer
; ; ; .
Notice — they differ by exactly , which is why strictness of inequalities cannot be ignored for discrete variables.
Solved problem 2 · A continuous variable: normalising, CDF, and a median
has density on and zero elsewhere. Find , the CDF, , and the median.
Step 1 — find c by normalising
Setting this equal to 1:
So on .
Step 2 — integrate for the CDF
For :
Check the endpoints: and
Step 3 — interval probability
Step 4 — the median
The median satisfies :
Step 5 — interpret
The median sits at 2.381 out of a range — well above the midpoint 1.5, because the density increases with and concentrates mass towards the right end.
Verify by differentiating back:
Answer
; on ; ; median .
Quantiles
The quantile function inverts the CDF:
The median is , quartiles are and , and the 95th percentile is
. The min is needed because the discrete CDF is a staircase and may jump past
rather than hitting it exactly.
import numpy as np
from scipy import stats
# Continuous: the worked example, f(x) = x²/9 on [0,3], F(x) = x³/27.
F = lambda x: np.clip(x, 0, 3) ** 3 / 27
print(f"P(1 ≤ X ≤ 2) = {F(2) - F(1):.4f} theory {7/27:.4f}")
print(f"median = {(27 * 0.5) ** (1/3):.4f}")
# Discrete: PMF, CDF, and the >= trap.
xs = np.array([1, 2, 4]); pmf = np.array([0.2, 0.5, 0.3])
cdf = np.cumsum(pmf)
print(f"\nCDF at {xs} = {cdf}")
print(f"P(X >= 2) = {1 - cdf[0]:.2f} <- 1 - F(1), NOT 1 - F(2)")
# Same idea with a named distribution: sf is the survival function 1 - cdf.
binom = stats.binom(n=10, p=0.3)
print(f"\nP(X >= 4) = {binom.sf(3):.4f} (sf(3) = 1 - F(3))")
print(f"wrong: {binom.sf(4):.4f} (excludes X = 4)")Exercise 1
is continuous with for . Find the density, the median, and .
Show solutionHide solution
Density — differentiate the CDF:
This is the exponential distribution with rate .
Median — solve :
Upper tail:
Worth noting: the mean of this distribution is , larger than the median . Right-skewed distributions have mean above median.
Exercise 2
A student writes for a continuous variable with density . Give two reasons this is wrong.
Show solutionHide solution
First, for any continuous variable. Probability comes from integrating the density over an interval, and the integral over the degenerate interval is zero. The correct statement involves a width:
Second, the value 0.8 is being misread as a probability. A density has units of "per unit ", so means probability accumulates at a rate of 0.8 per unit near . It carries no meaning as a probability on its own, and densities can legitimately exceed 1 — a uniform distribution on has everywhere on that interval, which would be nonsense if densities were probabilities.
The correct way to answer "how likely is near 2" is to pick an interval and integrate, or to report .
Next: Expectation, the first summary number computed from these functions.