Course contents 05 / 22

05 / 22 · Random Variables

Discrete distributions

From individual signals to count distributions: independent trials, waiting for a first event, rare-event limits and finite sampling. Original synthetic sensor examples show why equal averages can hide different mechanisms.

On this page 8

A monitoring board receives one signal from each of its sensors during a fixed window. Sometimes no sensor reports a fault; sometimes several do. To estimate the probability of an overloaded repair queue, we need more than the average count. We need a rule for how signals occur together.

The examples below use fictional devices and explicitly chosen probabilities. Their purpose is to connect a sampling mechanism to a distribution. They contain no production measurements or historical dataset.

Random variables#

Suppose two sensors report independently. Sensor A reports with probability 1/41/4 and sensor B with probability 1/21/2. An outcome records both signals, such as (1,0)(1,0). Define XX to be their total. Several outcomes can give the same value of XX:

Outcome (A,B)(A,B)ProbabilityCount XX
(0,0)(0,0)3/83/800
(1,0)(1,0)1/81/811
(0,1)(0,1)3/83/811
(1,1)(1,1)1/81/822

A random variable assigns a real number to an outcome: X:Ω→RX:\Omega\to\mathbb R. Events such as {X≤1}\{X\le 1\} must be measurable so that their probabilities are defined; in this finite example every subset of outcomes is an event. Adding the probabilities of outcomes with the same count gives the probability mass function (PMF):

pX(k)=P(X=k),(pX(0),pX(1),pX(2))=(3/8,1/2,1/8).p_X(k)=P(X=k),\qquad (p_X(0),p_X(1),p_X(2))=(3/8,1/2,1/8).

The masses are nonnegative and sum to one. A probability about the count is a sum of the corresponding masses. For example, P(X≤1)=3/8+1/2=7/8P(X\le 1)=3/8+1/2=7/8. The value X=1X=1 alone does not tell us which sensor reported. Reducing an outcome to a number can discard information that another question needs.

The cumulative distribution function (CDF) collects all mass at or below a threshold: FX(x)=P(X≤x)F_X(x)=P(X\le x). Here it is zero below zero, 3/83/8 on [0,1)[0,1), 7/87/8 on [1,2)[1,2) and one from two onward. Consequently P(a<X≤b)=FX(b)−FX(a)P(a<X\le b)=F_X(b)-F_X(a). A jump at a supported value equals its probability mass. Different physical mechanisms can have the same marginal distribution of a count; that does not make their joint relationships with other variables identical.

Bernoulli and categorical#

An individual report is an indicator: one when a specified event occurs and zero otherwise. We write I∼Bernoulli(p)I\sim\mathrm{Bernoulli}(p), where P(I=1)=pP(I=1)=p and P(I=0)=1−pP(I=0)=1-p. The parameter belongs to a defined trial and population. A device changing temperature between trials need not retain the same reporting probability.

A categorical model assigns probabilities to several mutually exclusive outcomes. Suppose a fictional inspection returns “ready”, “recheck” or “replace” with probabilities 0.650.65, 0.250.25 and 0.100.10. These sum to one. The probability of requiring any intervention is 0.350.35, so its indicator is Bernoulli even though the original outcome has three categories. Numeric category IDs are labels; averaging those IDs would depend on the arbitrary numbering.

A classifier can represent a conditional Bernoulli probability or a categorical probability vector for a given input. Softmax makes the entries nonnegative and normalized; it does not establish that the probabilities match observed frequencies. Estimating those probabilities and evaluating calibration are separate tasks. The connection between probability models and cross-entropy is developed through maximum likelihood.

Binomial#

Now inspect twelve devices under a model in which their report indicators are independent and each has probability p=1/5p=1/5. Let XX count reports. For general nn, any particular sequence with kk reports has probability pk(1−p)n−kp^k(1-p)^{n-k}. Independence lets us multiply, and the common pp makes this probability identical for all sequences with that count. There are (nk)\binom nk choices of reporting positions. Therefore

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

