Unit 3, lesson 16

Random Variables and Probability Distributions

How a random variable turns outcomes into numbers, how a probability mass function, a density and a cumulative distribution function give probabilities, and how binomial and normal models are built.

  • Video 16
  • Conditional Probability and Distributions

A parcel arrives late or on time, while the error of a temperature sensor can be any amount in a range. To compute probabilities about either one, the outcome first has to become a number, and the model then has to say how probability spreads over the possible numbers. This lesson defines random variables and three descriptions of their distributions, a mass function for values that can be listed, a density whose areas are probabilities, and a cumulative distribution function that works for both. It ends with the binomial and normal models and the assumptions behind them. All models on this page are constructed for illustration.

Key terms

Random variable

Definition A random variable XX is a function that assigns a real number X(ω)X(\omega) to each outcome ω\omega in the sample space Ω\Omega. Its distribution gives the probabilities of the events it defines, such as {X≤t}\{X \le t\} or {a≤X≤b}\{a \le X \le b\}. The value that occurs in a particular trial is a realization of XX, often written in lowercase as xx. The variable XX is discrete if, with probability 11, its values lie in a finite or countable set, and its support is then the set of values xx with P(X=x)>0P(X = x) > 0. It is absolutely continuous if the probabilities of intervals are areas under a density, as defined below. Some variables are neither, such as a mix of a point mass and a density, but the two kinds are enough for this lesson.

In plain words A random variable is a rule that turns an uncertain outcome into a number before the outcome is seen. The variable stands for the uncertain quantity, and a realization is the number that actually occurs. Whether to model a quantity as discrete or continuous depends on what is measured and why. A temperature error is often modeled as continuous even though a device stores it rounded.

Example For a parcel, let B=1B = 1 if it arrives late and B=0B = 0 if it arrives on time. When both cases have positive probability, the support of BB is {0,1}\{0, 1\}. For a sensor, let EE be the measurement error in degrees Celsius. The constructed models below make EE discrete with the values −2-2, −1-1, 00 and 11, continuous and uniform on the interval from −0.2-0.2 to 0.20.2, or normal. They describe the same physical quantity under different assumptions.

Probability mass function

Definition The probability mass function, or PMF, of a discrete random variable XX is pX(x)=P(X=x)p_X(x) = P(X = x). It satisfies pX(x)≥0p_X(x) \ge 0 for every xx and

∑xpX(x)=1,\sum_{x} p_X(x) = 1,

with the sum over the support, an infinite series when the support is infinite. For a set of values AA, the probability P(X∈A)P(X \in A) is the sum of pX(x)p_X(x) over the values xx in AA. In summation notation,

∑i=1nai=a1+a2+⋯+an,\sum_{i=1}^{n} a_i = a_1 + a_2 + \dots + a_n,

with one term for each value of the index ii from 11 to nn. The index is only a placeholder, so ∑i=1nai\sum_{i=1}^{n} a_i and ∑j=1naj\sum_{j=1}^{n} a_j are the same number.

In plain words A PMF puts a lump of probability on each possible value, and the lumps add to 11. The probability of an event about XX is the total of the lumps that the event contains. A PMF value is an actual probability, so it never exceeds 11.

Example The discrete sensor error EE has the support values e1,…,e4e_1, \dots, e_4 and the masses p1,…,p4p_1, \dots, p_4 in the table.

Error eie_i in degrees−2-2−1-10011
Probability pip_i0.10.10.20.20.40.40.30.3

The masses are nonnegative and ∑i=14pi=0.1+0.2+0.4+0.3=1\sum_{i=1}^{4} p_i = 0.1 + 0.2 + 0.4 + 0.3 = 1, so they form a PMF. The probability of a nonnegative error adds the masses at 00 and 11, so P(E≥0)=0.4+0.3=0.7P(E \ge 0) = 0.4 + 0.3 = 0.7. The value P(E=0)=0.4P(E = 0) = 0.4 is the probability of exactly zero error in this model.

