1.3.6 · D2Probability & Statistics

Visual walkthrough — Probability mass and density functions

1,958 words9 min readBack to topic

Prerequisites we lean on: 1.3.01-Random-variables-and-distributions (what a random variable is), and we finish by touching 1.3.07-Cumulative-distribution-functions.


Step 1 — A random variable is a labelling machine

WHAT. A random variable is just a rule that reads an outcome of some experiment and prints a number. We write it . If the experiment is "roll a die," then might print the face value.

WHY. We can't do arithmetic on the word "heads" or on a die-face drawing. Turning every outcome into a number lets us add, average, and plot. Everything below is arithmetic on the printed numbers.

PICTURE. On the left are raw outcomes (the little icons). The machine maps each to a spot on the number line on the right.

Figure — Probability mass and density functions

Step 2 — The PMF: stack the chances of every outcome that prints the same number

WHAT. For a discrete variable (finitely many, or countably many, separated printed values) the probability mass function is

Reading the equation left to right: is the number we want — the chance the machine prints exactly . The sum says "walk through every raw outcome whose print is ." is the chance of that one raw outcome. We add them.

WHY add? Because those raw outcomes are different, non-overlapping events. The additivity axiom of probability says the chance of "this OR that OR ..." (for disjoint events) is the sum of chances. Nothing fancier is allowed.

PICTURE. Two dice, sum. Six different rolls print . Their six chances (each ) stack into one bar of height .

Figure — Probability mass and density functions

Step 3 — What breaks when values become continuous

WHAT. Now let be a continuous measurement — a waiting time, a height, a house price. Ask: "What is , exactly?"

WHY it breaks. There are infinitely many possible values crammed into any interval. If each single value had a positive chance , then adding up infinitely many of them would blow past — impossible. The only escape: each single point must have chance .

PICTURE. As we allow finer and finer values, the PMF bars shrink toward the floor. A bar chart of zeros tells us nothing. We need a new object.

Figure — Probability mass and density functions

Step 4 — Rescue plan: measure chance per unit length (density)

WHAT. Instead of asking about single points, chop the number line into thin bins of width . Each bin does have positive chance. Define a new quantity — height so that height × width = bin chance:

Term by term: the numerator is the honest, positive chance of landing in the bin. Dividing by the width gives chance per unit length — a density. That is what is.

WHY divide? Because the bare bin-chance shrinks to as bins get thin, but the ratio chance/width settles onto a stable, finite number. Dividing out the width cancels the shrinking, exposing the shape that survives.

PICTURE. A histogram where the area of each bar equals its chance. Halving the bin width halves each bar's chance but keeps the height (density) roughly fixed — the outline stabilises.

Figure — Probability mass and density functions

Step 5 — Let the bins vanish: the sum becomes an integral

WHAT. The chance of a whole interval is the sum of its bins' chances. Each bin's chance is (height × width, from Step 4). So

WHY an integral, and not just a sum? As we have infinitely many infinitely thin bars. "Sum of height × width, as width → 0" is exactly the definition of the Riemann integral. We didn't invent calculus here — we bumped into it. The symbol is a stretched "S" for "Sum," and is the vanished .

PICTURE. Bars fuse into a smooth region; the staircase of rectangles becomes the shaded area under the curve between and .

Figure — Probability mass and density functions

Step 6 — The CDF ties both worlds together

WHAT. Define the Cumulative Distribution Function — "chance of landing at or below ": Here is a dummy sweeping variable that runs from up to the ceiling ; it just names the position we integrate over so the ceiling stays free.

WHY. is the running total of density from the far left up to — a probability you can read off directly (unlike density). Set the ceiling and and subtract to recover any interval: .

Undo it. By the Fundamental Theorem of Calculus, the density is the slope of the running total: Where rises steeply (probability piling up fast), is tall. Where is flat, .

PICTURE. Top: the density (a bump). Bottom: its running-area , an S-shape climbing from to ; the steepest part of the S sits under the peak of the bump.

Figure — Probability mass and density functions

More on this object lives in 1.3.07-Cumulative-distribution-functions.


Step 7 — Two edge cases you must be able to draw

WHAT. Test the machinery on the simplest continuous law and a decaying one.

(a) Uniform on . Equal chance everywhere means constant density on . Area must be : . So on , outside. Then .

(b) Exponential (waiting time), rate . CDF for . Differentiate: . It's tallest at (short waits common) and decays (long waits rare). Total area: .

WHY these two. The uniform shows a density that isn't a probability yet integrates to (here it happens to equal , a coincidence of unit width). The exponential shows a density that starts above the range of a PMF is irrelevant — density can be if , yet the total area is still exactly .

PICTURE. Left: the flat uniform box, shaded region = . Right: the exponential's decay, whole area = .

Figure — Probability mass and density functions

The one-picture summary

Figure — Probability mass and density functions

The whole journey on one canvas: discrete bars (chance you can point at) → shrink the bins → a smooth density curve whose shaded area is the chance of an interval → its running total climbs the S-shaped CDF from to .

Recall Feynman retelling — say it back in plain words

A random variable is a machine that turns each outcome into a number. For a die you can point at a bar: "sum-of-seven happens of the time," because six different rolls print seven and you add their chances. But when the number can be anything — a height, a wait — no single value can keep a positive chance, or the infinitely many of them would burst past . So each exact point has chance zero. To recover something useful, I chop the line into thin bins, measure each bin's honest chance, and divide by the bin's width. That ratio — chance per unit length — is the density. As the bins shrink to nothing, "add up height times width" becomes an integral, and the density becomes a smooth curve. The area under that curve over an interval is the interval's probability; the whole area is . Sweeping the area from the far left up to a moving ceiling gives the CDF, and the density is just how steeply that running total climbs. Test it: a flat box on (uniform) and a decaying (waiting times) both wrap up exactly one unit of area — and both densities are allowed to poke above , because a density was never a probability in the first place.

Recall Quick self-check

Why can a PDF value exceed 1 but a PMF value cannot? ::: A PMF value is a probability (capped at 1); a PDF value is a rate (chance per unit length) and only becomes a probability after multiplying by a width. How does the sum in the PMF become the integral in the PDF? ::: Bin-chance = density × width; summing height×width as width→0 is the definition of the Riemann integral. What is for continuous , and why? ::: 0, because has zero width and hence zero area. How do you get the PDF back from the CDF? ::: Differentiate: — the density is the slope of the running total.

Related uses: this density-vs-mass split powers 1.3.08-Expected-value-and-variance, the catalogue in 1.3.09-Common-probability-distributions, 1.4.02-Maximum-likelihood-estimation, the class probabilities of 2.1.05-Softmax-activation, and 3.2.04-Gaussian-processes.