This is X∼Bin(n,p)X\sim\mathrm{Bin}(n,p). The binomial theorem verifies that its probabilities sum to (p+(1−p))n=1(p+(1-p))^n=1. At the endpoint p=0p=0 the count is always zero; at p=1p=1 it is always nn, without needing to interpret ambiguous powers in an implementation.

For the twelve devices, exactly three reports have probability 0.2362230.236223. If the repair queue can accept three jobs, overload means at least four reports:

P(X≥4)=∑k=412(12k)(1/5)k(4/5)12−k≈0.205431.P(X\ge4)=\sum_{k=4}^{12}\binom{12}{k}(1/5)^k(4/5)^{12-k} \approx0.205431.

The event starts at four, so using P(X>4)P(X>4) would omit a possible overload. This calculation describes the specified mechanism; a real queue also depends on service times and carry-over from earlier windows.

For a fixed classifier evaluated on independently sampled examples from one unchanged population, correctness indicators have a common marginal success probability, and the binomial model can apply. Independence of examples alone is insufficient when their sampling populations or success probabilities differ. Fitting or selecting the classifier on those same labels also changes the evaluation setup. The two sensors in the opening example have different probabilities, so their sum was not obtained from the common-pp argument.

Geometric#

Instead of fixing the number of trials, wait for the first report. Assume independent trials with the same reporting probability 0<p≤10<p\le1, and count the reporting trial itself. For T∼Geom(p)T\sim\mathrm{Geom}(p), the event T=kT=k requires k−1k-1 nonreports followed by one report:

P(T=k)=(1−p)k−1p,k=1,2,…,P(T>k)=(1−p)k,k=0,1,….\begin{aligned} P(T=k)&=(1-p)^{k-1}p, &&k=1,2,\ldots,\\ P(T>k)&=(1-p)^k, &&k=0,1,\ldots. \end{aligned}

At p=1/5p=1/5, more than five trials are needed with probability (4/5)5=0.32768(4/5)^5=0.32768. A convention that counts nonreports instead uses T−1T-1 and starts at zero. Check which quantity a software interface returns before interpreting its result; SciPy’s geom counts the successful trial (reference). At p=0p=0, a first report never arrives, so no probability distribution on finite positive trial counts results.

For 0<p<10<p<1, after three nonreports the chance of five more is unchanged. More generally, for nonnegative integers m,km,k,

P(T>m+k∣T>m)=P(T>m+k)P(T>m)=(1−p)m+k(1−p)m=(1−p)k=P(T>k).\begin{aligned} P(T>m+k\mid T>m) &=\frac{P(T>m+k)}{P(T>m)}\\ &=\frac{(1-p)^{m+k}}{(1-p)^m}\\ &=(1-p)^k=P(T>k). \end{aligned}

This memorylessness follows from the constant independent trial mechanism. It need not describe repeated repairs: an intervention can change the device, and failures can share a cause. Even if trials are conditionally independent given an unknown fixed pp, observing failures can change our uncertainty about pp and hence our predictive waiting time. For p=1p=1, conditional statements involving an impossible history of failures are undefined.

Poisson#

Suppose each window has many independent opportunities for a report. Set their number to nn and their probability to p=λ/np=\lambda/n, where the expected count λ>0\lambda>0 stays fixed. For a fixed nonnegative integer kk and sufficiently large nn,

P(X=k)=(nk)(λ/n)k(1−λ/n)n−k=λkk!∏j=0k−1(1−j/n)(1−λ/n)n(1−λ/n)−k⟶e−λλkk!.\begin{aligned} P(X=k) &=\binom nk(\lambda/n)^k(1-\lambda/n)^{n-k}\\ &=\frac{\lambda^k}{k!} \prod_{j=0}^{k-1}(1-j/n) (1-\lambda/n)^n(1-\lambda/n)^{-k}\\ &\longrightarrow e^{-\lambda}\frac{\lambda^k}{k!}. \end{aligned}

