# 15.1. Density and CDF¶

Let \(f\) be a non-negative function on the real number line and suppose

Then \(f\) is called a *probability density function* or just *density* for short.

In the next section we will discuss the reason behind the name. For now, imagine the graph of \(f\) as a kind of continuous probability histogram. We will soon make that precise, but notice that by definition the total area under a density curve has to be 1.

Quick Check

Consider the function \(f(x) = \frac{1}{2}x\) for \(0 < x < 2\) and \(f(x) = 0\) elsewhere. Explain why \(f\) is a probability density. [It is quicker to use geometry than calculus.]

Answer

Non-negative, total area under the graph is 1

As an example, the function \(f\) defined by

is a density. It is easy to check by calculus that it integrates to 1.

**Note:** The calculus used in this text is very straightforward. You should be able to do it easily by hand. Later in this chapter we will give you some Python tools for calculus. We will also show how understanding probability can help us do calculus quickly.

Here is a graph of the function \(f\). The density puts all the probability on the unit interval.

## 15.1.1. Density is Not the Same as Probability¶

In the example above, \(f(0.5) = 6/4 = 1.5 > 1\). Indeed, there are many values of \(x\) for which \(f(x) > 1\). So the values of \(f\) are clearly not probabilities.

Then what are they? We’ll study that in the next section. In this section we will see that we can work with densities just as we did with the normal curve.

First, a labor-saving device: If \(f\) is positive only on a subinterval of the line, then usually we will just write its definition on the interval where it is positive. It will be assumed to be 0 elsewhere.

And we will draw the graph of \(f\) only over the region where it is positive:

## 15.1.2. Areas are Probabilities¶

A random variable \(X\) is said to *have density \(f\)* if for every pair \(a < b\),

This integral is the area between \(a\) and \(b\) under the density curve. The graph below shows the area corresponding to \(P(0.6 < X \le 0.8)\) for a random variable \(X\) that has the density in our example.

The area is

Quick Check

Let \(X\) have density \(f\) given by \(f(x) = \frac{1}{2}x\) for \(0 < x < 2\) and \(f(x) = 0\) elsewhere. Find \(P(X > 1)\).

Answer

\(0.75\)

## 15.1.3. Cumulative Distribution Function (CDF)¶

The cdf of \(X\) is the function \(F\) defined by

You are already familiar with the definition \(F(x) = P(X \le x)\). What’s new is that we can compute the probability by integrating the density function.

In our example, the only possible values of the random variable \(X\) are between 0 and 1, so \(F(x) = 0\) for \(x \le 0\) and \(F(x) = 1\) for \(x \ge 1\). For \(x\) between 0 and 1,

In terms of the graph of the density, \(F(x)\) is all the area to the left of \(x\) under the density curve. The graph below shows the area corresponding to \(F(0.8)\).

As before, the cdf can be used to find probabilities of intervals. For every pair \(a < b\),

That’s the same as the answer we got earlier in the section by integrating the density between 0.6 and 0.8.

By the Fundamental Theorem of Calculus, the density and cdf can be derived from each other:

You can use whichever of the two functions is more convenient in a particular application.

Also keep in mind that every cdf \(F\) satisfies some basic properties:

\(F(x) \to 0\) as \(x \to -\infty\)

\(F\) is non-decreasing

\(F(x) \to 1\) as \(x \to \infty\)