Probability & Statistics · Probability density function

Probability density function

A probability density function f describes a continuous random variable X: the probability that X lands in an interval is the area under f over that interval. Split the line into bins of width w and divide each bin’s probability by w: as w shrinks, the bars settle onto f.

Probability density function in this visualization

A probability density function ff describes a continuous random variable XX through areas: P(a≤X≤b)=∫abf(x) dxP(a \le X \le b) = \int_a^b f(x)\,dx, where f≥0f \ge 0 and the total area is 1. Here the line is cut into bins of width ww, and each bar is a bin’s exact probability, either as it is or divided by ww, drawn over ff; below it is the cumulative distribution function FF. With the bars as densities, halving ww brings them onto ff; there are five distributions to try, one of them drawn by hand.

What does the height f(x)f(x) measure? Probability per unit length, not probability. A bin’s probability divided by its width is the average of ff over the bin, so where ff is continuous at xx, the bar around xx tends to f(x)f(x) as ww shrinks, and a short interval has P(x≤X≤x+Δx)≈f(x) ΔxP(x \le X \le x + \Delta x) \approx f(x)\,\Delta x. That is why a density can exceed 1 even though no probability does: probability is the area, and a tall, narrow region can have a small area. A single point is an interval of width 0, so P(X=x)=0P(X = x) = 0 whatever f(x)f(x) is, and for such a variable ≤\le and << give the same probabilities.

How do the density and the cumulative distribution function fit together? F(x)=P(X≤x)F(x) = P(X \le x) is the area under ff to the left of xx, so the area over [a,b][a, b] above is the rise F(b)−F(a)F(b) - F(a) below. A bin’s probability is the rise of FF across the bin, so the bar divided by ww is the slope of the secant of FF over that bin. As ww shrinks, the secant turns toward the tangent: where ff is continuous, F′(x)=f(x)F'(x) = f(x), which is the fundamental theorem of calculus. Where ff jumps, as at the ends of the uniform, FF has a corner, and its slopes from the two sides are the values of ff on the two sides. Changing ff at a single point changes no area, so no probability changes either.

Why is a histogram divided by its bin width before it is compared with a density? Without the division the bars are probabilities, and they sink toward 0 as the bins narrow, not toward ff. Divided by ww, the bars over the whole line have total area 1 whatever the width, so histograms with different bins can be compared with each other and laid over ff. A histogram of data works the same way, with each bin’s share of the sample in place of its exact probability.

Things to notice

  • The largest bin probability in the record sinks toward 0, but no probability is lost: the bins multiply as they narrow, and their total stays the same.
  • The bins start at 0, so from w=1/2w = 1/2 on their ends fall on every jump of these densities. A bin across a jump would mix the two sides, and the largest deviation would stay at least half the jump however small ww became.

Controls

  • Press either layer to choose the point whose bin is selected and where the tangent touches; drag a ▲ handle to set the interval, and drag aa past the left edge for −∞-\infty.
  • With Draw chosen and the bars showing density, draw on the upper layer: the curve is scaled to area 1.

Related