Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 57 ยท Random Variables

CDFs and Continuous Random Variables

Learn the cumulative distribution function, probability density functions, how probability becomes area under a curve, and compute probabilities for uniform and normal variables with SciPy.

A discrete random variable puts probability on separate points. A continuous one, such as a waiting time or a height, spreads probability smoothly along a line. Asking for P(X = 2.5) exactly is meaningless: among infinitely many values, any one has probability zero. Instead, we ask about ranges. This lesson introduces the two functions that describe that: the density and the cumulative distribution.

The cumulative distribution function

The cumulative distribution function (CDF) works for both discrete and continuous variables:

F(x) = P(X โ‰ค x)

It starts at 0 on the far left, never decreases, and ends at 1 on the far right. It answers "what share of outcomes lies at or below x?". Percentiles are its inverse: the 90th percentile is the x where F(x) = 0.9.

For a fair die, the CDF is a staircase: F(1) = 1/6, F(2) = 2/6, ..., F(6) = 1. For any value between integers it stays flat: F(3.7) = 3/6.

Probabilities of ranges come from differences: P(a < X โ‰ค b) = F(b) - F(a).

Python The CDF of a die

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The probability density function

For a continuous variable the probability density function (PDF) f(x) describes how probability is spread out. It is not a probability itself. Instead:

P(a โ‰ค X โ‰ค b) = area under f between a and b

A valid density satisfies f(x) โ‰ฅ 0 everywhere and a total area of 1. Heights of f can exceed 1, since only areas are probabilities. If the density near 2.5 is high, values near 2.5 are relatively likely; to find an actual probability multiply by an interval width.

The link to the CDF: F(x) is the area under f up to x, and f is the slope of F. That is F(x) = integral of f, and f(x) = F'(x). In terms of ideas: the CDF accumulates, the PDF is the rate of accumulation.

flowchart LR
    D["PDF f(x)<br/>density, height of the curve"] -->|"area up to x"| C["CDF F(x)<br/>P(X <= x)"]
    C -->|"slope"| D
    C --> P["P(a < X <= b) = F(b) - F(a)"]

Density and cumulative function carry the same information in two forms.

A first continuous example: the uniform distribution

If a bus arrives at a random moment within a 10-minute window, the waiting time X is equally likely anywhere in 0 to 10. The density is flat: f(x) = 1/10 on [0, 10]. Then

  • P(X โ‰ค 3) = 3 * 1/10 = 0.3
  • P(4 โ‰ค X โ‰ค 7) = 3/10 = 0.3
  • P(X = 5) = 0

The CDF is the straight line F(x) = x/10 between 0 and 10.

Python Uniform waiting time with SciPy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

ppf is the percent point function (the inverse CDF); it returns percentiles.

The normal distribution, briefly

The most important continuous model is the bell-shaped normal distribution with mean mu and standard deviation sigma. Its density is a smooth symmetric curve. You do not integrate it by hand: tables or software supply the CDF. The empirical rule you already know is a statement about its CDF. The chapter on common distributions covers it fully.

Python Probabilities for a normal variable

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The probability within one standard deviation is about 0.683, matching the 68% rule. sf (survival function) is 1 - cdf and is more accurate for tail probabilities.

Plotting density and CDF together

Python PDF and CDF of the normal

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Expected value and variance for continuous variables

The definitions replace sums with integrals: E[X] = integral of x * f(x) dx, Var(X) = E[(X - mu)^2]. Every rule from the previous lesson, such as linearity, remains true. For the uniform distribution on [a, b]: mean (a + b)/2, variance (b - a)^2 / 12. For [0, 10] that gives 5 and 8.33.

Discrete versus continuous at a glance

Discrete Continuous
Described by PMF p(x) = P(X = x) PDF f(x) (density)
Probability of a single value Can be positive Always 0
Event probability Sum of PMF values Area under the PDF
CDF Staircase Smooth curve

Common mistakes

  • Reading a density value as a probability. Heights above 1 are fine.
  • Believing P(X = x) > 0 for a continuous variable.
  • Forgetting that P(a โ‰ค X โ‰ค b) and P(a < X < b) are equal for continuous variables.
  • Mixing up cdf (area to the left) and sf (area to the right).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. For a continuous random variable, P(X = 3) equals...

    A single point has zero width, so zero area under the density.
  2. 2. X is uniform on [0, 20]. What is P(X <= 5)?

    The CDF is x/20, so F(5) = 0.25.
  3. 3. Which property is true of every CDF?

    F(x) = P(X <= x) accumulates probability, so it is non-decreasing from 0 to 1.
  4. 4. A density function can have height 4 at some point. Is that possible?

    Density is not probability. A narrow tall peak can still enclose an area of 1.

Summary

  • The CDF F(x) = P(X โ‰ค x) works for all random variables and gives range probabilities by subtraction.
  • Continuous variables are described by a density; probability is the area under it.
  • Single points have probability 0 for continuous variables.
  • The uniform and normal distributions are the first continuous models; SciPy provides pdf, cdf, sf and ppf.
  • The same ideas of mean and variance carry over, with integrals instead of sums.

Next: Joint Distributions and Covariance