Statistics Chapter 6 of 15

Chapter 6: Random Variables and Discrete Distributions

Expected value, variance, binomial, geometric, Poisson

All chapters
On this page
What you will be able to do after this chapter
  • Define a random variable and distinguish discrete from continuous ones.
  • Build and check a probability mass function (PMF) and a cumulative distribution function (CDF).
  • Compute the expected value, variance, and standard deviation of a discrete random variable, and interpret them.
  • Apply the rules for linear transformations and for sums and differences of independent random variables.
  • Recognize when a situation is binomial, geometric, Poisson, or hypergeometric, and compute exact probabilities, means, and variances.
  • Use the 10 percent rule and the Poisson approximation, and choose the right model for a description.

In Chapter 5 we assigned probabilities to events. Most questions in statistics are about numbers produced by random processes: the number of defective items in a batch, the time until the first customer arrives, the mean of a sample. A random variable turns the outcome of a random process into a number so we can use the tools of algebra and calculus, and so we can talk about the "average" and the "spread" of a random outcome.

6.1

Random variables and probability distributions

Definitions
  • A random variable is a rule that assigns a number to each outcome of a random process. We write random variables in capitals (\(X, Y\)) and their observed values in lowercase (\(x, y\)).
  • A random variable is discrete if it takes a countable set of values (often integers such as counts). It is continuous if it can take any value in an interval (heights, times, weights).
  • The probability mass function (PMF) of a discrete \(X\) is \(p(x) = P(X = x)\). A valid PMF has \(p(x) \ge 0\) for all \(x\) and \(\sum_x p(x) = 1\).
  • The cumulative distribution function (CDF) is \(F(x) = P(X \le x) = \sum_{t \le x} p(t)\). It is nondecreasing, starts at 0, and ends at 1.
Random variable versus data

Before we collect data, \(X\) is uncertain: it has a distribution. After we observe it, we hold a fixed number \(x\). Probability theory describes the "before"; statistics uses the "after" to learn about the distribution. This distinction (a statistic computed from a random sample is itself a random variable) becomes central in Chapter 8.

Example 6.1: A PMF and probabilities from it

Let \(X\) be the number of defective items found when inspecting a small sample. Suppose the (hypothetical) distribution is

\(x\)0123
\(p(x)\)0.500.300.150.05
\(F(x)\)0.500.800.951.00

The probabilities are nonnegative and sum to 1, so this is a valid PMF. \(P(X \ge 2) = 0.15 + 0.05 = 0.20\), which also equals \(1 - F(1) = 1 - 0.80\). \(P(X = 1 \text{ or } 2) = 0.45\). "At most 2" is \(F(2) = 0.95\).

6.2

Expected value and variance

Mean (expected value) and variance of a discrete random variable \[\mu_X = E(X) = \sum_x x\,p(x)\] \[\sigma_X^2 = \operatorname{Var}(X) = E\big[(X-\mu)^2\big] = \sum_x (x-\mu)^2 p(x) = E(X^2) - \mu^2, \qquad \sigma_X = \sqrt{\operatorname{Var}(X)}.\]

The expected value is a probability-weighted average: the balance point of the PMF. It is not necessarily a value \(X\) can take (the expected number of children in a family can be 1.8). Its meaning comes from the law of large numbers: it is the long-run average of many independent repetitions. The variance is the probability-weighted average squared deviation, and the standard deviation \(\sigma\) is in the original units.

Expectation of a function

For any function \(g\), \(E[g(X)] = \sum_x g(x)\,p(x)\). You do not need the distribution of \(g(X)\) first. In particular \(E(X^2) = \sum x^2 p(x)\), which is what the shortcut formula for variance uses. Note that in general \(E(X^2) \ne [E(X)]^2\); the gap is exactly the variance.

Example 6.2: Mean and standard deviation from the PMF

Using the defect distribution of Example 6.1:

Mean

