Book contents

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 XX takes values in a countable set {x1,x2,…}\{x_1, x_2, \dots\} with probability mass function (pmf) p(x)=P(X=x)p(x) = P(X = x). The pmf must satisfy ∑xp(x)=1\sum_x p(x) = 1 and p(x)≥0p(x) \ge 0 for all xx.

Expectation and Variance

The expected value or mean of a discrete random variable is E[X]=∑xxp(x).E[X] = \sum_x x \, p(x).

The variance measures dispersion around the mean: Var(X)=E[(X−E[X])2]=∑x(x−E[X])2p(x).\text{Var}(X) = E[(X - E[X])^2] = \sum_x (x - E[X])^2 \, p(x).

Common Discrete Distributions

Continuous Random Variables

A continuous random variable XX has a probability density function (pdf) f(x)f(x) such that P(a≤X≤b)=∫abf(x)dxP(a \le X \le b) = \int_a^b f(x)\,dx and ∫−∞∞f(x)dx=1\int_{-\infty}^{\infty} f(x)\,dx = 1. The cumulative distribution function (cdf) is F(x)=P(X≤x)=∫−∞xf(t)dtF(x) = P(X \le x) = \int_{-\infty}^x f(t)\,dt.

Expectation and Variance

The expected value and variance of a continuous random variable are E[X]=∫−∞∞xf(x)dx,Var(X)=∫−∞∞(x−E[X])2f(x)dx.E[X] = \int_{-\infty}^{\infty} x \, f(x)\,dx, \quad \text{Var}(X) = \int_{-\infty}^{\infty} (x-E[X])^2 f(x)\,dx.

Common Continuous Distributions

Example: Poisson Approximation to the Binomial

When nn is large and pp is small, the Binomial(n,pn,p) distribution is approximated by a Poisson(λ=np\lambda = np) distribution. Consider n=1000n=1000 trials with p=0.002p=0.002. Then np=2np = 2.

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

  1. Let XX have a Bernoulli(pp) distribution. Show that Var(X)=p(1−p)\text{Var}(X) = p(1-p). Verify this by simulation for p=0.3p=0.3 in R or Python.

  2. Suppose XX has pdf f(x)=2xf(x) = 2x for 0≤x≤10\le x \le 1 and zero otherwise. Compute E[X]E[X] and Var(X)\text{Var}(X). Confirm your answer by simulating 10 000 observations.

  3. For a Gamma(α,β\alpha,\beta) random variable with α=2\alpha=2 and β=1\beta=1, find the cdf. Use Python or Julia to plot the pdf and cdf.

  4. A manufacturing process produces items with independent lifetimes following an exponential distribution with rate λ=0.2\lambda=0.2 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