Skip to content
BIASED

Discrete distributions

Random variables, the pmf and the CDF; the Bernoulli, categorical, binomial, geometric and Poisson distributions, each from its own story, with the Poisson limit of the binomial.

Numbers on outcomes

The topic Conditional probability and Bayes' formula worked with events: yes/no statements such as "the person is sick" or "the test is positive". We can now update their probabilities on new evidence. But the questions kept turning into numbers. How many of three test runs come back positive? How many suspicious words does a letter contain? What do two dice add up to? How many rolls until the first six?

A random variable attaches a number to every outcome. Formally it is a function

X:Ω→R.X : \Omega \to \mathbb R .

Roll two dice. The sample space Ω\Omega has 36 equally likely outcomes (a,b)(a, b), and the sum S(a,b)=a+bS(a, b) = a + b is a random variable. It sends (3,5)(3, 5) to 88, and so do four other outcomes. Statements about SS are events, that is, sets of outcomes:

{S=8}={(2,6),(3,5),(4,4),(5,3),(6,2)},P(S=8)=536.\{S = 8\} = \{(2,6), (3,5), (4,4), (5,3), (6,2)\}, \qquad P(S = 8) = \frac{5}{36}.

Nothing new is needed to compute such probabilities. Collect the outcomes where the variable takes the value, and use the rules from the earlier topics. Upper case XX is the variable; lower case xx is a value it can take.

The pmf and the CDF

For a discrete variable, one with finitely or countably many values, the whole story is in one table. The probability mass function (pmf) gives the probability of each value:

pX(x)=P(X=x).p_X(x) = P(X = x).

For the sum of two dice, counting outcomes as in the previous block gives

ss 2 3 4 5 6 7 8 9 10 11 12
36⋅pS(s)36 \cdot p_S(s) 1 2 3 4 5 6 5 4 3 2 1

A pmf is non-negative and sums to 1 over all values. Any probability about XX is a sum of pmf values. For example, P(S≥10)=(3+2+1)/36=1/6P(S \ge 10) = (3 + 2 + 1)/36 = 1/6.

The pmf describes the distribution, not the variable itself. A die and a six-sector spinner are different objects with the same distribution. Every probability statement about one holds for the other. That is why named distributions are worth learning: one table serves many problems.

The cumulative distribution function (CDF) accumulates the pmf:

FX(x)=P(X≤x).F_X(x) = P(X \le x).

For a discrete variable it is a staircase. It is flat between the values, jumps by pX(k)p_X(k) at each value kk, starts at 0 far to the left and reaches 1 far to the right. It is defined for every real xx, not only for the values. Since {X≤b}\{X \le b\} is the disjoint union of {X≤a}\{X \le a\} and {a<X≤b}\{a < X \le b\}, the probability of a half-open interval is a difference:

P(a<X≤b)=FX(b)−FX(a).P(a < X \le b) = F_X(b) - F_X(a).

Bernoulli and categorical

The simplest variable answers one yes/no question. X∼Bern⁡(p)X \sim \operatorname{Bern}(p), the Bernoulli distribution, takes the value 1 with probability pp and 0 with probability 1−p1 - p. Both cases fit in one formula:

pX(k)=pk(1−p)1−k,k∈{0,1}.p_X(k) = p^k (1 - p)^{1 - k}, \qquad k \in \{0, 1\}.

Every event gives one. The indicator 1A\mathbb 1_A equals 1 when AA happens and 0 otherwise, so 1A∼Bern⁡(P(A))\mathbb 1_A \sim \operatorname{Bern}(P(A)). Events from the earlier topics are Bernoulli variables in disguise. The result of one run of the medical test from the previous topic, 1 for positive, is Bern⁡(0.0981)\operatorname{Bern}(0.0981), where 0.09810.0981 is P(+)P(+) from the law of total probability.

This is also what a binary classifier outputs. A spam filter does not return "spam" or "not spam". It returns a number pp, and that number is read as the parameter of a Bernoulli distribution over the label.

With KK possible values instead of two, we get the categorical distribution Cat⁡(p1,…,pK)\operatorname{Cat}(p_1, \dots, p_K): value kk has probability pkp_k, with

p1+⋯+pK=1.p_1 + \dots + p_K = 1 .

The softmax layer of a 10-class image classifier outputs ten numbers p1,…,p10p_1, \dots, p_{10}: a categorical distribution over classes. A language model does the same over its whole vocabulary of tens of thousands of tokens. Generating text means drawing the next token from that categorical distribution, again and again. Training such models with cross-entropy fits these parameters by maximum likelihood; the topic Maximum likelihood shows why.

Counting successes

Repeat a Bernoulli trial nn times, independently and with the same pp, and count the successes. The count XX is a sum of indicators, X=1A1+⋯+1AnX = \mathbb 1_{A_1} + \dots + \mathbb 1_{A_n}, and it takes values 0,1,…,n0, 1, \dots, n.

Its pmf takes two steps. One particular sequence with kk successes and n−kn - k failures has probability pk(1−p)n−kp^k (1 - p)^{n - k}. This is the multiplication rule for independent events. There are (nk)\binom{n}{k} such sequences, one for each choice of where the successes go, as in the topic Outcomes, events and counting. So X∼Bin⁡(n,p)X \sim \operatorname{Bin}(n, p), the binomial distribution, has

P(X=k)=(nk)pk(1−p)n−k,k=0,1,…,n.P(X = k) = \binom{n}{k} p^k (1 - p)^{n - k}, \qquad k = 0, 1, \dots, n.

Ten fair coins land on exactly 5 heads with probability (105)/210=252/1024≈0.246\binom{10}{5}/2^{10} = 252/1024 \approx 0.246. Even the most likely count turns up only about a quarter of the time.

A classifier's test set is the same story. If the true error rate is pp and the nn test examples are independent, the number of errors is Bin⁡(n,p)\operatorname{Bin}(n, p). With n=100n = 100 and p=0.1p = 0.1, the chance of seeing exactly 10 errors is only about 0.130.13. The measured error rate almost never equals the true one exactly. How far it can stray is the subject of the limit theorems later in the course.

Both conditions matter: independent trials and the same pp. Run the medical test three times on one person. For a sick person the runs are independent with p=0.9p = 0.9, so the number of positives is Bin⁡(3,0.9)\operatorname{Bin}(3, 0.9). For a random person it is not binomial: the runs are only conditionally independent, and a first positive makes a second one more likely.

Draw 5 cards from a deck without putting them back, and the draws are dependent. The number of aces then follows the hypergeometric distribution, and exactly two aces has probability 0.0400.040, while the binomial formula with p=4/52p = 4/52 would say 0.0470.047. When the population is much larger than the sample, the difference fades. That is why a poll of 1,000 people out of millions can use binomial formulas.

Waiting for the first success

Now keep repeating the same trial and ask how long the wait is. Let XX be the number of trials up to and including the first success. Its values are 1,2,3,…1, 2, 3, \dots, with no upper limit. X=kX = k means k−1k - 1 failures followed by a success, so X∼Geom⁡(p)X \sim \operatorname{Geom}(p), the geometric distribution, has

P(X=k)=(1−p)k−1p,k=1,2,…P(X = k) = (1 - p)^{k - 1} p, \qquad k = 1, 2, \dots

Some books count the failures before the first success instead. Their variable is ours minus one. In this course Geom⁡\operatorname{Geom} always counts trials.

The tail is even simpler. X>kX > k means exactly that the first kk trials all failed:

P(X>k)=(1−p)k.P(X > k) = (1 - p)^k .

The wait for a six exceeds 10 rolls with probability (5/6)10≈0.16(5/6)^{10} \approx 0.16.

Now suppose mm rolls have already passed without a six. By the definition of conditional probability, and because {X>m+k}\{X > m + k\} lies inside {X>m}\{X > m\},

P(X>m+k∣X>m)=(1−p)m+k(1−p)m=(1−p)k=P(X>k).P(X > m + k \mid X > m) = \frac{(1 - p)^{m + k}}{(1 - p)^m} = (1 - p)^k = P(X > k).

The geometric distribution is memoryless: the remaining wait has the same distribution as a fresh one. After 10 rolls without a six, the chance of 10 more without one is still 0.160.16. The feeling that a six is "due" is the gambler's fallacy. The die does not remember.

Rare events and the Poisson limit

Some counts come from many opportunities, each with a tiny chance. A site has a million visitors a day, and each one hits a rare bug with probability 3⋅10−63 \cdot 10^{-6}. A long document contains a rare word a few times. The count is binomial, but nn is huge, pp is tiny, and often neither is known. What we do know is λ=np\lambda = np, the typical number of events. The topic Expectation and variance will show that λ\lambda is exactly the average count.

So fix λ\lambda, set p=λ/np = \lambda/n and let nn grow. Split the binomial pmf into four factors:

(nk)(λn)k(1−λn)n−k=n(n−1)⋯(n−k+1)nk⋅λkk!⋅(1−λn)n⋅(1−λn)−k.\binom{n}{k} \Big(\frac{\lambda}{n}\Big)^k \Big(1 - \frac{\lambda}{n}\Big)^{n-k} = \frac{n(n-1)\cdots(n-k+1)}{n^k} \cdot \frac{\lambda^k}{k!} \cdot \Big(1 - \frac{\lambda}{n}\Big)^{n} \cdot \Big(1 - \frac{\lambda}{n}\Big)^{-k}.

As n→∞n \to \infty with kk fixed, the first factor tends to 1, the third tends to e−λe^{-\lambda}, and the fourth tends to 1. What remains is the Poisson distribution Pois⁡(λ)\operatorname{Pois}(\lambda):

P(X=k)=e−λλkk!,k=0,1,2,…P(X = k) = e^{-\lambda} \frac{\lambda^k}{k!}, \qquad k = 0, 1, 2, \dots

It is a genuine pmf. The series ∑kλk/k!\sum_k \lambda^k/k! equals eλe^\lambda, so the probabilities sum to 1. It has a single parameter, and it never asks for nn or pp separately.

The approximation is good quickly. With λ=3\lambda = 3, the binomial probability of zero events is 0.0100.010 for n=5n = 5, 0.0280.028 for n=10n = 10 and 0.0480.048 for n=100n = 100, against the Poisson value e−3≈0.050e^{-3} \approx 0.050.

The classic data set is Bortkiewicz's (1898): deaths from horse kicks in the Prussian cavalry, 200 corps-years with 122 deaths, so λ=0.61\lambda = 0.61. Years with 0, 1, 2, 3 and 4 deaths were observed 109, 65, 22, 3 and 1 times, and Pois⁡(0.61)\operatorname{Pois}(0.61) predicts 108.7, 66.3, 20.2, 4.1 and 0.6. Many soldiers, each with a tiny and roughly independent risk: exactly the story above.

Which story gives which distribution

Each family comes from a story, and the story tells you which one to use.

Story Distribution Values
One yes/no trial Bern⁡(p)\operatorname{Bern}(p) 0,10, 1
One of KK categories Cat⁡(p1,…,pK)\operatorname{Cat}(p_1, \dots, p_K) 1,…,K1, \dots, K
Successes in nn independent trials Bin⁡(n,p)\operatorname{Bin}(n, p) 0,…,n0, \dots, n
Trials up to the first success Geom⁡(p)\operatorname{Geom}(p) 1,2,…1, 2, \dots
Rare events among many opportunities Pois⁡(λ)\operatorname{Pois}(\lambda) 0,1,2,…0, 1, 2, \dots

When the story breaks, so does the formula. Clicks from the same user or near-duplicate test examples are not independent trials, and the real spread is wider than the binomial says. Bursty counts, such as requests from a bot or repeats of a word that has just appeared, vary more than a Poisson with the same λ\lambda. Models such as the negative binomial or mixtures handle such counts.

All five families take countable values: one table of probabilities covers everything. A waiting time in seconds, a person's height or a model's predicted probability lives on a continuum. There the table fails. The topic Kolmogorov's axioms showed that every single point of [0,1][0, 1] has probability zero under the uniform distribution, so a pmf would be zero everywhere. The topic Continuous distributions replaces the pmf with a density and keeps the CDF. It also meets the exponential distribution, the continuous cousin of the geometric and memoryless too.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.