The finite product tends to one because kk is fixed. The last factor also tends to one, while (1−λ/n)n(1-\lambda/n)^n tends to e−λe^{-\lambda}. The limiting masses sum to one by the exponential series. They define X∼Poisson(λ)X\sim\mathrm{Poisson}(\lambda). At λ=0\lambda=0, use the degenerate count zero.

The parameter is an expected count per specified window, not a rate without units. If a homogeneous Poisson process has rate rr per minute, a window of length tt minutes has parameter λ=rt\lambda=rt. Independent increments and a constant rate are assumptions of that process; a single Poisson-shaped histogram does not establish them. The continuous-distributions topic connects this process to waiting times.

Take λ=1.2\lambda=1.2. The zero-report probabilities for n=12,48,192n=12,48,192 are respectively 0.2824300.282430, 0.2966340.296634 and 0.3000620.300062, approaching e−1.2=0.301194e^{-1.2}=0.301194. The figure keeps the whole probability mass, including the tail bucket.

Figure

A fixed mean with changing count probabilities

Probabilities of zero, one, two and at least three reportsn = 12: 0.282, 0.377, 0.230, 0.111; n = 48: 0.297, 0.365, 0.220, 0.118; n = 192: 0.300, 0.362, 0.218, 0.120; Poisson: 0.301, 0.361, 0.217, 0.121Model0123+n = 120.2820.3770.2300.111n = 480.2970.3650.2200.118n = 1920.3000.3620.2180.120Poisson0.3010.3610.2170.121Each row sums to 1Probabilities of zero, one, two and at least three reportsn = 12: 0.282, 0.377, 0.230, 0.111; n = 48: 0.297, 0.365, 0.220, 0.118; n = 192: 0.300, 0.362, 0.218, 0.120; Poisson: 0.301, 0.361, 0.217, 0.121Model0123+n = 120.2820.3770.2300.111n = 480.2970.3650.2200.118n = 1920.3000.3620.2180.120Poisson0.3010.3610.2170.121Each row sums to 1
Rows: Bin(n, 1.2/n) and Poisson(1.2). Cells contain probabilities; the last combines counts of three or more. Shading reflects mass. Increasing n brings the binomial probabilities toward the Poisson values while the mean remains 1.2.

Independent reports and shared causes#

Consider two newly specified mechanisms for a fictional 48-sensor board. In the first, each sensor independently reports with probability 1/401/40 in each window. The count is A∼Bin(48,1/40)A\sim\mathrm{Bin}(48,1/40). In the second, the board has twelve groups of four sensors. Each group independently activates with probability 1/401/40, and activation makes all four sensors report together. Thus B=4ZB=4Z with Z∼Bin(12,1/40)Z\sim\mathrm{Bin}(12,1/40).

Each individual sensor still reports with probability 1/401/40. Both counts have theoretical mean 1.21.2, but the second can take only multiples of four. Their zero-report probabilities already separate them:

P(A=0)=(39/40)48≈0.296634,P(B=0)=(39/40)12≈0.737998.\begin{aligned} P(A=0)&=(39/40)^{48}\approx0.296634,\\ P(B=0)&=(39/40)^{12}\approx0.737998. \end{aligned}

For orientation, variance measures the probability-weighted squared distance from the mean: Var⁡(X)=∑k(k−μ)2pX(k)\operatorname{Var}(X)=\sum_k(k-\mu)^2p_X(k) with μ=∑kkpX(k)\mu=\sum_k kp_X(k). The expectation and variance topic derives the summation rules. They give variances 48(1/40)(39/40)=1.1748(1/40)(39/40)=1.17 and 42⋅12(1/40)(39/40)=4.684^2\cdot12(1/40)(39/40)=4.68 for these mechanisms. A Poisson distribution with mean 1.21.2 has variance 1.21.2.

