TL;DR
A continuous random variable can take any value in a range, such as a height or a waiting time. For such a variable, the probability of hitting one exact value is zero, so we describe it with a density instead: a function whose height tells you how concentrated the probability is near . The probability of landing in an interval is the area under over that interval.
Where you'll see it: in every model of a continuous quantity, from the bell curve of measurement error to the waiting-time models in queueing and the noise distributions inside generative models.
Intuition
Density is probability per unit width
A histogram of heights is a row of bars. Each bar's area is the fraction of people in that bin. Make the bins narrower and more numerous, and the staircase of bar tops smooths into a curve. That curve is the density. Its height at a point is not a probability. It is a probability per unit of , the same way a mass density is mass per unit of volume.
Physically: a thin metal rod has a density in kilograms per metre. The mass of a short piece is density times length. No single point of the rod has mass, but a piece of it does. A probability density works the same way. A point has zero width, so it holds zero probability. A small interval of width holds about .
This is also why the density can exceed 1. A density of 5 at some point just means that, locally, probability is packed five times tighter than one unit per unit width. What must equal 1 is the total area.
Why we need it
For a die roll the outcomes are discrete, and each face has a probability you can list. For a height or a waiting time, there are uncountably many possible values. Assigning each one a positive probability is impossible, since they would add up to more than 1. The density sidesteps this. It assigns zero to every point and a meaningful area to every interval, and the area is what we measure.
- exponential, rate 0.5
The math
Definition
A function is a probability density function for a continuous random variable if for every , and for every interval
where the total area is one:
Here is a value the variable can take, and is the density at that value. The integral is the definite integral from to , which adds up tiny slices of area. The two conditions say that is never negative and that the probabilities over the whole line add to 1.
Because a single point has no width, the integral from to is zero:
So for a continuous variable, , and are all the same number. The endpoints do not matter.
The cumulative distribution function
The probability of being at or below is the cumulative distribution function:
The density is the rate at which grows. By the fundamental theorem of calculus, wherever is continuous,
This gives a second way to find from : differentiate. It also explains why , which is often the easiest way to compute an interval probability by hand.
Expectation and spread
Averages of a continuous variable replace sums with integrals. The expected value of is
Taking gives the mean , and gives the variance . These are the same expectations and mean and variance you know from discrete variables, with the sum swapped for an integral.
Worked examples
Let be uniform on the interval from 0 to 2. Its density is constant on that interval and zero outside it:
Question 1: is a valid density?
- It is never negative.
- The area is the base times the height: . Yes.
Question 2: what is ?
- Integrate over the interval: .
- Half the probability sits in the middle half of the range, which matches the picture of a flat density.
Question 3: what is ?
- It is a single point, so the integral from 1 to 1 is 0. Even though is positive, the probability of exactly 1 is zero.
Let be uniform on , so on that interval and zero elsewhere.
- Check the total area: . It is a valid density.
- Its height is 2, which is bigger than 1. That is fine, because a density is probability per unit of , and the interval is short.
- . The left half of the interval holds half the probability, as it must for a flat density.
Suppose the waiting time , in minutes, follows the exponential density for , with rate per minute. The average wait is minutes.
Question 1: what is ?
- First find the cumulative function: . Then use the complement: .
- . About a 22% chance of waiting more than three minutes.
Question 2: what is ?
- Subtract the cumulative values: .
- and , so the answer is about .
- Interpretation: roughly a quarter of waits fall in that one-minute window, which is about what you would expect for a distribution whose mean is 2 minutes.
Tradeoffs and failure modes
A density is the right tool for continuous quantities and the wrong tool for counts. Most mistakes come from mixing the two up or from reading the height as a probability.
| Situation | Problem | Better choice |
|---|---|---|
| Reading as the probability of | Gives a number that can exceed 1 and has no meaning as a probability | Integrate over an interval, or use |
| Counting discrete outcomes such as dice or defects | There is no density for a countable set, and integrals do not apply | A probability mass function, with sums |
| Asking for the probability of an exact value | The answer is always 0 for a continuous variable | Ask for an interval, such as |
| Using a formula outside its support | An exponential density is for ; integrating the formula over negative gives wrong areas | Check the domain of before integrating |
| Estimating a density from data with a histogram | The shape depends heavily on bin width | Kernel density estimation, with a bandwidth you choose and check |
| Assuming a density exists for every random variable | Some mixtures of discrete and continuous parts have no density | Work with the cumulative distribution , which always exists |
The most common error in practice is the first row. A density reported as a probability above 1 is a sign that the integral was never taken.
History
The idea grew out of the eighteenth and nineteenth century work on measurement errors. Pierre-Simon Laplace and Carl Friedrich Gauss used continuous curves to describe errors in astronomical observations in the early 1800s, and those curves are densities in the modern sense. The formal framework came much later. In 1933 Andrey Kolmogorov put probability on a measure-theoretic footing, and in that setting a density is a derivative of one measure with respect to another. The density you use in practice is the special case where the measure is area under a curve.
It caught on because it turned a hard question about single points into an easy question about areas. That lets an engineer, a statistician and a machine learning researcher use the same tools, integrals, for very different continuous problems.
Check yourself
QuestionWhat does the area under a probability density function between and represent?Show answer
It is the probability that the random variable falls between and . Probabilities for a continuous variable are areas under the density, not heights of the density.
QuestionLet have density on and zero elsewhere. What is ?Show answer
. First check that is valid: . So the answer is one eighth.
QuestionIf a continuous random variable has , why is still zero, even though the density at 2 is positive?Show answer
The density is probability per unit width, not probability at a point. The probability of an exact value is the integral over an interval of zero width, and that integral is 0. The density at 2 says how much probability sits in a small interval around 2, roughly times the width of that interval, and that width shrinks to zero.
QuestionWaiting times at a service desk follow an exponential density with rate per minute. What is the probability that a customer waits more than 10 minutes?Show answer
Using with and , the answer is . About 37% of customers wait longer than ten minutes.