Probability Density Functions

A probability density function (PDF) describes a continuous random variable X. Probabilities are areas under its graph: P(a \le X \le b) = \int_a^b f(x)\,dx. A PDF is never negative, the total area under it is 1, and any single value of X has probability 0.

Before this lesson: Density Curves, Definite Integrals and Improper Integrals

From histograms to density

Think of a histogram of many measured values, such as reaction times, drawn so that each bar’s area is the fraction of values in that bin. As the data set grows and the bins get narrower, the tops of the bars settle into a smooth curve. That curve is the density.

A continuous random variable can take any value in an interval, so there are too many values to list one at a time. Instead, probability is spread along the axis, and f(x) tells you how thickly it is spread near x. The height f(x) is probability per unit of x, not a probability. Only areas are probabilities.

Probability density function rules

A function f is a probability density function when both conditions hold:

f(x) \ge 0 \text{ for all } x, \qquad \int_{-\infty}^{\infty} f(x)\,dx = 1

Then the probability that X lands in an interval is the area over that interval:

P(a \le X \le b) = \int_a^b f(x)\,dx

Because a single point has no width, P(X = a) = 0 for every a. So it doesn’t matter whether the endpoints are included: P(a \lt X \lt b) and P(a \le X \le b) are equal.

Steps

  1. Check that f(x) is never negative and that its total area is 1 (or use that fact to find an unknown constant).
  2. Write the probability as an integral of f over the interval in the question.
  3. Use only the part of the interval where the formula for f applies; f is 0 elsewhere.
  4. Integrate and evaluate at the limits.

Probability density function examples

Example 1: Find k, then a probability

X has density f(x) = kx² for 0 ≤ x ≤ 3, and f(x) = 0 elsewhere. Find k and P(1 ≤ X ≤ 2).

\int_0^3 kx^2\,dx = 1

The total area must be 1.

k\left[\dfrac{x^3}{3}\right]_0^3 = 1

Integrate with the power rule (see antiderivatives).

k\left(\dfrac{27}{3} - 0\right) = 1

Evaluate at the limits (see fundamental theorem of calculus).

9k = 1

Simplify.

k = \dfrac{1}{9}

Divide both sides by 9.

P(1 \le X \le 2) = \int_1^2 \dfrac{x^2}{9}\,dx

The probability is the area from 1 to 2.

P(1 \le X \le 2) = \left[\dfrac{x^3}{27}\right]_1^2

Integrate.

P(1 \le X \le 2) = \dfrac{8}{27} - \dfrac{1}{27} = \dfrac{7}{27}

Evaluate at the limits and subtract.

P(1 \le X \le 2) \approx 0.2593

Divide.

Answer: k = 1/9 and P(1 ≤ X ≤ 2) = 7/27 ≈ 0.2593.

Graph of the density f(x) = x²/9 for x from 0 to 3, rising from 0 to 1, with f(x) = 0 elsewhere. The region under the curve from x = 1 to x = 2 is shaded; its area is 7/27, about 0.259, which is P(1 ≤ X ≤ 2). The whole area under the curve is 1.
The shaded area is the probability in Example 1. The curve reaches a height of 1 at x = 3, but heights are not probabilities; areas are.

Example 2: Quiz times (word problem)

The time X, in minutes, that a student takes to finish a 10-minute quiz has density f(x) = x/50 for 0 ≤ x ≤ 10, and 0 elsewhere. Check that f is a valid density, then find the probability that a student takes more than 6 minutes.

\int_0^{10} \dfrac{x}{50}\,dx = \left[\dfrac{x^2}{100}\right]_0^{10} = \dfrac{100}{100} = 1

The total area is 1, and f(x) ≥ 0 on the interval.

P(X \gt 6) = \int_6^{10} \dfrac{x}{50}\,dx

The area from 6 to 10.

P(X \gt 6) = \left[\dfrac{x^2}{100}\right]_6^{10}

Integrate.

P(X \gt 6) = \dfrac{100}{100} - \dfrac{36}{100} = 0.64

Evaluate at the limits and subtract.

P(X \lt 6) = 1 - 0.64 = 0.36

Complement rule.

Answer: 0.64 of students take more than 6 minutes, and 0.36 finish in under 6 minutes.

Example 3: A density on an infinite interval

X has density f(x) = 2/x³ for x ≥ 1, and 0 for x below 1. Show that the total area is 1, and find P(X \gt 3) and P(X ≤ 2).

\int_1^{\infty} \dfrac{2}{x^3}\,dx = \lim_{b \to \infty} \left[-\dfrac{1}{x^2}\right]_1^b

Write the improper integral as a limit (see improper integrals).

\lim_{b \to \infty} \left(1 - \dfrac{1}{b^2}\right) = 1

Evaluate at the limits; 1/b² goes to 0.

P(X \gt 3) = \lim_{b \to \infty} \left(\dfrac{1}{9} - \dfrac{1}{b^2}\right) = \dfrac{1}{9}

The area to the right of 3.