We generated 512 fictional windows from each mechanism, using Python Random seeds 2026111305 and 2026111308 respectively. Each independent sensor or group uses one fresh uniform draw per window, compared with 1/401/40. The following counts are saved outputs of that specified simulation, not measured sensor performance.

Figure

A shared cause changes the shape of the count distribution

Two synthetic count histogramsBuckets: 0, 1, 2, 3, 4, 5, 6+. Independent: 152, 191, 113, 42, 12, 1, 1. Grouped: 368, 0, 0, 0, 121, 0, 23. Both models have mean 1.2; only the grouped model has zero probabilities for 1, 2 and 3.Independent01002003004001520191111324231241516+reports per windowGroups of four01002003004003680010203121405236+reports per windowTwo synthetic count histogramsBuckets: 0, 1, 2, 3, 4, 5, 6+. Independent: 152, 191, 113, 42, 12, 1, 1. Grouped: 368, 0, 0, 0, 121, 0, 23. Both models have mean 1.2; only the grouped model has zero probabilities for 1, 2 and 3.Independent01002003004001520191111324231241516+reports per windowGroups of four01002003004003680010203121405236+reports per window
Bars: 512 synthetic windows per mechanism, independent sensors on the left and groups of four on the right. Red dots: expected windows under Poisson(1.2), without fitting. Scales match; “6+” includes the full tail. Narrow layouts stack the panels.

The observed means are 1.1757811.175781 and 1.3125001.312500; finite samples need not have equal means even when their models do. The corresponding empirical variances, with denominator 512, are 1.1058201.105820 and 5.0898445.089844. The independent case resembles a Poisson approximation; the grouped case leaves all one-, two- and three-report bins empty. Agreement in one histogram would still not prove independence. Here we know the mechanism because we constructed it.

Hypergeometric#

A maintenance team has a finite rack of eighteen devices, five marked for recalibration. It selects six uniformly without replacement. Every six-device subset has the same probability. The probability of selecting exactly two marked devices is

P(X=2)=(52)(134)(186)=275714≈0.385154.P(X=2)=\frac{\binom52\binom{13}4}{\binom{18}6} =\frac{275}{714}\approx0.385154.

The numerator chooses the marked and unmarked parts; the denominator counts all possible subsets. With population size NN, marked count KK and sample size nn, this is the hypergeometric distribution:

P(X=k)=(Kk)(N−Kn−k)(Nn),max⁡(0,n−N+K)≤k≤min⁡(n,K).P(X=k)=\frac{\binom Kk\binom{N-K}{n-k}}{\binom Nn},\qquad \max(0,n-N+K)\le k\le\min(n,K).

These bounds ensure neither part of the sample is larger than its available population. The parameters are integers with 0≤K≤N0\le K\le N and 0≤n≤N0\le n\le N. The selection mechanism matters: prioritizing devices known to be faulty would no longer make all subsets equally likely.

After drawing a marked device first, the next marked probability is 4/174/17; after drawing an unmarked device it is 5/175/17. The changing composition makes draws dependent. A binomial substitute with six trials and p=5/18p=5/18 gives 0.3148980.314898 for exactly two, appreciably below the correct value. The approximation improves when the sampled fraction is small, under uniform sampling; it cannot repair selection bias.

Which story gives which distribution#

What is fixed before drawing?What is counted?Distribution
One trial, report probability ppOne indicatorBernoulli
One trial, category probabilitiesOne category labelCategorical
nn independent trials, common ppReports among all nnBinomial
Independent trials, common p>0p>0Trials through the first reportGeometric
Independent rare opportunities, stable window meanTotal reportsPoisson approximation
A finite population and uniform sampling without replacementMarked items in the sampleHypergeometric

What changed#

A probability model now describes all possible counts together. We can compute a queue-overload probability, a waiting-time tail or a sampling probability from the same PMF. Choosing that PMF requires specifying the trial, the stopping rule and the dependence structure. The observed average alone cannot supply those choices.

Limitations#

