
Math 183 • Statistical Methods • Spring 2026
% % \providecommand{}{p_{0}} \providecommand{}{p_{1}} \providecommand{}{p_{2}} \providecommand{}{p_{12}} \providecommand{1n}{p_{1n}} % % % % $$
Random variable
A random variable is a variable which assumes values based on the outcome of a trial from a random phenomenon.
Tip
Think of a random variable as a placeholder for the different outcomes we can witness from a trial.
Notation
Random variables are usually denoted by capital letters (e.g., \(X, Y, Z, V, W\)) from the end of the alphabet.
Support
The support of a random variable is the universe of all possible values a random variable can assume.
Types of random variables
Since a random variable is simply a “placeholder” for the values a variable can take … random variables are also divided into groups based on its support.
Recall the main types of variables from Week-1:
Coin toss
You flip a coin. The random variable, \(X\), is a placeholder for the outcome of the coin toss.
1) The support of the random variable is \(\text{supp}(X) = \left\{H, T\right\}\), i.e., \[\left\{X=H\right\} \quad\text{or}\quad \left\{X=T\right\}\]
2) This is an example of a nominal categorical random variable
Computer-friendly Convention
Usually, a discrete outcome is “encoded” as {0, 1}, i.e.,
– \(X=1\) is understood to be that the outcome is \(H\), and
– \(X=0\) is understood to be that the outcome is \(T\).
For categorical variables, this usually evident from the problem (but not always ⚠️)
This class
You’re bored in your Math 183 class and you’ve also just had lunch. To keep yourself entertained you decide to count how many times you yawn. If \(X\) denotes this random variable:
1) The support of the random variable is \(\text{supp}(X) = \left\{1, 2, 3, \dots\right\}\), i.e., \[\left\{X=1\right\}, \quad\text{or} \left\{X=2\right\},\quad\text{or}\dots\quad\text{or} \left\{X=100\right\}, \quad \dots\] 2) This is an example of a discrete quantitative random variable
BMI
We pick a student at random and ask them what their BMI is (weight ÷ height\(^2\)). Let \(X\) denote this random variable:
1) The support of the random variable is \(\text{supp}(X) = {\mathbb R}\), i.e., \[\left\{X=x\right\}, \quad\text{for any}\quad x \in {\mathbb R}\] 2) This is an example of a continuous quantitive random variable
Every random variable has:
A support, \(\text{supp}(X)\)
A probability distribution \({\mathbb P}_X\).
Measures of central tendency and dispersion.
Probability Distribution
A probability distribution, \({\mathbb P}\), associated with a random variable \(X\) describes the probability with \(X\) can take on the possible values in its support.
Tip
A probability distribution is the minimum amount of information you need in order to determine the probabilities for all possible events you can create from a random variable
Suppose the random variable \(X\) denotes a randomly chosen student’s favorite primary color.
| \(\text{supp}(X)\) | Red | Blue | Green |
|---|---|---|---|
| \({\mathbb P}(\left\{X=x\right\})\) | 0.20 | 0.55 | 0.25 |
You can use this information to find, for example,
\[ {\mathbb P}\left(\left\{X = \text{Red or Green}\right\}\right) = {\mathbb P}\left(\left\{X = \text{Red}\right\} \cup \left\{X = \text{Green}\right\}\right) \]
Probability Mass Function
For a discrete random variable \(X\), the assignment \[x \mapsto {\mathbb P}(X=x) =: \color{red}{p(x)}\] for every \(x \in \text{supp}(X)\) is called its probability mass function.

