
Lecture 11: Continuous Random Variables
August 22, 2026
๐ Last lecture we had a very math heavy lecture covering:
rbinom(), pbinom() and dbinom() functions๐ This lecture is again a little math heavy, and we shall be looking at:
rbinom(), pbinom() and dbinom() functionsRecall the following definitions:
Consider a random variable \(X\) that follows a \(\text{Binomial}(n,p)\) distribution.
The PMF and CDF of \(X\) respectively are
\[ \begin{align} p_X(k) & = \mathbb{P}(X=k) = {n \choose k} \cdot p^k \cdot (1-p)^{n-k} \\ \\ F_X(k) & = \mathbb{P}(X\leq k) = \mathbb{P}(X=0) + \mathbb{P}(X=1) + ... +\mathbb{P}(X=k) \end{align} \]
We have a quick practice with the rbinom(), pbinom() and dbinom() functions.
dbinom(), pbinom() & rbinom()dbinom() determines the probability of \(X\) taking a specific value, i.e. \(\mathbb{P}(X=k)\).pbinom() determines the CDF of \(X\) at a certain value, i.e. \(\mathbb{P}(X\leq k)\).rbinom() generates realizations from a \(X\sim\text{Binomial}(n,p)\) random variable.These functions each take the general form of the base R functions that exist for the key named distributions (some of which we will cover later).
We summarize these functions in the table below:
| Binomial | Poisson | Geometric | Role |
|---|---|---|---|
dbinom() |
dpois() |
dgeom() |
PMF |
pbinom() |
ppois() |
pgeom() |
CDF |
qbinom() |
qpois() |
qgeom() |
Quantile |
rbinom() |
rpois() |
rgeom() |
Simulation |
๐ Note that the discrete uniform is different since we use the sample() function instead.
A Poisson random variable describes the outcomes of an experiment counting occurrences in a fixed time interval when the mean rate of occurrence is known.
Formally, the PMF of the Poisson random variable \(X\sim\mathcal{P}(\lambda)\) with mean rate \(\lambda\) is:
\[ \mathbb{P}(X=k)=\frac{e^{-\lambda}\lambda^k}{k!};\quad k \in\{0,1,2,...\}. \]
๐ The CDF of this distribution is quite complicated mathematically and is not covered in this course.

Recall the roles of the functions dpois(), ppois() and rpois(). Below we demonstrate how to use them.
Examples
Compute \(\mathbb{P}(X=3)\) when \(X\sim\mathcal{P}(2)\).
Since \(\lambda\) is defined as the mean rate of occurrence, the expectation of a Poisson random variable is simply
\[ \mathbb{E}[X] = \lambda. \]
Recall \(X\sim\mathcal{P}(3)\) from our previous example. Applying the formula:
\[ \mathbb{E}[X] = 3. \]
This matches the simulation from the previous slide, which averaged to approximately 3:
๐ In general, for \(X\sim\mathcal{P}(\lambda)\), \(\mathbb{E}[X] = \lambda\).
So far we have been considering discrete random variables, i.e. random variables with discrete support:
What about continuous random variables with continuous support:
Remember that \(\mathbb{P}(X=k)\neq 0\) for any value \(k\) in the support of a discrete random variable \(X\).
๐ This is not true for a continuous random variable!
Returning to our dartboard example: the probability of hitting any single point is zero, but the probability of hitting a whole region is not.
The probability density function (PDF) of a continuous random variable \(X\) is a function \(f_X(x)\) such that for any \(a\leq b\), \[ \mathbb{P}(a\leq X\leq b) = \int_a^b f_X(x)\,dx. \]
The cumulative distribution function (CDF) of a continuous random variable \(X\) is \[ F_X(x) = \mathbb{P}(X\leq x) = \int_{-\infty}^x f_X(t)\,dt. \]
To consider a practical example, suppose buses arrive at a stop every 12 minutes. If you arrive at the bus stop at a random time, how long will you wait?
Let \(X\) be the time you wait for the bus, i.e. a continuous random variable supported on \((0,12)\).
To select a distribution we must consider what assumptions to make.
To make a claim about the distribution of \(X\) we make the following assumptions:
This is the continuous version of the uniform distribution, hence we define a continuous uniform random variable.
A continuous uniform random variable \(X\sim\mathcal{U}([a,b])\) with continuous support \([a,b]\) has probability density function
\[ f_X(x) = \begin{cases} \frac{1}{b-a} &\quad x\in[a,b] \\ 0 & \quad \text{otherwise}. \end{cases} \]
As a check, notice that the density integrates to 1 over its support, as required of any PDF:
\[ \int_a^b f_X(x)\,dx = \int_a^b \frac{1}{b-a}\,dx = \left[\frac{x}{b-a}\right]_a^b = \frac{b-a}{b-a} = 1. \]
In the case of our bus stop example the support is \([0,12]\), i.e. \(a=0\) and \(b=12\), and so for \(X\sim\mathcal{U}([0,12])\) we have that
\[ f_X(x) = \frac{1}{12};\quad x\in[0,12]. \]