Cumulative distribution function

Definition The cumulative distribution function, or CDF, of a random variable XX is

F(t)=P(X≤t)F(t) = P(X \le t)

for every real number tt. It never decreases, it tends to 00 as t→−∞t \to -\infty and to 11 as t→∞t \to \infty, and for a<ba < b

P(a<X≤b)=F(b)−F(a).\begin{aligned} &P(a < X \le b) \\[0.4em] &\quad = F(b) - F(a). \end{aligned}

At each value xx the jump of FF equals P(X=x)P(X = x). So for a discrete variable with finitely many values, FF is a step function that rises by pX(x)p_X(x) at each support value xx and already takes the higher value at xx itself.

In plain words The CDF accumulates probability from the left, up to and including the threshold. Its values are probabilities, so they lie between 00 and 11. For a discrete variable it matters whether an endpoint is included, because a single value can carry positive probability.

Example For the discrete sensor error EE, the CDF is 00 for t<−2t < -2. It is 0.10.1 from −2-2 up to but not including −1-1, then 0.30.3 up to 00, then 0.70.7 up to 11, and 11 from 11 on. At t=0.5t = 0.5 it is still 0.70.7, since no support value lies between 00 and 11. The interval that excludes −1-1 has

P(−1<E≤1)=F(1)−F(−1)=1−0.3=0.7,\begin{aligned} &P(-1 < E \le 1) \\[0.4em] &\quad = F(1) - F(-1) \\[0.4em] &\quad = 1 - 0.3 = 0.7, \end{aligned}

while including the left endpoint gives P(−1≤E≤1)=0.9P(-1 \le E \le 1) = 0.9, because the mass 0.20.2 at −1-1 is added back.

Probability density function

Definition For a nonnegative, piecewise continuous function ff and numbers a≤ba \le b, the definite integral

∫abf(x) dx\int_a^b f(x)\,dx

is the area of the region under the graph of ff and above the horizontal axis between x=ax = a and x=bx = b. When ff has a constant value cc on [a,b][a, b] the region is a rectangle with area c (b−a)c\,(b - a). For other shapes the area is the limit of the total area of narrow rectangles under the graph as their widths shrink to 00. A probability density function, or PDF, is such a function ff with total area 11 under its whole graph. A random variable XX has density ff, and is absolutely continuous, if for all a≤ba \le b

P(a≤X≤b)=∫abf(x) dx.\begin{aligned} &P(a \le X \le b) \\[0.4em] &\quad = \int_a^b f(x)\,dx. \end{aligned}

Then P(X=a)=0P(X = a) = 0 for every single value aa, so including or excluding an endpoint does not change the probability of an interval, and F(t)F(t) is the area under ff to the left of tt. If XX carries a unit, ff carries the reciprocal unit, so that height times width is a pure number.

In plain words A density height is not a probability. It says how tightly probability is packed near a value, and only areas under the curve are probabilities. A density can therefore exceed 11, as long as the total area is 11. A single exact value has zero width and so zero probability, yet some value always occurs. A reading rounded to some resolution stands for a short interval of true values, and that interval can have positive probability.

Example Model the sensor error EE as uniform from −0.2-0.2 to 0.20.2 degrees. The width is 0.40.4 degrees, so the constant density is 2.52.5 per degree, which makes the total area 0.4×2.5=10.4 \times 2.5 = 1. The probability of an error between −0.1-0.1 and 0.050.05 degrees is a rectangle area,

∫−0.10.052.5 dx=0.15×2.5=0.375.\begin{aligned} \int_{-0.1}^{0.05} 2.5\,dx &= 0.15 \times 2.5 \\[0.4em] &= 0.375. \end{aligned}

The density at 00 is 2.52.5 per degree, but P(E=0)=0P(E = 0) = 0. A reading of 0.00.0 rounded to the nearest 0.10.1 degree stands for true errors from −0.05-0.05 up to 0.050.05, an interval with probability 0.1×2.5=0.250.1 \times 2.5 = 0.25. Inside the support the CDF is F(t)=(t+0.2)/0.4F(t) = (t + 0.2)/0.4, so F(0)=0.5F(0) = 0.5.

Binomial distribution

Definition A Bernoulli random variable takes the value 11 with probability pp and the value 00 with probability 1−p1 - p, where 0≤p≤10 \le p \le 1. The value 11 is called a success, whatever the event coded 11 means. Let KK count the successes in a fixed number nn of Bernoulli trials that are independent and share the same success probability pp. Then KK has the binomial distribution with parameters nn and pp, and for k=0,1,…,nk = 0, 1, \dots, n

P(K=k)=(nk)pk×(1−p)n−k,\begin{aligned} P(K = k) &= \binom{n}{k} p^k \\[0.4em] &\quad \times (1 - p)^{n - k}, \end{aligned}

where the binomial coefficient (nk)=n!k! (n−k)!\binom{n}{k} = \frac{n!}{k!\,(n - k)!} counts the ways to choose which kk of the nn trials are successes, and the convention 00=10^0 = 1 applies when pp is 00 or 11. A categorical distribution extends the Bernoulli model to one of mm named categories, with probabilities that are nonnegative and sum to 11.

In plain words A binomial count adds up independent yes or no trials that all have the same chance. Each arrangement of kk successes among nn trials has the same probability, and the binomial coefficient counts the arrangements. The model fails when the trials are linked, for example by shared weather, or when their chances differ, even though counting the successes still makes sense. A categorical variable such as a service type names alternatives, and coding them as 00, 11 and 22 does not make the gaps between the codes meaningful.

Example Each of 33 parcels is late with probability 0.20.2, independently of the others. Writing L for late and O for on time, exactly two parcels are late in the three arrangements LLO, LOL and OLL. Each has probability 0.22×0.8=0.0320.2^2 \times 0.8 = 0.032, so P(K=2)=3×0.032=0.096P(K = 2) = 3 \times 0.032 = 0.096. The full PMF is

Late parcels kk00112233
P(K=k)P(K = k)0.5120.5120.3840.3840.0960.0960.0080.008

and its four values sum to 11. A service type that is economy, express or pickup with probabilities 0.50.5, 0.30.3 and 0.20.2 follows a categorical distribution.

Normal distribution

Definition For a real number μ\mu and a number σ>0\sigma > 0, a random variable XX has the normal distribution with mean μ\mu and standard deviation σ\sigma, written X∼N(μ,σ2)X \sim N(\mu, \sigma^2), if it has the density

f(x)=1σ2π e−z2/2,z=x−μσ,\begin{gathered} f(x) = \frac{1}{\sigma\sqrt{2\pi}}\, e^{-z^2/2}, \\[0.4em] z = \frac{x - \mu}{\sigma}, \end{gathered}

for every real xx. The number zz is the signed distance from xx to μ\mu in units of σ\sigma. The density is symmetric about μ\mu, highest at x=μx = \mu with height 1/(σ2π)1/(\sigma\sqrt{2\pi}), and positive on the whole real line. The CDF has no formula in elementary functions, so interval probabilities come from software or tables. About 0.68270.6827 of the probability lies within one σ\sigma of μ\mu, about 0.95450.9545 within two and about 0.99730.9973 within three. The parameters μ\mu and σ\sigma are the mean and standard deviation of the distribution, quantities defined through expectation in the next lesson.

In plain words A normal model is a symmetric bell centered at μ\mu, and σ\sigma sets its width. It gives some probability to every interval, however far from the center, so it can be a poor model for a quantity with hard limits or with heavier tails. It is a useful approximation in many settings, but it remains an assumption, and data that look roughly symmetric do not prove it.