| \(\text{supp}(X)\) | Red | Blue | Green |
|---|---|---|---|
| \({\mathbb P}(\left\{X=x\right\})\) | 0.20 | 0.55 | 0.25 |
Conditional Probability Mass Function
The distribution of \(X\) conditional on the event \(A\), denoted \(X|A\), denoted \(p_{X}(x|A)\), is given by the conditional probability mass function \[ p_{X}(x | A) = {\mathbb P}(X=x | A) = {\mathbb P}(\left\{X=x\right\} | A) \]
Joint Probability Mass Function
The distribution of \(X\) and \(Y\) is given by the joint PMF \[ p_{X,Y}(x,y) = {\mathbb P}(X=x, Y=y) = {\mathbb P}(\left\{X=x\right\} \cap \left\{Y=y\right\}) \] and conditioned on the event \(\left\{Y = y\right\}\) the conditional PMF of \(X | \left\{Y=y\right\}\) is \[ p_{X|Y}(x | y) = {\mathbb P}(X=x | Y=y) = {\mathbb P}\left(\left\{X=x\right\} | \left\{Y=y\right\}\right) \]
Conditional Probability Mass Function
The distribution of \(X\) is given by the joint probability mass function \(p_{X,Y}(x, y)\) \[ p_{X,Y}(x,y) = {\mathbb P}(X=x, Y=y) = {\mathbb P}(\left\{X=x\right\} \cap \left\{Y=y\right\}) \]
If \(X \perp\kern-5pt \perp Y\): \[\begin{aligned} p_{X,Y}(x, y) &= {\mathbb P}(\left\{X=x\right\} \cap \left\{Y=y\right\})\\ &= {\mathbb P}(\left\{X=x\right\}) \times {\mathbb P}(\left\{Y=y\right\})\\ &= p_{X}(x) \times p_{Y}(y) \end{aligned}\]
If \(X \not\perp\kern-5pt \perp Y\): \[\begin{aligned} p_{X,Y}(x, y) &= {\mathbb P}(\left\{X=x\right\} \cap \left\{Y=y\right\})\\ &= {\mathbb P}(\left\{X=x\right\} | \left\{Y=y\right\}) {\mathbb P}(\left\{Y=y\right\}) \quad\quad\text{recall week-2}\\ &= p_{X|Y}(x | y) p_{Y}(y)\\ \end{aligned}\]
\[ p_{X,Y}(x, y) = \begin{cases} p_{X}(x) \times p_{Y}(y) & X \perp\kern-5pt \perp Y\\ p_{X|Y}(x | y) \times p_{Y}(y) & X \not\perp\kern-5pt \perp Y \end{cases} \]
Given a quantitative random variable \(X\) with PMF \(p_{X}(x)\)
The Cumulative Distribution Function (CDF) of a discrete random variable \(X\) is defined as:
\[F_X(x) = P(X ≤ x)\]
Essentially, the CDF at a point x is the probability that the random variable X takes a value less than or equal to x.
For discrete random variables, the CDF is a step function.
\[a ≤ b \quad \text{then} \quad F(a) ≤ F(b)\]
#| standalone: true
#| viewerHeight: 600
#| components: viewer
#| layout: vertical
import numpy as np
import scipy
from scipy import stats
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from shiny import App, render, ui
from matplotlib.patches import Patch
# Generate a random sample
np.random.seed(0)
sample_data = np.random.randint(-5, 7, 1000)
sample_data = np.array([*np.random.randint(-3, 2, 1000), *sample_data])
sample_data = np.array([*np.random.randint(3, 5, 1000), *sample_data])
# Define the UI
app_ui = ui.page_fluid(
ui.layout_sidebar(
ui.sidebar(
ui.input_slider(
"x_val",
"x",
min = float(np.floor(sample_data.min())-0.5),
max = float(np.ceil(sample_data.max())+0.5),
value = 0.0,
step = 0.5,
ticks=True,
animate=False
)
),
ui.output_plot("plots", height="500px")
)
)
# Define the server logic
def server(input, output, session):
@output
@render.plot
def plots():
x = input.x_val()
# Create figure and axes
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
# Histogram Plot
ax_hist = axes[0]
bins = 11
counts, bins, patches = ax_hist.hist(sample_data, bins=bins, color='lightgrey', edgecolor='black', density=True, align='left', width=0.5)
# Color the bars <= x in blue
for patch, bin_edge in zip(patches, bins):
if bin_edge <= x:
patch.set_facecolor('dodgerblue')
# Add vertical line at x
ax_hist.axvline(x, color='red', linewidth=1, alpha=0.5)
ax_hist.set_xticks(np.arange(-5, 6, 1))
ax_hist.set_title("Probability Mass Function (PMF)")
ax_hist.set_xlabel("Support")
ax_hist.set_ylabel("p(x)")
ax_hist.set_ylim(0, 1.0)
# CDF Plot
ax_cdf = axes[1]
Xrange = np.linspace(-5.5, 5.5, 200)
ecdf = lambda x: np.sum(sample_data <= x) / len(sample_data)
Y = [ecdf(x) for x in Xrange]
ax_cdf.plot(Xrange, Y, color='dodgerblue')
ax_cdf.axhline(ecdf(x), color='red', linewidth=1, linestyle='--', alpha=0.25)
ax_cdf.axvline(x, ymax=ecdf(x), color='red', linewidth=0.25, alpha=0.25)
# Add vertical line at x
ax_cdf.axvline(x, color='red', linewidth=2)
ax_cdf.set_title("Cumulative Distribution Function (CDF)")
ax_cdf.set_xlabel("Support")
ax_cdf.set_xticks(np.arange(-5, 6, 1))
ax_cdf.set_ylabel("F(x)")
ax_cdf.set_ylim(-0.05, 1.05)
ax_cdf.set_xlim(-5.5, 5.5)
plt.tight_layout()
return fig
# Create the Shiny app
app = App(app_ui, server)
app
You’ve just made an amazing (in your opinion) TikTok short which has a potential for going viral.
With probability \(0.1\), the TikTok will really go viral, leading to \(10,000\) additional followers
With probability \(0.9\), your TikTok is not as good as you thought it was, and it leads to \(0\) additional followers.
How many additional followers do you expect to have after you post your TikTok?
Expectation
The expectation of a (quantitative) random variable \(X\) is a weighted-average of all possible outcomes of \(X\), weighted by the probability of each outcome over its support.
\[\begin{aligned} {\mathbb E}(X) &= \sum_{x \in \text{supp}(X)} x \times {\mathbb P}(X=x)\\ &= \sum_{x \in \text{supp}(X)} x \times p_{X}(x) \end{aligned}\]
Let \(X\) be the random variable representing the number of additional followers you get on TikTok.
| \(\text{supp}(X)\) | \(10,000\) (viral) | \(0\) (not viral) |
|---|---|---|
| \(p(x)\) | 0.1 | 0.9 |
\[\begin{aligned} {\mathbb E}(X) &= \sum_{x \in \text{supp}(X)} x \times {\mathbb P}(X=x)\\ \\ &= (0.1 \times 10,000) + (0.9 \times 0)\\ \\ \therefore {\mathbb E}(X) &= 1,000. \end{aligned}\]
For two random variables \(X\) and \(Y\), and for two constants \(a, b \in {\mathbb R}\), \[ {\mathbb E}(aX + bY) = a {\mathbb E}(X) + b {\mathbb E}(Y) \]
Why?
\[ \begin{aligned} {\mathbb E}(aX + bY) &= \sum_{x \in \text{supp}(X)}\sum_{ y \in \text{supp}(Y)} (ax + by) \cdot p_{X,Y}(x, y)\\ &= a\sum_{x \in \text{supp}(X)}\sum_{ y \in \text{supp}(Y)} x \cdot p_{X,Y}(x,y) + b \sum_{x \in \text{supp}(X)}\sum_{ y \in \text{supp}(Y)} y \cdot p_{X,Y}(x,y)\\ &= a\sum_{x \in \text{supp}(X)} x \left(\sum_{ y \in \text{supp}(Y)} p_{X,Y}(x,y)\right) + b \sum_{y \in \text{supp}(Y)} y \left(\sum_{ x \in \text{supp}(X)} p_{X,Y}(x,y)\right)\\ &= a\sum_{x \in \text{supp}(X)} x \cdot p_{X}(x) + b \sum_{y \in \text{supp}(Y)} y p_{Y}(y)\\ &= a{\mathbb E}(X) + b {\mathbb E}(Y) \end{aligned} \]
Expected value of \(Y = f(X)\)
\[ {\mathbb E}(f(X)) = \sum_{x \in \text{supp}(X)} {\mathbb P}(X=x) \times f(x) \]
Consider the following two gambling scenarios:
You flip a fair coin.
\[\begin{aligned}{\mathbb E}(X) &= \Big(\frac{1}{2} \times \$10\Big) + \Big(\frac 12 \times \ -$10\Big)\\ \\ &= \$0\end{aligned}\]
You roll a fair die:
\[\begin{aligned}{\mathbb E}(X) &= \Big(\frac{1}{6} \times \$60\Big) + \Big(\frac 56 \times \ -$12\Big)\\ \\ &= \$0\end{aligned}\]
Which of these two senarios do you prefer? Still the same?
Variance
The variance of a (quantitative) random variable \(X\) is a measure of the spread or dispersion of the random variable \(X\) around its expected value.
\[ {\text{Var}}(X) = \sum_{x \in \text{supp}(X)} {\mathbb P}(X=x) \times (x - {\mathbb E}(X))^2 \]
Equivalent formulation
\[ {\text{Var}}(X) = {\mathbb E}(X^2) - {\mathbb E}(X)^2 \]
Let \(X\) be the random variable representing your net gain.
| \(\text{supp}(X)\) | $10 | -$10 |
|---|---|---|
| \({\mathbb P}(X=x)\) | \(\frac 12\) | \(\frac 12\) |
\({\mathbb E}(X) = 0\)
\[\begin{aligned}{\text{Var}}(X) &= \left(\frac 12 \times (10 - 0)^2\right) + \left(\frac 12 \times (-10 - 0)^2\right)\\ \\ &= 100\end{aligned}\]
| \(\text{supp}(X)\) | $60 | -$12 |
|---|---|---|
| \({\mathbb P}(X=x)\) | \(\frac 16\) | \(\frac 56\) |
\({\mathbb E}(X) = 0\)
\[\begin{aligned}{\text{Var}}(X) &= \left(\frac 16 \times (60 - 0)^2\right) + \left(\frac 56 \times (-12 - 0)^2\right)\\ \\ &= 720\end{aligned}\]

Question
Which of the three distributions above has the largest variance?
Variance of a linear combination
For two independent random variables \(X\) and \(Y\) with \(X \perp\kern-5pt \perp Y\), and
for two constants \(a, b \in {\mathbb R}\), \[{\text{Var}}(aX + bY) = a^2 {\text{Var}}(X) + b^2 {\text{Var}}(Y).\]
Given a random variable \(X\) and an event \(A\)
The conditional expectation of \(X\) given the event \(A\) is \[\begin{aligned} {\mathbb E}(X|A) &= \sum_{x \in \text{supp}(X)} x \times {\mathbb P}(X=x | A)\\ &= \sum_{x \in \text{supp}(X)} x \times p_{X}(x|A) \end{aligned}\]
The conditional variance of \(X\) given the event \(A\) is \[\begin{aligned} {\text{Var}}(X|A) &= \sum_{x \in \text{supp}(X)} (x - {\mathbb E}(X|A))^2 \times {\mathbb P}(X=x | A)\\ &= \sum_{x \in \text{supp}(X)} (x - {\mathbb E}(X|A))^2 \times p_{X}(x|A) \end{aligned}\]