Chapter 4 · OpenStax Ch 4

Discrete Random Variables

Random variables that count things, their expected values, and the named distributions.

4.1 Expectation

A random variable \(X\) is a number whose value depends on chance, like the face a die shows. Its probability distribution lists every possible value with its probability. The expected value is the probability-weighted average of the values,

\[\mu = E[X] = \sum x \, P(x),\]

and it is what the ordinary average of the outcomes settles toward after many repetitions. Roll the fair die and watch the sample mean wander, then calm down near 3.5. Now drag the weight of face 6 up. The probabilities change, the table recomputes \(\mu\), and the running mean settles somewhere new. The expected value need not be a possible outcome, and no die ever shows 3.5. It is a long-run average, not a prediction of the next roll.

Reading: OpenStax Introductory Statistics, Sections 4.1, 4.2.

Try it

  1. All six faces start with weight 1, a fair die. Expected value μ reads 3.5.
  2. Slide Weight of face 6 to 10. The light bars renormalise and μ moves toward 6.
  3. Press Roll 100 a few times. Dark bars pile under the light ones.
  4. Watch Sample mean close in on Expected value μ as Rolls grows.
  5. Slide a weight to 0 to remove a face. One face must always stay possible.

4.2 Variance of a random variable

Two dice can have the same expected value and behave very differently. One always shows 3 or 4, the other only 1 or 6. The variance of a random variable measures how far outcomes typically land from \(\mu\). It weights each squared distance by its probability,

\[\sigma^2 = \sum (x - \mu)^2 \, P(x), \qquad \sigma = \sqrt{\sigma^2}.\]

Each stick in the top chart is a distance \(x - \mu\), and the bottom chart shows how much each face contributes to \(\sigma^2\). Faces far from \(\mu\) contribute a lot even when they are unlikely. Roll the die and the sample variance \(s^2\) of the outcomes1 drifts toward \(\sigma^2\). Push the weights of faces 1 and 6 up and the rest down. Now \(\mu\) stays near 3.5 while \(\sigma^2\) grows.

1 The sample variance divides by \(n - 1\). Reading: OpenStax Introductory Statistics, Section 4.2.

Try it

  1. A fair die to begin with. Variance σ² reads 2.92.
  2. Slide Weight of face 1 and Weight of face 6 to 10. The variance climbs, because the far faces are now likely.
  3. The lower chart shows each face's contribution. The ends contribute most.
  4. Slide only Weight of face 3 and Weight of face 4 to 10. The variance falls toward zero.
  5. Press Roll 100 several times. Sample variance s² converges on σ².

4.3 The named discrete distributions

Some situations come up so often that their distributions have names. The binomial counts successes in \(n\) independent trials that share the same chance \(p\), and its probabilities are \(P(X = k) = \binom{n}{k} p^k (1-p)^{n-k}\). The geometric counts trials until the first success, which gives \(P(X = k) = (1-p)^{k-1} p\). The hypergeometric counts successes when drawing without replacement, so each draw changes the odds. The Poisson counts rare events at an average rate \(\lambda\), with \(P(X = k) = \lambda^k e^{-\lambda} / k!\).

Pick a distribution, read its one-line scenario, and move the sliders to see the shape respond. Then draw. The dark bars of real draws pile up under the light bars of theory, and the sample mean approaches \(E[X]\). The skill being built here is recognition. Given a story, which distribution is it?

Reading: OpenStax Introductory Statistics, Sections 4.3 to 4.6.

Try it

  1. Binomial is selected, with Trials n at 10 and Success chance p at 0.3. The light bars are P(X = k).
  2. Slide p to 0.8. The bars shift right and E[X] rises to 8.
  3. Press Draw 100 a few times. Dark bars of real draws fill in under the light ones.
  4. Compare Sample mean with E[X] and Sample variance with Var(X).
  5. Pick Geometric, Hypergeometric or Poisson. Each brings its own sliders and its own story line.