You may have noticed that since we can only compute the probability that \(X\) falls in an interval, we are primarily interested in the CDF of continuous random variables, since
\[ \mathbb{P}(p\leq X\leq q)=\mathbb{P}(X\leq q) - \mathbb{P}(X\leq p) = F_X(q) - F_X(p). \]
Often it is challenging to write a closed form expression for the CDF, but in the case of the continuous uniform we find that the CDF is given by:
\[ F_X(x) = \mathbb{P}(X\leq x) = \frac{x-a}{b-a};\quad x\in [a,b]. \]
Using calculus, we can derive this CDF directly from the PDF by computing:
\[ \begin{align} F_X(x) & = \mathbb{P}(X\leq x) = \int_a^x f_X(y)\,dy \\ & = \int_a^x \frac{1}{b-a}\,dy = \left[\frac{y}{b-a}\right]_a^x \\ & = \frac{x-a}{b-a}. \end{align} \]
Letโs say we wish to compute analytically the probability that the wait time is between 3 and 7 minutes. This is equivalent to computing the shaded area:

We can compute this quickly using the CDF:
\[ \begin{align} \mathbb{P}(3\leq X\leq 7) & = \mathbb{P}(X\leq 7) - \mathbb{P}(X\leq 3) \\ & = \frac{7-0}{12-0} - \frac{3-0}{12-0} = \frac{1}{3}. \end{align} \]
This can clearly be computed using basic geometry, but to practice our calculus methods we can also arrive at the same answer directly:
\[ \begin{align} \mathbb{P}(3\leq X\leq 7) & = \int_3^7 f_X(x)dx \\ & = \int_3^7 \frac{1}{12}dx \\ & = \left[\frac{x}{12}\right]_3^7 \\ & = \frac{7}{12}-\frac{3}{12} = \frac{4}{12}=\frac{1}{3}. \end{align} \]
punif() FunctionR has the in-built function punif() for computing the uniform CDF \(\mathbb{P}(X\leq x)\), which has the syntax:
q is the quantile \(x\)min is the lower bound of the support \(a\)max is the upper bound of the support \(b\)Quick Examples: for \(X\sim\mathcal{U}([0,12])\),
[1] 0.5
[1] 1
Much like with discrete random variables we have 4 standard functions for each distribution:
| Uniform | Exponential | Normal | Role |
|---|---|---|---|
dunif() |
dexp() |
dnorm() |
|
punif() |
pexp() |
pnorm() |
CDF |
qunif() |
qexp() |
qnorm() |
Quantile |
runif() |
rexp() |
rnorm() |
Simulation |
๐ R has built-in d/p/q/r functions for many more continuous distributions too โ e.g. gamma (dgamma()), beta (dbeta()), chi-squared (dchisq()), Studentโs t (dt()), and log-normal (dlnorm()).
04:00
Use the functions from the previous slide to answer the following questions about the continuous uniform random variable \(X\sim\mathcal{U}(10,25)\):
lower.tail = FALSE)[1] 0.3333333
[1] 0.7333333
[1] 17.50824
punif(20, ..., lower.tail = FALSE) computes \(\mathbb{P}(X>20)\) directly using the upper tail of the CDF.runif(10000, ...) simulates 10000 realizations of \(X\), and mean() approximates \(\mathbb{E}[X]\) via their long-run average.The normal (Gaussian) distribution is the most important distribution in statistics. It is more commonly known as the bell curve.

