Random Variables and Probability Distributions
A random variable turns uncertain outcomes into numbers. Once outcomes are numeric, we can describe their long-run behavior with a probability distribution, compute expected values, and model real processes such as successes in repeated trials, arrivals in a time interval, or draws from a finite collection. The Lane text introduces the binomial, Poisson, multinomial, and hypergeometric distributions as probability models that later support inference.
The art is matching assumptions to context. A binomial model is natural for a fixed number of independent success/failure trials with constant success probability. A Poisson model is natural for counts of rare events in a fixed interval when events occur independently at a stable rate. A hypergeometric model is natural for sampling without replacement. When the model assumptions fail, the formula may still produce a number, but the number no longer answers the intended question.
Definitions
A random variable assigns a numerical value to each outcome of a random process. A discrete random variable has countable possible values, such as 0, 1, 2, and so on. A continuous random variable has possible values over intervals, such as time, length, or measurement error.
A probability mass function for a discrete random variable gives
for each possible value . The probabilities must be nonnegative and sum to 1. A cumulative distribution function is
For continuous variables, probabilities are areas under a density curve rather than heights at individual points. For a continuous random variable, for any exact value , even though intervals can have positive probability.
The expected value or mean of a discrete random variable is
The variance is
where . Standard deviation is .
A Bernoulli trial has two outcomes, usually called success and failure, with success probability . If is 1 for success and 0 for failure, then has a Bernoulli distribution with and .
If counts successes in independent Bernoulli trials with constant success probability , then has a binomial distribution:
A Poisson distribution with rate models counts in a fixed interval:
For a Poisson random variable, and .
Key results
The binomial distribution has mean and variance
These results match the idea that is the sum of independent Bernoulli variables. Expected values add, and independent variances add. If and each is Bernoulli(), then
The hypergeometric distribution models the number of successes in draws without replacement from a population of objects containing successes:
This distribution differs from the binomial because the draws are dependent: after one success is drawn, fewer successes remain.
The multinomial distribution generalizes the binomial to more than two categories. If independent trials fall into categories with probabilities , then counts have probability
where .
The Poisson distribution can approximate a binomial distribution when is large, is small, and is moderate. This approximation is useful for rare-event counts, but it should not hide the assumptions: events should occur independently and at a stable average rate across the interval.
Distribution choice is also a modeling claim. If a call center receives more calls during lunch than at midnight, a single Poisson rate for the whole day may be too crude even if the total count is a nonnegative integer. If survey responses are clustered by classroom, a binomial model that treats every student response as independent may underestimate variability. If a quality inspector samples a large warehouse without replacement but the sample is tiny relative to the warehouse, a binomial approximation may be acceptable. The formulas become useful only after the data-generating process has been described clearly enough to defend the assumptions.
Visual
| Distribution | Random variable | Parameters | Mean | Variance | Typical setting |
|---|---|---|---|---|---|
| Bernoulli | one success/failure trial | one yes/no outcome | |||
| Binomial | successes in fixed trials | independent repeated trials | |||
| Poisson | events in interval | arrivals, rare counts | |||
| Hypergeometric | successes without replacement | depends on finite correction | finite sampling | ||
| Multinomial | counts in several categories | for category | category-specific | survey choices |
Worked example 1: Binomial probability
Problem: A website experiment has a historical conversion probability of . Suppose 20 independent visitors see a page. Let be the number who convert. Find , , and the mean and standard deviation.
Method:
- Identify the model. There are fixed trials, each visitor either converts or does not, and the problem assumes independent visitors with constant . Thus .
- Compute :
- Evaluate the combination:
- Substitute:
- Compute :
- Calculate terms:
- Add:
- Mean and standard deviation:
Answer: , , the expected number of conversions is 2.4, and the standard deviation is about 1.45.
Checked answer: A value of 3 conversions is near the expected value 2.4, so a probability around 0.225 is plausible. Zero or one conversion is below average but not rare with only 20 visitors.
Worked example 2: Hypergeometric versus binomial
Problem: A shipment contains 50 devices, 6 of which are defective. An inspector selects 5 devices without replacement. What is the probability that exactly 2 are defective? Why is a binomial model not exact?
Method:
- Identify parameters: total devices, defectives, draws, and defective draws.
- Use the hypergeometric formula:
- Compute pieces:
- Substitute:
Answer: The exact probability is about 0.094. A binomial model with would treat each draw as independent with constant defect probability. That is not exact because after a defective device is drawn, only 5 defectives remain among 49 devices; the probability changes.
Checked answer: The numerator counts ways to choose 2 defectives and 3 nondefectives. The denominator counts all possible sets of 5 devices, so the ratio matches the sampling mechanism.
Code
from scipy.stats import binom, hypergeom, poisson
# Binomial conversion example
n, p = 20, 0.12
print("P(X=3):", binom.pmf(3, n, p))
print("P(X<=1):", binom.cdf(1, n, p))
print("mean:", binom.mean(n, p), "sd:", binom.std(n, p))
# Hypergeometric inspection example
N, K, draws = 50, 6, 5
print("P(exactly 2 defective):", hypergeom.pmf(2, N, K, draws))
# Poisson rare-event example: average 4 calls per hour
print("P(6 calls in an hour):", poisson.pmf(6, mu=4))
SciPy uses pmf for discrete probability mass functions and cdf for cumulative probabilities. Naming the parameters in comments is useful because different distributions use different conventions.
Common pitfalls
- Using a binomial model for sampling without replacement from a small finite population.
- Forgetting that "at most 1" means .
- Treating expected value as the most likely exact outcome. The expectation can be non-integer.
- Using the Poisson distribution for counts whose rate changes sharply over time or space.
- Ignoring dependence among trials, such as multiple purchases by the same customer.
- Rounding intermediate probabilities too aggressively.