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 and sensor B with probability . An outcome records both signals, such as . Define to be their total. Several outcomes can give the same value of :
| Outcome | Probability | Count |
|---|---|---|
A random variable assigns a real number to an outcome: . Events such as 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):
The masses are nonnegative and sum to one. A probability about the count is a sum of the corresponding masses. For example, . The value 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: . Here it is zero below zero, on , on and one from two onward. Consequently . 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 , where and . 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 , and . These sum to one. The probability of requiring any intervention is , 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 . Let count reports. For general , any particular sequence with reports has probability . Independence lets us multiply, and the common makes this probability identical for all sequences with that count. There are choices of reporting positions. Therefore
This is . The binomial theorem verifies that its probabilities sum to . At the endpoint the count is always zero; at it is always , without needing to interpret ambiguous powers in an implementation.
For the twelve devices, exactly three reports have probability . If the repair queue can accept three jobs, overload means at least four reports:
The event starts at four, so using 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- argument.
Geometric#
Instead of fixing the number of trials, wait for the first report. Assume independent trials with the same reporting probability , and count the reporting trial itself. For , the event requires nonreports followed by one report:
At , more than five trials are needed with probability . A convention that counts nonreports instead uses and starts at zero. Check which quantity a software interface returns before interpreting its result; SciPy’s geom counts the successful trial (reference). At , a first report never arrives, so no probability distribution on finite positive trial counts results.
For , after three nonreports the chance of five more is unchanged. More generally, for nonnegative integers ,
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 , observing failures can change our uncertainty about and hence our predictive waiting time. For , 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 and their probability to , where the expected count stays fixed. For a fixed nonnegative integer and sufficiently large ,
The finite product tends to one because is fixed. The last factor also tends to one, while tends to . The limiting masses sum to one by the exponential series. They define . At , 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 per minute, a window of length minutes has parameter . 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 . The zero-report probabilities for are respectively , and , approaching . The figure keeps the whole probability mass, including the tail bucket.
A fixed mean with changing count probabilities
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 in each window. The count is . In the second, the board has twelve groups of four sensors. Each group independently activates with probability , and activation makes all four sensors report together. Thus with .
Each individual sensor still reports with probability . Both counts have theoretical mean , but the second can take only multiples of four. Their zero-report probabilities already separate them:
For orientation, variance measures the probability-weighted squared distance from the mean: with . The expectation and variance topic derives the summation rules. They give variances and for these mechanisms. A Poisson distribution with mean has variance .
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 . The following counts are saved outputs of that specified simulation, not measured sensor performance.
A shared cause changes the shape of the count distribution
The observed means are and ; finite samples need not have equal means even when their models do. The corresponding empirical variances, with denominator 512, are and . 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
The numerator chooses the marked and unmarked parts; the denominator counts all possible subsets. With population size , marked count and sample size , this is the hypergeometric distribution:
These bounds ensure neither part of the sample is larger than its available population. The parameters are integers with and . 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 ; after drawing an unmarked device it is . The changing composition makes draws dependent. A binomial substitute with six trials and gives 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 | One indicator | Bernoulli |
| One trial, category probabilities | One category label | Categorical |
| independent trials, common | Reports among all | Binomial |
| Independent trials, common | Trials through the first report | Geometric |
| Independent rare opportunities, stable window mean | Total reports | Poisson approximation |
| A finite population and uniform sampling without replacement | Marked items in the sample | Hypergeometric |
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 and , the sum has masses at zero, one and two. A binomial with the same mean uses two probabilities of and has masses . The heterogeneous case is more concentrated: its variance is instead of . Heterogeneity alone does not imply extra spread.
If both indicators instead equal the same fair indicator, the count has masses and variance . 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#
- NIST/SEMATECH. e-Handbook of Statistical Methods, §1.3.6.1: What is a probability distribution?, §1.3.6.6.18: Binomial distribution, and §1.3.6.6.19: Poisson distribution. Definitions, PMFs and moments; accessed 13 November 2026. Our examples and figures are independently specified.
- The SciPy community. SciPy 1.18.0 reference manual:
geom, Notes andhypergeom, Notes. Support conventions and hypergeometric parameter mapping. No documentation example, plotting code or input data is reused. - Python Software Foundation. Python 3.15.2 documentation,
random: Notes on reproducibility. SeededRandominstances andrandom()sequence guarantees; the executable example uses only APIs also present in Python 3.9.