\(E(X) = 0(0.50) + 1(0.30) + 2(0.15) + 3(0.05) = 0.30 + 0.30 + 0.15 = 0.75\).

Variance by the definition

\(\operatorname{Var}(X) = (0-0.75)^2(0.50) + (1-0.75)^2(0.30) + (2-0.75)^2(0.15) + (3-0.75)^2(0.05) = 0.28125 + 0.01875 + 0.234375 + 0.253125 = 0.7875\).

Variance by the shortcut

\(E(X^2) = 0 + 1(0.30) + 4(0.15) + 9(0.05) = 1.35\), so \(\operatorname{Var}(X) = 1.35 - 0.75^2 = 0.7875\). Same answer.

Standard deviation

\(\sigma = \sqrt{0.7875} = 0.8874\). On average a sample has 0.75 defects, give or take about 0.89.

Example 6.3: Expected value of a game

A carnival game costs $5. You roll a fair die: a six pays $12, a five pays $3, and anything else pays nothing. Let \(X\) be the payout.

\(x\)0312
\(p(x)\)4/61/61/6

\(E(X) = 0 + 3/6 + 12/6 = 2.50\). The expected net gain is \(2.50 - 5 = -2.50\): on average you lose $2.50 per play. Also \(E(X^2) = 9/6 + 144/6 = 25.5\), so \(\operatorname{Var}(X) = 25.5 - 6.25 = 19.25\) and \(\sigma = \$4.39\). A casino, insurer, or carnival operator lives on the law of large numbers: any single play is uncertain, but the average over thousands of plays is very close to the expected value.

6.3

Rules for means and variances

Linear transformations

For constants \(a\) and \(b\),

\[E(aX + b) = a\,E(X) + b, \qquad \operatorname{Var}(aX + b) = a^2\operatorname{Var}(X), \qquad \sigma_{aX+b} = |a|\,\sigma_X.\]

Adding a constant shifts the mean but not the spread. Multiplying by \(a\) scales the mean by \(a\) and the standard deviation by \(|a|\). (Compare with Chapter 3, where the same rules held for data.)

Sums and differences of random variables
  • Means always add: \(E(X \pm Y) = E(X) \pm E(Y)\), with no conditions.
  • Variances add if \(X\) and \(Y\) are independent: \(\operatorname{Var}(X \pm Y) = \operatorname{Var}(X) + \operatorname{Var}(Y)\). Note the plus, even for a difference: uncertainty accumulates.
  • Standard deviations do not add. \(\sigma_{X+Y} = \sqrt{\sigma_X^2 + \sigma_Y^2}\).
  • For \(n\) independent, identically distributed copies with mean \(\mu\) and variance \(\sigma^2\): \(E(X_1 + \cdots + X_n) = n\mu\) and \(\operatorname{Var}(X_1 + \cdots + X_n) = n\sigma^2\), so the SD of the sum is \(\sigma\sqrt{n}\).
Example 6.4: Combining independent random variables

\(X\) has mean 10 and SD 3; \(Y\) has mean 7 and SD 4; they are independent.

\(E(2X - Y) = 2(10) - 7 = 13\). \(\operatorname{Var}(2X - Y) = 2^2(9) + (-1)^2(16) = 36 + 16 = 52\), so the SD is \(\sqrt{52} = 7.21\).

\(E(X - Y) = 3\) and \(\operatorname{Var}(X - Y) = 9 + 16 = 25\), so the SD is exactly 5 (not \(3 - 4\), which would be negative, and not \(3 + 4 = 7\)).

A total of 25 independent items, each with mean 4 and SD 1.5, has mean \(25 \times 4 = 100\) and SD \(1.5\sqrt{25} = 7.5\).

Independence matters for variances

