STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 5
Random Variables and Distributions
Random variables provide a bridge between probability theory and data. A random variable assigns a numerical value to each outcome in the sample space. Understanding distributions of random variables is key to modelling and inference.
Discrete Random Variables
A discrete random variable takes values in a countable set with probability mass function (pmf) . The pmf must satisfy and for all .
Expectation and Variance
The expected value or mean of a discrete random variable is
The variance measures dispersion around the mean:
Common Discrete Distributions
Bernoulli(): , . Models a single success/failure experiment. , .
Binomial(): Number of successes in independent Bernoulli trials. Pmf . Mean , variance .
Poisson(): Number of events occurring in a fixed interval when events occur independently and at a constant rate . Pmf . Mean and variance both equal .
Continuous Random Variables
A continuous random variable has a probability density function (pdf) such that and . The cumulative distribution function (cdf) is .
Expectation and Variance
The expected value and variance of a continuous random variable are
Common Continuous Distributions
Uniform(): for . Mean , variance .
Exponential(): Models waiting times between Poisson events. Density for . Mean , variance .
Gamma(): Two-parameter family with density for . Mean , variance . The exponential is Gamma(1,).
Normal(): Density . Mean , variance . Approximates many sums of independent random variables (central limit theorem).
Example: Poisson Approximation to the Binomial
When is large and is small, the Binomial() distribution is approximated by a Poisson() distribution. Consider trials with . Then .
Worked example
Simulating and comparing Binomial and Poisson distributions (Python):
import numpy as np
import matplotlib.pyplot as plt
n = 1000
p = 0.002
lam = n * p
# Simulate counts
sim_binom = np.random.binomial(n, p, size=10000)
sim_pois = np.random.poisson(lam, size=10000)
# Plot histograms
plt.hist(sim_binom, bins=range(0,11), alpha=0.5, label='Binomial')
plt.hist(sim_pois, bins=range(0,11), alpha=0.5, label='Poisson')
plt.legend()
plt.xlabel('Count')
plt.ylabel('Frequency')
plt.show()
In the resulting plot, the histograms of the binomial and Poisson simulations are nearly indistinguishable.
Exercises
Practice
Let have a Bernoulli() distribution. Show that . Verify this by simulation for in R or Python.
Suppose has pdf for and zero otherwise. Compute and . Confirm your answer by simulating 10 000 observations.
For a Gamma() random variable with and , find the cdf. Use Python or Julia to plot the pdf and cdf.
A manufacturing process produces items with independent lifetimes following an exponential distribution with rate failures per hour. What is the probability that an item lasts more than 10 hours? Generate a sample of 500 lifetimes and estimate this probability empirically.
References
Casella G, Berger RL. Statistical Inference. 2nd ed. Duxbury; 2002.
Rice JA. Mathematical Statistics and Data Analysis. 3rd ed. Belmont, CA: Duxbury Press; 2006.
Ross SM. A First Course in Probability. 10th ed. Pearson; 2020.