Example Model the sensor error as normal with μ=0\mu = 0 and σ=0.1\sigma = 0.1 degree. The peak density is 1/(0.12π)≈3.9891/(0.1\sqrt{2\pi}) \approx 3.989 per degree. The probability of an error between −0.1-0.1 and 0.10.1 degree, one standard deviation on each side of the mean, is an area of about 0.68270.6827. The peak height is neither that probability nor the probability of an error of exactly 00, which is 00. Unlike the uniform model on [−0.2,0.2][-0.2, 0.2], this model allows errors larger than 0.20.2 degree in size, with total probability about 0.04550.0455.

Check yourself

  1. A discrete random variable XX takes the values 00, 22, 55 and 99 with probabilities 0.150.15, 0.350.35, 0.30.3 and 0.20.2. Find P(2≤X≤5)P(2 \le X \le 5), the CDF value F(4)F(4) and P(X>5)P(X > 5).
Show the answer

The interval from 22 to 55 with both ends included contains the support values 22 and 55, so P(2≤X≤5)=0.35+0.3=0.65P(2 \le X \le 5) = 0.35 + 0.3 = 0.65. The CDF at 44 includes the values 00 and 22, so F(4)=0.15+0.35=0.5F(4) = 0.15 + 0.35 = 0.5. The mass at 55 is not included, because 55 exceeds 44. Above 55 the only support value is 99, so P(X>5)=0.2P(X > 5) = 0.2, which matches 1−F(5)=1−0.81 - F(5) = 1 - 0.8. A tempting shortcut fails here, since F(5)−F(2)=0.3F(5) - F(2) = 0.3 leaves out the mass at 22. The correct difference is F(5)−F(1)=0.8−0.15=0.65F(5) - F(1) = 0.8 - 0.15 = 0.65, because no support value lies between 11 and 22.

  1. A random variable UU is uniform on [1,1.5][1, 1.5]. Find its density, P(1.1≤U≤1.3)P(1.1 \le U \le 1.3) and P(U=1.2)P(U = 1.2). A classmate says a density value of 22 is impossible, because probabilities cannot exceed 11. What is wrong with the argument?
Show the answer

The support has width 0.50.5, so the density is 1/0.5=21/0.5 = 2 on [1,1.5][1, 1.5] and 00 elsewhere. The interval from 1.11.1 to 1.31.3 has width 0.20.2, so its probability is the rectangle area 0.2×2=0.40.2 \times 2 = 0.4. A single point has zero width, so P(U=1.2)=0P(U = 1.2) = 0, even though the density there is 22. The classmate treats a density height as a probability. Only areas under a density are probabilities, and here the total area is 0.5×2=10.5 \times 2 = 1, as it must be.

  1. Four parcels are each late with probability 0.10.1. Assuming independence, find the probability that exactly one is late and the probability that at least one is late. Then suppose instead that all four ride on one truck, which is late with probability 0.10.1 and makes every parcel late when it is late and every parcel on time otherwise. Is the number of late parcels still binomial, and what is the probability that at least one is late?
Show the answer

Under independence the count KK is binomial with n=4n = 4 and p=0.1p = 0.1. Then

P(K=1)=4×0.1×0.93=0.2916,\begin{aligned} P(K = 1) &= 4 \times 0.1 \times 0.9^3 \\[0.4em] &= 0.2916, \end{aligned}

and the complement of no late parcel gives P(K≥1)=1−0.94=1−0.6561=0.3439P(K \ge 1) = 1 - 0.9^4 = 1 - 0.6561 = 0.3439.

With the shared truck, each parcel is still late with probability 0.10.1, but the four trials are not independent. The count is 00 with probability 0.90.9 and 44 with probability 0.10.1, so it is not binomial, and P(K≥1)=0.1P(K \ge 1) = 0.1. Equal success probabilities are not enough. The binomial formula also needs independent trials.

How this lesson connects

It also uses exponential functions.