The variance rule requires independence. If \(X\) and \(Y\) are positively correlated, \(\operatorname{Var}(X+Y)\) is larger than \(\operatorname{Var}(X) + \operatorname{Var}(Y)\); in general \(\operatorname{Var}(X+Y) = \operatorname{Var}(X) + \operatorname{Var}(Y) + 2\operatorname{Cov}(X,Y)\). For example, the total return of two stocks that move together is riskier than the independent-variance formula suggests. Also do not confuse \(X + X = 2X\) (perfectly dependent, variance \(4\sigma^2\)) with two independent copies \(X_1 + X_2\) (variance \(2\sigma^2\)).

6.4

The binomial distribution

Many situations count the number of "successes" in a fixed number of trials: heads in 10 flips, defective items in a batch, voters who favor a candidate in a poll, correct guesses on a multiple-choice test.

Binomial setting (BINS)
  • Binary: each trial results in success or failure.
  • Independent: the trials are independent.
  • Number: the number of trials \(n\) is fixed in advance.
  • Same probability: the probability of success \(p\) is the same on every trial.

Then \(X\), the number of successes, has the binomial distribution \(X \sim \text{Binomial}(n, p)\), written \(\text{Bin}(n,p)\). A single trial (\(n = 1\)) is a Bernoulli trial.

Binomial formulas \[P(X = k) = \binom{n}{k}p^k(1-p)^{n-k},\qquad k = 0, 1, \ldots, n.\] \[\mu = np, \qquad \sigma^2 = np(1-p), \qquad \sigma = \sqrt{np(1-p)}.\]

Why? Each specific sequence of \(k\) successes and \(n-k\) failures has probability \(p^k(1-p)^{n-k}\) (independence), and there are \(\binom{n}{k}\) sequences with exactly \(k\) successes.

Example 6.5: Binomial probabilities

A basketball player makes each free throw with probability 0.30 (independent shots). In 10 shots let \(X\) be the number made, \(X \sim \text{Bin}(10, 0.3)\).

\(P(X = 3) = \binom{10}{3}(0.3)^3(0.7)^7 = 120 \times 0.027 \times 0.0823543 = 0.2668\).

\(P(X \le 3) = P(0) + P(1) + P(2) + P(3) = 0.0282 + 0.1211 + 0.2335 + 0.2668 = 0.6496\).

\(P(X \ge 4) = 1 - P(X \le 3) = 0.3504\) (use the complement to avoid summing many terms).

Mean \(= 10(0.3) = 3\); SD \(= \sqrt{10(0.3)(0.7)} = 1.449\).

Example 6.6: Guessing on a multiple-choice test

A quiz has 10 multiple-choice questions with 4 options each. A student who guesses every question has \(X \sim \text{Bin}(10, 0.25)\).

The expected number correct is \(10(0.25) = 2.5\). The chance of passing with at least 6 correct is \(P(X \ge 6) = 0.0197\), about 2 percent. Guessing is not a strategy.

Check the conditions
  • Cards dealt without replacement from a small deck are not independent: not binomial (it is hypergeometric, Section 6.7).
  • If the number of trials is not fixed (roll until you get a six), it is not binomial (it is geometric).
  • If the success probability changes (a student who improves as the quiz goes on), it is not binomial.
  • Sampling without replacement from a large population is approximately binomial when the sample is less than 10 percent of the population (the 10 percent rule).
Going deeper: Deriving the binomial mean and variance from Bernoulli trials

Write \(X = I_1 + I_2 + \cdots + I_n\), where \(I_j = 1\) if trial \(j\) is a success and 0 otherwise. Each \(I_j\) is Bernoulli: \(E(I_j) = 1\cdot p + 0 \cdot (1-p) = p\), \(E(I_j^2) = p\), so \(\operatorname{Var}(I_j) = p - p^2 = p(1-p)\). Means add, so \(E(X) = np\). The \(I_j\) are independent, so variances add and \(\operatorname{Var}(X) = np(1-p)\). No summing of binomial coefficients is needed.

