Probability

Random Variables

↩ Back
01

What Is a Random Variable

Definition
From outcomes to numbers

A random variable $X$ attaches a number to every outcome $\omega$ (one single result, like HHT) from the sample space $\Omega$ (the set of all possible results), so we can work with numbers instead of listing outcomes.

$X(\omega) \in \mathbb{R}, \quad \omega \in \Omega$

Example

Notation for the probability of getting at least two heads when flipping three coins, before and after introducing $X$.

Without XWith X = number of heads
$P(\{HHT, HTH, THH, HHH\})$$P(X \ge 2)$
Distinction
Discrete vs continuous

Random variables fall into two broad families, depending on what kind of values they can take.

TypeValuesExamples
Discrete countable, often integers number of heads in 3 flips, dice rolls, number of emails per day
Continuous any value in an interval waiting time, height, temperature
Notation
Introduced in this section
SymbolMeaning
$X$a random variable, uppercase by convention
$x$a specific value $X$ could take, lowercase by convention
support of $X$the set of values $X$ can actually take
02

Probability Mass Function (PMF)

Definition
Probability of each value

For a discrete random variable, the PMF gives the probability that $X$ equals a specific value $x$.

$p(x) = P(X = x)$

It must satisfy two conditions to make sense as a probability.

1$p(x) \ge 0$ for every value $x$ in the support
2$\sum_x p(x) = 1$, all the probability mass adds up to one
Example
PMF of the coin flip count

Continuing the three flip example, counting outcomes for each value of $X$ gives this PMF.

$x$outcomes with this count$p(x)$
0TTT$\frac{1}{8}$
1HTT, THT, TTH$\frac{3}{8}$
2HHT, HTH, THH$\frac{3}{8}$
3HHH$\frac{1}{8}$
Notation
Introduced in this section
SymbolMeaning
$p(x)$PMF, probability that $X$ equals $x$
03

Cumulative Distribution Function (CDF)

Definition
Accumulating probability up to x

The CDF works for both discrete and continuous variables. It answers "what is the chance $X$ is at most this value?".

$F(x) = P(X \le x)$

For a discrete variable, $F(x)$ is a step function: it stays flat between possible values of $X$ and jumps up by $p(x)$ exactly at each value $X$ can take.

$F(x) = \sum_{x_i \le x} p(x_i)$
Properties
What every CDF must satisfy
1non-decreasing: $F(x)$ never goes down as $x$ increases
2limits: $F(x) \to 0$ as $x \to -\infty$, $F(x) \to 1$ as $x \to \infty$
3right-continuous: no gap appears just after a jump

The CDF also gives interval probabilities directly, without needing the PMF or PDF at all.

$P(a < X \le b) = F(b) - F(a)$
Interactive
A loaded die: rolling x or less

This die is loaded, a trick die where each face has a different chance: $p(1){=}0.05$, $p(2){=}0.10$, $p(3){=}0.15$, $p(4){=}0.20$, $p(5){=}0.20$, $p(6){=}0.30$. Slide $x$ to pick a face value, the chart on the right shows the probability of rolling $x$ or less.

3
Result
Probability of rolling x or less
F(x), rolling x or less 1 − F(x), rolling more than x

F(3) = P(rolling 3 or less) = 0.05 + 0.10 + 0.15 = 0.30
p(3) = P(rolling exactly 3) = 0.15
Notation
Introduced in this section
SymbolMeaning
$F(x)$CDF, probability that $X$ is at most $x$
04

Continuous Random Variables and the PDF

Distinction
Density instead of mass

A continuous variable can take infinitely many values in an interval, so the probability of any single exact value is zero.

$P(X = x) = 0 \text{ for any } x$

Example

Let $H$ be someone's height. No matter how precisely we measure, there are infinitely many decimal digits to pin down exactly.

$P(H = 1.650122\ldots) = 0$
Properties
What every PDF must satisfy

A probability density function $f(x)$ describes how likely values are near $x$. Probability comes from the area under $f$, not from $f(x)$ itself.

$P(a \le X \le b) = \int_a^b f(x)\,dx$

1$f(x) \ge 0$ everywhere, though $f(x)$ itself can exceed 1
2the total area under $f$ equals 1, $\int_{-\infty}^{\infty} f(x)\,dx = 1$
Interactive
Shrinking the window around a height

Look at heights near 170 cm. Instead of asking for exactly 170 cm, ask for a window $[170-\epsilon, 170+\epsilon]$, and shrink $\epsilon$ toward 0.

10.0
140 200 160.0 180.0

Window: [160.0, 180.0] cm, P ≈ 2 × 10.0 × 0.0165 = 0.33
Notation
Introduced in this section
SymbolMeaning
$f(x)$PDF, density of $X$ around $x$
05

Expectation

Definition
The long run average value

$E[X]$, also written as $\mu$, weighs every possible value of $X$ by how likely it is, giving the average outcome you would see if you repeated the experiment many times.

Discrete

$E[X] = \sum_x x \cdot p(x)$

Continuous

$E[X] = \int_{-\infty}^{\infty} x \cdot f(x)\,dx$
Properties
Linearity and functions of X

Expectation is linear, regardless of whether $X$ and $Y$ are independent.

$E[aX + b] = aE[X] + b$
$E[X + Y] = E[X] + E[Y]$

To find the expectation of a function of $X$, weigh $g(x)$ instead of $x$, no need to derive the distribution of $g(X)$ first.

$E[g(X)] = \sum_x g(x) \cdot p(x)$
Example
Expected value of a fair die roll
1
A fair die has $p(x) = \frac{1}{6}$ for $x = 1, \dots, 6$.
2
$E[X] = 1 \cdot \frac{1}{6} + 2 \cdot \frac{1}{6} + \dots + 6 \cdot \frac{1}{6} = \frac{21}{6} = 3.5$.
3
Notice that 3.5 is not a value the die can actually show. The expectation is an average over many rolls, not a prediction for any single roll.
Notation
Introduced in this section
SymbolMeaning
$E[X]$, $\mu$expectation, the long run average value of $X$
06

Variance and Standard Deviation

Definition
How spread out X is

Variance measures the average squared distance between $X$ and its own mean $\mu = E[X]$.

$\text{Var}(X) = E\big[(X - \mu)^2\big]$

Expanding the square gives a version that is usually faster to compute by hand.

$\text{Var}(X) = E[X^2] - (E[X])^2$
Properties
Standard deviation and scaling

Standard deviation $\sigma$ is the square root of the variance, back in the same units as $X$.

$\sigma = \sqrt{\text{Var}(X)}$

Shifting $X$ by a constant does not change how spread out it is, only scaling it does, and the scale factor gets squared.

$\text{Var}(aX + b) = a^2 \, \text{Var}(X)$
Example
Variance of a fair die roll
1
For a fair die, $p(x) = \frac{1}{6}$ for $x = 1, \dots, 6$, and we already found $E[X] = 3.5$.
2
$E[X^2] = 1^2 \cdot \frac{1}{6} + 2^2 \cdot \frac{1}{6} + \dots + 6^2 \cdot \frac{1}{6} = \frac{91}{6} \approx 15.167$.
3
$\text{Var}(X) = E[X^2] - (E[X])^2 = 15.167 - 3.5^2 = 15.167 - 12.25 = 2.917$.
4
$\sigma = \sqrt{2.917} \approx 1.708$, so a typical roll lands about 1.7 away from the mean of 3.5.
Notation
Introduced in this section
SymbolMeaning
$\text{Var}(X)$, $\sigma^2$variance, how spread out $X$ is around its mean
$\sigma$standard deviation, $\sqrt{\text{Var}(X)}$
07

Chebyshev's Inequality

Definition
A guarantee that works for any distribution

For any random variable $X$ with mean $\mu$ and variance $\sigma^2$, and any $k > 0$, only a limited share of the probability can sit far from the mean, no matter the shape of the distribution.

$P(|X - \mu| \ge k\sigma) \le \dfrac{1}{k^2}$
Example
Checking the bound against a fair die
1
From the previous sections, the fair die has $\mu = 3.5$ and $\sigma \approx 1.708$.
2
For $k = 2$, Chebyshev guarantees $P(|X - 3.5| \ge 2 \times 1.708) \le \frac{1}{4} = 0.25$.
3
That interval is $(3.5 - 3.416,\ 3.5 + 3.416) = (0.084,\ 6.916)$, which covers every face of the die from 1 to 6.
4
The true probability of landing outside it is actually 0, which is under 0.25, the Chebyshev bound.
Chebyshev's bound is safe, but not necessary tight.