Unequal probabilities and dependence have different effects. With two independent indicators of probabilities 0.10.1 and 0.90.9, the sum has masses (0.09,0.82,0.09)(0.09,0.82,0.09) at zero, one and two. A binomial with the same mean uses two probabilities of 0.50.5 and has masses (0.25,0.50,0.25)(0.25,0.50,0.25). The heterogeneous case is more concentrated: its variance is 0.180.18 instead of 0.500.50. Heterogeneity alone does not imply extra spread.

If both indicators instead equal the same fair indicator, the count has masses (0.5,0,0.5)(0.5,0,0.5) and variance 11. This positive dependence increases spread. Other forms of dependence can reduce it. Duplicate observations, shared failures and population shifts should prompt a check of the actual mechanism, not a universal correction factor.

Counts can also be censored: a counter that stops at four merges all larger values. Treating recorded fours as exact counts changes the model. The probability matrix groups counts of three or more as “3+”; the histogram figure groups six or more as “6+”. Discrete variables can have any countable support, including fractional values. Continuous and mixed distributions require another representation; an uncountable range alone does not guarantee the existence of a density.

What you should remember#

  • A random variable maps outcomes to numbers; its PMF aggregates outcomes sharing a value.
  • Bernoulli and categorical describe one trial. A normalized prediction vector still needs evaluation.
  • Binomial requires independent indicators with a common probability; geometric also changes the stopping rule.
  • Poisson is a rare-opportunity limit with a specified window mean. Shared causes can invalidate it.
  • Hypergeometric sampling is uniform and without replacement; the available composition changes.
  • Check assumptions and tail conventions before substituting a distribution into a calculation.

Code#

This standalone standard-library example reproduces the reported probabilities and both synthetic histograms. Python random() supplies reproducible pseudorandom draws; it does not turn the fictional model into real observations. The complete verification also enumerates all 18,564 six-device subsets and checks the formulas with exact fractions.

from math import comb, exp
from random import Random
from statistics import mean, pvariance

def binomial(n, p, k):
    return comb(n, k) * p**k * (1-p)**(n-k)

print("Binomial:", f"{binomial(12, .2, 3):.6f}",
      f"{sum(binomial(12, .2, k) for k in range(4, 13)):.6f}")
print("Geometric:", f"{.8**5:.5f}")
print("Poisson zero:", f"{exp(-1.2):.6f}")
for n in [12, 48, 192]:
    print("Binomial zero:", n, f"{(1-1.2/n)**n:.6f}")

# Each run is a fictional experiment with a specified dependence structure.
for group_size, seed in [(1, 2026111305), (4, 2026111308)]:
    rng = Random(seed)
    counts = [group_size * sum(rng.random() < 1/40
              for _ in range(48//group_size)) for _ in range(512)]
    histogram = [counts.count(k) for k in range(6)]
    histogram.append(sum(k >= 6 for k in counts))
    print("Group size:", group_size, "histogram:", histogram)
    print("Mean, variance:", f"{mean(counts):.6f}", f"{pvariance(counts):.6f}")

print("Without replacement:", f"{comb(5,2)*comb(13,4)/comb(18,6):.6f}")
print("Binomial substitute:", f"{binomial(6,5/18,2):.6f}")
Binomial: 0.236223 0.205431
Geometric: 0.32768
Poisson zero: 0.301194
Binomial zero: 12 0.282430
Binomial zero: 48 0.296634
Binomial zero: 192 0.300062
Group size: 1 histogram: [152, 191, 113, 42, 12, 1, 1]
Mean, variance: 1.175781 1.105820
Group size: 4 histogram: [368, 0, 0, 0, 121, 0, 23]
Mean, variance: 1.312500 5.089844
Without replacement: 0.385154
Binomial substitute: 0.314898

Next#

A trial count records the first reporting opportunity. A continuous waiting time records how long until an event, with no fixed trial spacing. Continuous distributions develops densities and the exponential waiting-time model. We will keep distinguishing a distributional assumption from evidence that a physical process satisfies it.

References#