Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 36 · Random Variables Review

Probability and Expectation Review

Review random variables, distributions, expectation, variance and independence, plus the six distributions you need for stochastic processes, with Python checks.

Stochastic processes are built from random variables, so a few facts must be second nature before you go further. This lesson reviews them quickly. If anything is unfamiliar, treat the Python examples as a lab where you can test the formulas yourself.

Random variables and distributions

A random variable X is a number determined by chance. Its distribution says how likely each value is.

  • A discrete variable has a probability mass function p(x) = P(X = x), with Σ p(x) = 1.
  • A continuous variable has a density f(x) >= 0, with ∫ f(x) dx = 1, and P(a <= X <= b) = ∫ from a to b of f(x) dx.
  • The cumulative distribution function (CDF) is F(x) = P(X <= x) for both kinds.

Expectation and variance

The expectation (mean) is the probability-weighted average:

Text
E[X] = Σ x p(x)        (discrete)
E[X] = ∫ x f(x) dx     (continuous)

For a function g, E[g(X)] = Σ g(x) p(x) (or the integral version). You do not need the distribution of g(X) itself.

The variance measures spread: Var(X) = E[(X - E[X])²] = E[X²] - (E[X])². The standard deviation is its square root.

Key rules:

Rule Condition
E[aX + bY] = aE[X] + bE[Y] always (linearity)
Var(aX + b) = a² Var(X) always
Var(X + Y) = Var(X) + Var(Y) if X and Y are independent (or merely uncorrelated)
E[XY] = E[X] E[Y] if X and Y are independent

Linearity needs no independence at all, and that is why it is so powerful.

Python Mean and variance of a fair die, three ways

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.

Independence

Events A and B are independent if P(A and B) = P(A) P(B). Random variables X and Y are independent if every pair of events about them is independent. Independence is the assumption behind most simple models, and later chapters relax it one step at a time (the Markov property is a weak form of dependence).

Six distributions you will use constantly

Distribution Where it appears Mean Variance
Bernoulli(p) one trial, success or failure p p(1-p)
Binomial(n, p) successes in n independent trials np np(1-p)
Geometric(p) trials until the first success (k = 1, 2, ...) 1/p (1-p)/p²
Poisson(λ) counts of rare events λ λ
Exponential(λ) waiting times (density λe^(-λx), x >= 0) 1/λ 1/λ²
Normal(μ, σ²) sums of many small effects μ σ²

The geometric and exponential distributions share a special feature called memorylessness: if you have already waited s units without success, the remaining wait has the same distribution as when you began. In symbols, P(X > s + t | X > s) = P(X > t). This property is the key to why Markov chains and Poisson processes are mathematically tractable, and we will use it in Chapter 5.

Python Check the table of means and variances

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.

Note that NumPy's exponential takes the scale 1/λ, not the rate λ. This mix-up is a classic source of bugs.

Joint distributions and covariance

For two variables, the covariance is Cov(X, Y) = E[XY] - E[X]E[Y]. It is 0 for independent variables (the converse is false). The correlation Cov(X, Y) / (σ_X σ_Y) always lies between -1 and 1.

For a sum, Var(X + Y) = Var(X) + Var(Y) + 2 Cov(X, Y). This is why dependent steps in a process make sums spread out more (positive covariance) or less (negative covariance) than independent steps.

flowchart LR
    A["Independent"] --> B["Cov = 0"]
    B -.->|"does NOT imply"| A
    C["Uncorrelated"] --> D["Var adds"]

Independence implies zero covariance, but zero covariance does not imply independence.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which identity holds for ANY random variables X and Y (no independence needed)?

    Linearity of expectation always holds. The other two need independence or zero covariance.
  2. 2. The mean of a Geometric(p) variable (trials until the first success) is...

    On average you need 1/p trials: for p = 0.25 that is 4.
  3. 3. What does memorylessness of the exponential distribution mean?

    Having already waited s gives no information about the remaining wait.
  4. 4. Two variables with Cov(X, Y) = 0 are always independent.

    Zero covariance is weaker than independence. For example, X uniform on {-1, 0, 1} and Y = X² have covariance 0 but are dependent.

Summary

  • A distribution gives a PMF or density; the CDF is P(X <= x).
  • E[X] is the weighted average; Var(X) = E[X²] - (E[X])².
  • Expectation is linear always; variances add for independent (or uncorrelated) variables.
  • Bernoulli, binomial, geometric, Poisson, exponential and normal cover most of what you need.
  • Geometric and exponential variables are memoryless.

Next: Conditional Probability and Conditional Expectation