We denote a normal random variable \(X\sim\mathcal{N}(\mu,\sigma^2)\).
The normal distribution is described by parameters:
In our previous plot above we used \(\mu=0\) and \(\sigma^2=\sigma=1\), which is known as a standard normal distribution.

For normal random variable \(X\sim\mathcal{N}(\mu,\sigma^2)\) the density function is
\[ f_X(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(\frac{-(x-\mu)^2}{2\sigma^2}\right);\quad x\in\mathbb{R}. \]
Hence if we wish to determine \(\mathbb{P}(-1\leq X\leq 1)\) we determine
\[ \mathbb{P}(-1\leq X\leq 1) = \int_{-1}^1 \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(\frac{-(x-\mu)^2}{2\sigma^2}\right) dx, \]
which isnโt so easy to compute. Instead we can use R functions!
Compute \(\mathbb{P}(3\leq X\leq 10)\) when \(X\sim\mathcal{N}(4,3^2)\).
[1] 0.6078085
Approximate the mean of the sum of two \(X\sim\mathcal{N}(1,2^2)\) random variables using \(n=10000\) simulations.
[1] 1.965537
05:00
Suppose the heights of students in class A are normally distributed with a mean \(\mu=67\) inches and a standard deviation of \(\sigma=3\) inches.
Now consider class B student heights, which we suppose are normally distributed with mean \(\mu=70\) inches and a standard deviation of \(\sigma=4\) inches.
mean() on the logical comparison to approximate \(\mathbb{P}(X>Y)\) โ the proportion of simulations where the class A height exceeds the class B height.Stepping outside the bounds of the course for a moment, we take a look at this last simulation.
Define \(X\sim\mathcal{N}(67,3^2)\) and \(Y\sim\mathcal{N}(70,4^2)\).
We approximated via simulation:
\[ \mathbb{P}(X>Y)=\mathbb{P}(X-Y>0) \]
But can we compute this probability exactly?
A remarkable fact from probability theory: any linear combination of independent normal random variables is itself normal.
Suppose \(X_1\sim\mathcal{N}(\mu_1,\sigma_1^2)\) and \(X_2\sim\mathcal{N}(\mu_2,\sigma_2^2)\) are independent. Then
\[ X_1 - X_2 \sim \mathcal{N}\left(\mu_1-\mu_2,\; \sigma_1^2+\sigma_2^2\right). \]
The mean follows from linearity of expectation:
\[ \mathbb{E}[X_1-X_2] = \mathbb{E}[X_1] - \mathbb{E}[X_2] = \mu_1-\mu_2. \]
The variance follows since \(X_1\) and \(X_2\) are independent:
\[ \text{Var}(X_1-X_2) = \text{Var}(X_1) + \text{Var}(-X_2) = \sigma_1^2+\sigma_2^2. \]
Applying this to \(X\sim\mathcal{N}(67,3^2)\) and \(Y\sim\mathcal{N}(70,4^2)\) with \(\mu_1=67,\sigma_1=3,\mu_2=70,\sigma_2=4\), we get
\[ X-Y \sim \mathcal{N}\left(67-70,\; 3^2+4^2\right) = \mathcal{N}(-3, 25) = \mathcal{N}(-3, 5^2). \]

๐ค Today we covered a lot of material, including:
๐คฉ Next class we will conclude our exploration of probability by looking into: