Continuous Probability Distributions

PDF, CDF, Quantiles, and Expectations

Joel Sanqui (Appalachian State University)

Introduction

A continuous random variable is a variable that can take any value within a continuous range or interval (e.g., height, time, temperature).

Unlike discrete variables, the probability of a continuous variable taking an exact single value is always zero: \(P(X = x) = 0\)

Instead, we define probabilities over intervals using specific mathematical functions.

Probability Density Function (PDF)

The Probability Density Function (PDF), denoted as \(f(x)\), represents the relative likelihood of a continuous random variable falling near a given point.

Key Properties:

  • Non-negativity: \(f(x) \geq 0\) for all \(x\).
  • Total Area: The total area under the curve is exactly 1: \(\int_{-\infty}^{\infty} f(x) \, dx = 1\).
  • Interval Probability: The probability that \(X\) falls between \(a\) and \(b\) is the area under \(f(x)\) from \(a\) to \(b\): \(P(a \leq X \leq b) = \int_{a}^{b} f(x) \, dx\).

Cumulative Distribution Function (CDF)

The Cumulative Distribution Function (CDF), denoted as \(F(x)\), gives the probability that the random variable \(X\) is less than or equal to a certain value \(x\).

Definition:

\(F(x) = P(X \leq x) = \int_{-\infty}^{x} f(t) \, dt\)

Key Properties

  • \(F(x)\) is non-decreasing.
  • \(\lim_{x \to -\infty} F(x) = 0\) and \(\lim_{x \to \infty} F(x) = 1\).
  • \(P(a \leq X \leq b) = P(a < X < b) = F(b) - F(a)\).
  • The PDF is the derivative of the CDF: \(f(x) = \frac{d}{dx}F(x)\).

Quantiles and Percentiles

The Quantile Function (or inverse CDF) finds the value \(x_p\) such that the probability of the variable being less than or equal to \(x_p\) is exactly \(p\) (where \(0 \leq p \leq 1\)).

Definition:

\(F(x_p) = p \implies x_p = F^{-1}(p)\)

Common Quantiles:

  • Median (\(x_{0.50}\)): The 50th percentile; splits the distribution in half.
  • Lower Quartile (\(x_{0.25}\)): The 25th percentile.
  • Upper Quartile (\(x_{0.75}\)): The 75th percentile.

Expectations: Mean and Variance

Expectations summarize the central tendency and spread of a continuous distribution.

Expected Value or Mean (\(\mu\)):

The long-run average or center of mass of the distribution. \(E[X] = \mu = \int_{-\infty}^{\infty} x \cdot f(x) \, dx\)

Variance (\(\sigma^2\)):

A measure of the dispersion or spread around the mean. \(Var(X) = \sigma^2 = E[(X - \mu)^2] = \int_{-\infty}^{\infty} (x - \mu)^2 \cdot f(x) \, dx\)

\(\text{Alternative Formula: } Var(X) = E[X^2] - (E[X])^2\)

Example 1: Continuous Uniform Distribution

The Continuous Uniform Distribution models a scenario where all outcomes within a bounded interval \([a, b]\) are equally likely.

Formulas

  • PDF: \(f(x) = \frac{1}{b-a}\) for \(a \leq x \leq b\)
  • CDF: \(F(x) = \frac{x-a}{b-a}\) for \(a \leq x \leq b\), \(F(x) = 0\) for \(x <a\) and \(F(x) = 1\) if \(x > b\)
  • Mean: \(E[X] = \frac{a+b}{2}\) and Variance: \(Var(X) = \frac{(b-a)^2}{12}\)

library(ggplot2)
ggplot(data.frame(x = c(2, 8)), aes(x = x)) +
  stat_function(fun = dunif, args = list(min = 2, max = 8), color = "blue", size = 1.2) +
  labs(title = "Uniform PDF U(2, 8)", y = "f(x)", x = "x") +
  theme_minimal()

Proofs of the formulas in Example 1

For \(a \leq x \leq b\):

\(F(x) = \int_{a}^{x} f(t) \, dt = \int_{a}^{x} \frac{1}{b-a} \, dt\) \(= \left[ \frac{t}{b-a} \right]_{a}^{x} = \frac{x - a}{b-a}\)

\(E[X] = \int_{a}^{b} x \cdot \frac{1}{b-a} \, dx\) \(= \frac{1}{b-a} \left[ \frac{x^2}{2} \right]_{a}^{b}\) \(= \frac{b^2 - a^2}{2(b-a)} = \frac{(b-a)(b+a)}{2(b-a)}=\frac{(b+a)}{2}\)

Variance formula derivation

Using the alternative identity: \(Var(X) = E[X^2] - (E[X])^2\)

\(E[X^2] = \int_{a}^{b} x^2 \cdot \frac{1}{b-a} \, dx = \frac{1}{b-a} \left[ \frac{x^3}{3} \right]_{a}^{b} = \frac{b^3 - a^3}{3(b-a)} = \frac{a^2 + ab + b^2}{3}\)