P(X \le 2) = \left[-\dfrac{1}{x^2}\right]_1^2 = 1 - \dfrac{1}{4} = \dfrac{3}{4}

The area from 1 to 2, since f is 0 below 1.

Answer: the total area is 1, P(X \gt 3) = 1/9 \approx 0.111 and P(X ≤ 2) = 3/4.

Example 4: Which functions are densities?

Decide whether each function is a valid PDF. Each one is 0 outside the interval given. (a) f(x) = 1 − |x| for −1 ≤ x ≤ 1. (b) g(x) = x − 1/2 for 0 ≤ x ≤ 2. (c) h(x) = 1.5 for 0 ≤ x ≤ 2/3.

f(x) = 1 - |x| \ge 0 \text{ on } [-1, 1]

(a) f is never negative.

\tfrac{1}{2}(2)(1) = 1

(a) The graph is a triangle with base 2 and height 1 (see area of a triangle).

g(0) = -\tfrac{1}{2}

(b) g is negative near 0.

\int_0^2 \left(x - \tfrac{1}{2}\right)dx = 2 - 1 = 1

(b) The total area is 1, but that is not enough.

\int_0^{2/3} 1.5\,dx = 1.5 \cdot \tfrac{2}{3} = 1

(c) A rectangle with area 1.

Answer: (a) and (c) are valid PDFs. (b) is not, because it is negative for x between 0 and 1/2. Part (c) shows that a density can be larger than 1.

Example 5: A piecewise density and its median

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 P(1 ≤ X ≤ 4), P(X = 4) and the median distance.

0.3(2) + 0.1(4) = 0.6 + 0.4 = 1

Check the total: two rectangles.

P(1 \le X \le 4) = 0.3(2 - 1) + 0.1(4 - 2)

Split the area at x = 2.

P(1 \le X \le 4) = 0.3 + 0.2 = 0.5

Multiply, then add.

P(X = 4) = \int_4^4 f(x)\,dx = 0

A single point has no width.

0.3m = 0.5

The median m has area 0.5 to its left. It is below 2, because the area up to 2 is 0.6.

m = \dfrac{5}{3} \approx 1.67

Divide both sides by 0.3.

Answer: P(1 ≤ X ≤ 4) = 0.5, P(X = 4) = 0, and the median distance is 5/3 ≈ 1.67 km.

Common mistakes

MistakeExample of the errorFix
Reading f(a) as a probabilitySaying P(X = 1) = f(1) = 1/9 in Example 1For a continuous variable, P(X = 1) = 0. Probabilities are areas, so integrate f over an interval.
Requiring f(x) ≤ 1Rejecting h(x) = 1.5 in Example 4A density can be larger than 1. Only the total area must equal 1.
Checking only the total areaAccepting g(x) = x − 1/2 in Example 4Also check that f(x) ≥ 0 everywhere.
Using the formula outside its intervalIntegrating 2/x³ from 0 in Example 3Use the formula only where it applies (x ≥ 1); f is 0 elsewhere.
Forgetting to divide by the new exponentWriting the antiderivative of kx² as kx³, so 27k = 1, in Example 1The antiderivative is kx³/3, which gives 9k = 1 and k = 1/9.

Related ideas

Density as probability per unit

For a short interval, P(x ≤ X ≤ x + Δx) ≈ f(x)Δx. In Example 1, f(2) = 4/9, so P(2 ≤ X ≤ 2.01) ≈ (4/9)(0.01) ≈ 0.0044. The exact area is about 0.0045.

PDFs and PMFs

A discrete random variable has a probability mass function: probabilities sit at single points and add to 1. A continuous random variable has a density instead. Its probability is spread out, and integrals replace sums.

Density curves in statistics

The density curves lesson in Statistics finds areas with geometry and tables. With calculus, any density can be handled with an integral, including the normal distribution.

The cumulative distribution function

The area to the left of x, F(x) = P(X ≤ x), is the cumulative distribution function. It is the topic of the next lesson, Cumulative Distribution Functions.

Practice problems

  1. f(x) = kx for 0 ≤ x ≤ 4, and 0 elsewhere. Find k.
  2. With the density from Problem 1, find P(1 ≤ X ≤ 3).
  3. f(x) = 3x² for 0 ≤ x ≤ 1, and 0 elsewhere. Find P(X \gt \tfrac{1}{2}).
  4. f(x) = c(4 − x²) for −2 ≤ x ≤ 2, and 0 elsewhere. Find c.
  5. Is f(x) = x/4 for 0 ≤ x ≤ 2 (and 0 elsewhere) a PDF? Explain.
  6. f(x) = 3/x⁴ for x ≥ 1, and 0 elsewhere. Find P(X \gt 2).
  7. f(x) = ke^{-2x} for x ≥ 0, and 0 elsewhere. Find k.
  8. With k from Problem 7, find P(X ≤ 1).
  9. f(x) = 0.2 for 0 ≤ x ≤ 5, and 0 elsewhere. Find P(X = 3) and P(1 \lt X \lt 3).
  10. f(x) = 2x for 0 ≤ x ≤ 1, and 0 elsewhere. Find the median of X.