The variance \(np(1-p)\) is largest when \(p = 1/2\) and shrinks toward 0 as \(p\) approaches 0 or 1: a nearly certain outcome varies little.

6.5

The geometric distribution

Suppose we repeat independent trials, each with success probability \(p\), until the first success. The number of the trial on which the first success occurs, \(X\), has a geometric distribution, \(X \sim \text{Geom}(p)\), taking values \(1, 2, 3, \ldots\). This is a BINS situation without a fixed \(n\).

Geometric formulas \[P(X = k) = (1-p)^{k-1}p,\quad k = 1, 2, \ldots\qquad P(X \le k) = 1 - (1-p)^k \qquad P(X > k) = (1-p)^k.\] \[\mu = \frac{1}{p},\qquad \sigma^2 = \frac{1-p}{p^2}.\]

The PMF is always decreasing: the most likely value is 1. The mean \(1/p\) matches intuition: with \(p = 1/6\), the average wait for a six is 6 rolls.

Example 6.7: Waiting for the first success

A telemarketer's calls succeed with probability 0.20, independently. Let \(X\) be the number of the call on which the first sale occurs.

\(P(X = 4) = 0.8^3 (0.2) = 0.1024\). \(P(X \le 4) = 1 - 0.8^4 = 0.5904\). The mean wait is \(1/0.2 = 5\) calls and \(\sigma = \sqrt{0.8}/0.2 = 4.47\): waits vary a lot.

The memoryless property

Given that the first \(m\) trials were failures, the number of additional trials needed has the same geometric distribution as at the start: \(P(X > m + k \mid X > m) = P(X > k)\). Past failures do not make success "due". This is the gambler's fallacy in distribution form.

6.6

The Poisson distribution

The Poisson distribution models the number of events in a fixed interval of time or region of space when events occur independently, at a constant average rate, and (essentially) one at a time: calls to a help line per hour, typos per page, radioactive decays per second, accidents at an intersection per month.

Poisson formulas

If \(X\) counts events in an interval where the average number of events is \(\lambda\), then \(X \sim \text{Poisson}(\lambda)\) and

\[P(X = k) = \frac{e^{-\lambda}\lambda^k}{k!},\quad k = 0, 1, 2, \ldots\qquad \mu = \lambda,\quad \sigma^2 = \lambda.\]

The mean equals the variance. If the rate per unit time is \(r\), the mean count in an interval of length \(t\) is \(\lambda = rt\): rates scale with the length of the interval.

Example 6.8: Calls to a help desk

A help desk receives on average 3 calls per hour (hypothetical), so \(X \sim \text{Poisson}(3)\) for one hour.

\(P(X = 0) = e^{-3} = 0.0498\). \(P(X = 1) = 3e^{-3} = 0.1494\). So \(P(X \ge 2) = 1 - 0.0498 - 0.1494 = 0.8009\).

For two hours the mean is \(\lambda = 6\), so \(P(X = 6) = e^{-6}6^6/6! = 0.1606\). Notice that we changed \(\lambda\) to match the interval; we did not just double the probability.

Poisson as a limit of binomials

When \(n\) is large and \(p\) is small, \(\text{Bin}(n,p)\) is well approximated by \(\text{Poisson}(\lambda = np)\). For example, \(\text{Bin}(100, 0.03)\) gives \(P(X=2) = 0.2252\) while \(\text{Poisson}(3)\) gives 0.2240. The approximation is good when \(n \ge 20\) and \(p \le 0.05\), roughly. Use the tool below to watch it converge.

6.7

The hypergeometric distribution

The binomial needs independent trials. When we sample without replacement from a small finite population, each draw changes what remains. Suppose the population has \(N\) items, of which \(K\) are "successes"; we draw \(n\) items at random without replacement and let \(X\) count the successes.

Hypergeometric formulas \[P(X = k) = \frac{\binom{K}{k}\binom{N-K}{n-k}}{\binom{N}{n}},\qquad \mu = n\frac{K}{N},\qquad \sigma^2 = n\frac{K}{N}\left(1 - \frac{K}{N}\right)\frac{N-n}{N-1}.\]