Substitute \(E[X^2]\) and \((E[X])^2\) back into the formula:

\(Var(X) = \frac{a^2 + ab + b^2}{3} - \left(\frac{a+b}{2}\right)^2 = \frac{a^2 + ab + b^2}{3} - \frac{a^2 + 2ab + b^2}{4}\) \(= \frac{4a^2 + 4ab + 4b^2 - 3a^2 - 6ab - 3b^2}{12} = \frac{a^2 - 2ab + b^2}{12} = \frac{(b-a)^2}{12}\)

Example 2

Arrival time of some particles are uniformly distributed over the next 2 to 12 minutes. What is the probability that a particle will arrive between 5 and 10 minutes? What is the 75th percentile of the arrival times?

We are working with a continuous uniform random variable \(X \sim U(2, 12)\) representing the particle arrival time in minutes.

Probability Density Function (PDF): \(f(x) = \frac{1}{b - a} = \frac{1}{12 - 2} = \frac{1}{10} = 0.1 \quad \text{for } 2 \le x \le 12\)

Calculating \(P(5 < X < 10)\)

To find the probability over the interval \((5, 10)\), we integrate the constant PDF over those boundaries. Geometrically, this represents the area of a rectangle of \(\text{width} = 5\) and \(\text{height} = 1/10\):

\(\begin{aligned} P(5 < X < 10) &= \int_{5}^{10} f(x) \, dx \\ &= \int_{5}^{10} \frac{1}{10} \, dx \\ &= \frac{1}{10} \cdot (10 - 5) = \frac{5}{10} = \mathbf{0.5} \end{aligned}\)

Obtaining the 75th Quantile

To find the value \(x_{0.75}\) below which \(75\%\) of the data falls, we set the Cumulative Distribution Function (CDF) equal to \(0.75\):

\(F(x) = \frac{x - a}{b - a} = \frac{x - 2}{10}\)

\(\begin{aligned} \frac{x_{0.75} - 2}{10} &= 0.75 \\ x_{0.75} - 2 &= 0.75 \cdot 10 \\ x_{0.75} - 2 &= 7.5 \\ x_{0.75} &= 7.5 + 2 = \mathbf{9.5} \end{aligned}\)

Example 3:

Consider a random variable with pdf \(f(x) = 2 e^{-2x}\) if \(x > 0\) and 0 otherwise. Find \(P(X > 2)\), the CDF \(F(x)\) and the mean and variance of X.

Answers

  • PDF: \(f(x) = 2e^{-2x}\) for \(x > 0\)
  • CDF: \(F(x) = 1 - e^{-2x}\)
  • Mean: \(E[X] = \frac{1}{2}\)
  • Variance: \(Var(X) = \frac{1}{4}\)

Example 3 PDF Plot

library(ggplot2)
ggplot(data.frame(x = c(0, 4)), aes(x = x)) +
  stat_function(fun = dexp, args = list(rate = 2), color = "blue", size = 1.2) +
  labs(title = "Exponential PDF f(x) = 2e^(-2x)", y = "f(x)", x = "x") +
  theme_minimal()

Finding \(P(X > 2)\)

To find the probability that \(X > 2\), we integrate the PDF from \(2\) to \(\infty\):

\[P(X > 2) = \int_{2}^{\infty} 2e^{-2x} \, dx\]

Evaluating the definite integral: \[P(X > 2) = \left[ -e^{-2x} \right]_{2}^{\infty} = 0 - (-e^{-4}) = e^{-4}\] Numerical value: \[P(X > 2) \approx 0.01832\]

Finding the Cumulative Distribution Function (CDF)

The CDF \(F(x) = P(X \le x)\) is found by integrating the PDF from \(-\infty\) to \(x\).

For \(x \le 0\): \[F(x) = 0\] For \(x > 0\): \[F(x) = \int_{0}^{x} 2e^{-2t} \, dt = \left[ -e^{-2t} \right]_{0}^{x} = -e^{-2x} - (-e^{0}) = 1 - e^{-2x}\]

Complete CDF Summary

Combining both cases, the full Cumulative Distribution Function is:

\[F(x) = \begin{cases} 1 - e^{-2x} & \text{if } x > 0 \\ 0 & \text{if } x \le 0 \end{cases}\]

Finding the Mean \(E[X]\)

The expected value (mean) is defined as: \[E[X] = \int_{0}^{\infty} x \cdot 2e^{-2x} \, dx\] Using integration by parts (\(\int u \, dv = uv - \int v \, du\)):

Let \(u = x \implies du = dx\) and let \(dv = 2e^{-2x}dx \implies v = -e^{-2x}\)

\[E[X] = \left[ -xe^{-2x} \right]_{0}^{\infty} - \int_{0}^{\infty} (-e^{-2x}) \, dx\]

\[E[X]= 0 + \left[ -\frac{1}{2}e^{-2x} \right]_{0}^{\infty} = 0 - \left( -\frac{1}{2} \right) = \frac{1}{2} = 0.5\]