Show answers

1.

\int_0^4 kx\,dx = k\left[\dfrac{x^2}{2}\right]_0^4 = 8k

Integrate and evaluate at the limits.

8k = 1

The total area is 1.

k = \dfrac{1}{8}

Divide both sides by 8.

Answer: k = 1/8

2.

P(1 \le X \le 3) = \int_1^3 \dfrac{x}{8}\,dx = \left[\dfrac{x^2}{16}\right]_1^3

Integrate with k = 1/8.

P(1 \le X \le 3) = \dfrac{9}{16} - \dfrac{1}{16} = \dfrac{1}{2}

Evaluate at the limits and subtract.

Answer: 1/2

3.

P(X \gt \tfrac{1}{2}) = \int_{1/2}^1 3x^2\,dx = \left[x^3\right]_{1/2}^1

Integrate.

P(X \gt \tfrac{1}{2}) = 1 - \dfrac{1}{8} = \dfrac{7}{8}

Evaluate at the limits and subtract.

Answer: 7/8

4.

\int_{-2}^2 c(4 - x^2)\,dx = c\left[4x - \dfrac{x^3}{3}\right]_{-2}^2

Integrate.

c\left[\left(8 - \dfrac{8}{3}\right) - \left(-8 + \dfrac{8}{3}\right)\right] = \dfrac{32}{3}c

Evaluate at the limits and simplify.

\dfrac{32}{3}c = 1

Set the total area equal to 1.

c = \dfrac{3}{32}

Multiply both sides by 3/32.

Answer: c = 3/32

5.

\int_0^2 \dfrac{x}{4}\,dx = \left[\dfrac{x^2}{8}\right]_0^2 = \dfrac{4}{8} = \dfrac{1}{2}

Find the total area.

Answer: no. It is never negative, but its total area is 1/2, not 1.

6.

P(X \gt 2) = \lim_{b \to \infty}\left[-\dfrac{1}{x^3}\right]_2^b

An antiderivative of 3x⁻⁴ is −x⁻³.

P(X \gt 2) = \lim_{b \to \infty}\left(\dfrac{1}{8} - \dfrac{1}{b^3}\right) = \dfrac{1}{8}

Evaluate the limit.

Answer: 1/8

7.

\int_0^{\infty} e^{-2x}\,dx = \lim_{b \to \infty}\left[-\tfrac{1}{2}e^{-2x}\right]_0^b

Integrate (see u-substitution).

\lim_{b \to \infty}\left(\tfrac{1}{2} - \tfrac{1}{2}e^{-2b}\right) = \tfrac{1}{2}

Evaluate the limit; the exponential goes to 0.

k \cdot \tfrac{1}{2} = 1

Set the total area equal to 1.

k = 2

Multiply both sides by 2.

Answer: k = 2

8.

P(X \le 1) = \int_0^1 2e^{-2x}\,dx = \left[-e^{-2x}\right]_0^1

Integrate.

P(X \le 1) = 1 - e^{-2} \approx 0.8647

Evaluate at the limits; use a calculator for the exponential.

Answer: about 0.8647

9.

P(X = 3) = 0

A single value has probability 0.

P(1 \lt X \lt 3) = 0.2(3 - 1) = 0.4

Area of a rectangle.

Answer: P(X = 3) = 0 and the interval probability is 0.4

10.

\int_0^m 2x\,dx = m^2

Area to the left of the median m.

m^2 = \tfrac{1}{2}

Set the area equal to 1/2.

m = \dfrac{\sqrt{2}}{2} \approx 0.7071

Take the positive square root.

Answer: about 0.7071

Probability density function FAQ

What is a probability density function?

It is a function f(x) that gives the probabilities of a continuous random variable as areas: the probability that X falls between a and b is the integral of f from a to b. It is never negative, and its total area is 1.

Can a probability density function be greater than 1?

Yes. The height of a density is probability per unit, not a probability, so it can be larger than 1 on a short interval. Only the total area must equal 1.

What is the difference between a PDF and a PMF?

A probability mass function (PMF) gives P(X = x) for a discrete variable, and its values add to 1. A PDF describes a continuous variable, and you integrate it to get probabilities.

Why is P(X = a) = 0 for a continuous random variable?

The probability is the area over the interval from a to a, which has width 0. That is why including or leaving out an endpoint never changes a probability.

Summary

  • A probability density function f(x) gives probabilities as areas: P(a \le X \le b) = \int_a^b f(x)\,dx.
  • A valid PDF is never negative, and its total area is 1.
  • Use the total area to find an unknown constant k.
  • Any single value has probability 0, so endpoints don’t matter.
  • f(x) is a density, not a probability, so it can be larger than 1.

Previous lesson: Negative Binomial Distribution

Next lesson: Cumulative Distribution Functions

Back to the Probability Theory Index