The last factor \(\frac{N-n}{N-1}\) is the finite population correction. It shrinks the variance because sampling without replacement reveals more about the population than sampling with replacement. When \(n\) is less than about 10 percent of \(N\), the factor is close to 1 and \(X\) is approximately \(\text{Bin}(n, K/N)\).

Example 6.9: Defective items in a small lot

A lot of 10 items contains 4 defectives. Three are drawn at random without replacement. Let \(X\) be the number of defectives.

\(P(X = 1) = \dfrac{\binom{4}{1}\binom{6}{2}}{\binom{10}{3}} = \dfrac{4 \cdot 15}{120} = 0.5\). The (incorrect) binomial calculation with \(p = 0.4\) gives \(\binom{3}{1}(0.4)(0.6)^2 = 0.432\). The difference is large because the sample is 30 percent of the lot. For a lot of 1,000 with 400 defectives, the two answers would agree to three decimals.

6.8

Choosing the right distribution

DistributionWhat is random?ParametersMeanVariance
BernoulliOne trial: 1 or 0\(p\)\(p\)\(p(1-p)\)
BinomialSuccesses in \(n\) independent trials\(n, p\)\(np\)\(np(1-p)\)
GeometricTrial number of first success\(p\)\(1/p\)\((1-p)/p^2\)
PoissonEvents in an interval\(\lambda\)\(\lambda\)\(\lambda\)
HypergeometricSuccesses in \(n\) draws without replacement\(N, K, n\)\(nK/N\)\(n\frac{K}{N}(1-\frac{K}{N})\frac{N-n}{N-1}\)
Quick decision guide
  • Is the number of trials fixed? If yes and trials are independent, count successes: binomial. If drawing without replacement from a small population: hypergeometric.
  • Waiting for the first success? Geometric.
  • Counting events in continuous time or space with no upper limit? Poisson.
6.9

Chapter summary

Key ideas and formulas
  • PMF: \(p(x) \ge 0\), \(\sum p(x) = 1\). CDF \(F(x) = P(X \le x)\).
  • \(E(X) = \sum x p(x)\); \(\operatorname{Var}(X) = \sum (x-\mu)^2 p(x) = E(X^2) - \mu^2\).
  • \(E(aX+b) = aE(X)+b\); \(\operatorname{Var}(aX+b) = a^2\operatorname{Var}(X)\).
  • \(E(X \pm Y) = E(X) \pm E(Y)\); for independent variables \(\operatorname{Var}(X \pm Y) = \operatorname{Var}(X) + \operatorname{Var}(Y)\). SDs do not add.
  • Binomial: \(P(k) = \binom{n}{k}p^k(1-p)^{n-k}\), \(\mu = np\), \(\sigma^2 = np(1-p)\). Check BINS.
  • Geometric: \(P(k) = (1-p)^{k-1}p\), \(\mu = 1/p\), memoryless.
  • Poisson: \(P(k) = e^{-\lambda}\lambda^k/k!\), \(\mu = \sigma^2 = \lambda\); scales with the interval length; approximates \(\text{Bin}(n,p)\) for large \(n\) and small \(p\).
  • Hypergeometric: sampling without replacement; the binomial is a good approximation if \(n < 0.1N\).

Key terms

TermMeaning
Random variableA numerical outcome of a random process
PMF, CDF\(P(X=x)\) and \(P(X \le x)\)
Expected valueProbability-weighted average; long-run mean
Variance, SDExpected squared deviation from the mean; its square root
Bernoulli trialOne trial with two outcomes
BINSConditions for the binomial: binary, independent, number fixed, same probability
Finite population correctionThe factor \((N-n)/(N-1)\) in the hypergeometric variance
MemorylessPast failures do not change the distribution of the remaining wait
6.10

Practice