Finding the Variance

We use the formula: \(Var(X) = E[X^2] - (E[X])^2\). First, calculate \(E[X^2]\): \[E[X^2] = \int_{0}^{\infty} x^2 \cdot 2e^{-2x} \, dx\] Using integration by parts again: * Let \(u = x^2 \implies du = 2x \, dx\) * Let \(dv = 2e^{-2x}dx \implies v = -e^{-2x}\)

\[E[X^2] = \left[ -x^2 e^{-2x} \right]_{0}^{\infty} - \int_{0}^{\infty} (-e^{-2x})(2x) \, dx\]

Finding the Variance

\[E[X^2] = 0 + \int_{0}^{\infty} 2x e^{-2x} \, dx = E[X] = \frac{1}{2}\]

Now substitute \(E[X^2]\) and \(E[X]\) into the variance formula:

\[Var(X) = E[X^2] - (E[X])^2\] \[Var(X) = \frac{1}{2} - \left(\frac{1}{2}\right)^2 = \frac{1}{2} - \frac{1}{4} = \frac{1}{4} = 0.25\]

The Four Uniform Functions in R

R provides four core functions for the continuous uniform distribution \(U(a, b)\):

  • dunif(x, min, max): Probability Density Function (PDF).
  • punif(q, min, max): Cumulative Distribution Function (CDF).
  • qunif(p, min, max): Quantile Function (Inverse CDF).
  • runif(n, min, max): Random Variate Generation.

Default parameters are min = 0 and max = 1.

dunif() — Probability Density

Because every outcome is equally likely across a continuous range, the density height is a flat line at \(1 / \text{max} - \text{min})\).

x_vals <- seq(0, 15, length.out = 500)
density_vals <- dunif(x_vals, min = 2, max = 12)

plot(x_vals, density_vals, type = "l", lwd = 3, col = "aquamarine",
     main = "PDF: dunif(min = 2, max = 12)", xlab = "x", ylab = "Density")
abline(h = 0, lty = 2, col = "gray")

punif() — Cumulative Probability

punif(x) calculates the area under the PDF curve to the left of value \(x\) (i.e., \(P(X \le x)\)).

prob_vals <- punif(x_vals, min = 2, max = 12)

plot(x_vals, prob_vals, type = "l", lwd = 3, col = "gold",
     main = "CDF: punif(min = 2, max = 12)", xlab = "q", ylab = "P(X <= q)")

# Example lookup: P(X <= 7)
prob_at_7 <- punif(7, min = 2, max = 12)
points(7, prob_at_7, col = "red", pch = 19, cex = 1.5)
text(7, prob_at_7, labels = paste0("punif(7) = ", prob_at_7), pos = 4, col = "red")

qunif() — Quantiles (Inverse CDF)

qunif(p) reverses punif. You pass a probability \(p\) (between 0 and 1), and it returns the corresponding data value \(x\) where \(P(X \le x) = p\).

p_inputs <- seq(0, 1, length.out = 100)
q_outputs <- qunif(p_inputs, min = 2, max = 12)

plot(p_inputs, q_outputs, type = "l", lwd = 3, col = "orchid",
     main = "Quantile Function: qunif(min = 2, max = 12)", xlab = "Probability (p)", ylab = "Quantile Value (x)")
# Find the 75th percentile
p75 <- qunif(0.75, min = 2, max = 12)
points(0.75, p75, col = "red", pch = 19, cex = 1.5)
text(0.75, p75, labels = paste0("qunif(0.75) = ", p75), pos = 2, col = "red")

runif() — Random Sampling

runif(n) draws \(n\) random, independent samples from the continuous uniform corridor. As \(n \to \infty\), the sample distribution matches the theoretical PDF.

set.seed(123)
simulated_data <- runif(10000, min = 2, max = 12)

hist(simulated_data, freq = FALSE, breaks = 25, col = "deepskyblue",
     main = "Random Samples: runif(10000, min = 2, max = 12)", xlab = "Value")
# Overlay the theoretical density flatline
curve(dunif(x, min = 2, max = 12), add = TRUE, col = "red", lwd = 3)

Summary

Key ideas for continuous probability distributions:

  • PDF (\(f(x)\)): Needs to be integrated to obtain probabilities, its value is not a probability unlike the pmf for discrete case.
  • CDF (\(F(x)\)): Integrates the density from left to right to obtain \(P(X \leq x)\).
  • Quantiles (\(F^{-1}(p)\)): Lets you work backward from a probability threshold to an exact target value.
  • Expectations (\(E[X], Var(X)\)): Mean and variance of X are integrals.
  • R functions for continuous uniform distribution dunif, punif, qunif, runif

References

  • Properties of the Distribution Ross, S. M. (2014). A First Course in Probability (9th ed.). Pearson.

  • Computational Software: R Core Team (2026). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria. Available at https://www.R-project.org/.