Mathematical foundations
Random Variables and Probability Models
Learn the sample-space, event, random-variable, distribution, density, and modeling distinctions that support probabilistic machine learning.
By the end you can
- Distinguish outcomes, events, random variables, probability mass functions, densities, and cumulative distributions
- Explain why a density value is not itself a probability
- Translate a real uncertainty question into a probability model with a clear sample space
- Identify where probability assumptions enter prediction, simulation, and decision-making
Visual
From outcomes to distributions
Each layer answers a different question, and the vocabulary is not loose talk. These are the definitions a measurement standard is willing to be held to. The international Guide to the expression of uncertainty in measurement — the GUM — gives each one its own numbered clause. A random variable there is a variable with an associated probability distribution: the variable is defined first, on the outcomes, and the distribution is attached to it afterwards. The distribution function, the density and the mass function each get a clause of their own. On the density the standard is careful. It calls f(x)dx the “probability element”, not a probability.
The layers are separable because each can fail on its own. A sample space can omit an outcome the world still produces. A random variable can be a perfectly good function of outcomes the model has mis-specified. A distribution can be internally consistent and empirically wrong. Only the last layer, summaries and decisions, has no clause in any standard: what the number is for is not a mathematical question.
- 01
Sample space Ω
All elementary outcomes the model treats as possible.
- 02
Events
Subsets of outcomes about which probability statements are made.
- 03
Random variable X
A function that converts outcomes into values.
- 04
Distribution of X
The probabilities induced on those values.
- 05
Summaries and decisions
Expectations, intervals, risks, and actions computed from the distribution.
A random variable is a function on outcomes, not a mysterious number that changes by itself.
A probability model is a disciplined description of uncertainty
Probability begins with a set of possible outcomes and a rule that assigns probabilities to events. A random variable maps each outcome to a numerical value. This separation matters. The uncertainty belongs to the modeled outcome, while the random variable is the quantity we choose to observe or summarize.
A model may be mathematically coherent yet empirically poor, and the cost of that gap is not always academic. In R v Clark the prosecution's headline figure was that the chance of two sudden infant deaths in one family was 1 in 73 million. The arithmetic behind it was a single multiplication. The Court of Appeal's judgment records Professor Meadow's evidence that “you have to multiply 1 in 8,543 times 1 in 8,543 ... approximately a chance of 1 in 73 million”. Squaring a rate is a legitimate operation inside a model in which the two deaths are independent events. Whether that model applies to families was never established.
The Royal Statistical Society said so in a news release in October 2001: “This approach is, in general, statistically invalid. It would only be valid if SIDS cases arose independently within families, an assumption that would need to be justified empirically.” The same release stated that the 1 in 73 million figure “has no statistical basis”. The judgment also records Professor Berry's objection that “simply squaring the figure was an illegitimate over simplification”. On 11 April 2003 the Court of Appeal held that it was very likely the figure “grossly overstates the chance of two sudden deaths within the same family from unexplained but natural causes”.
Probability theory tells us how conclusions follow from assumptions; data and model checking tell us whether those assumptions are useful. Nothing inside 8,543 × 8,543 could have raised the independence assumption. It had to be written down as an assumption, and then tested against families.
The multiplication in R v Clark was correct; what went unchecked was the model that made multiplying legitimate.
Case
Kolmogorov, 1933: the axioms are younger than the mathematics using them
The rules used here are less than a century old. Andrei Kolmogorov published Grundbegriffe der Wahrscheinlichkeitsrechnung in Berlin in 1933, and it set probability on a measure-theoretic footing. The title page of that first edition carries the name as A. Kolmogoroff.
Its sources were traced in 2006 by Glenn Shafer and Vladimir Vovk, writing in Statistical Science. Their assessment of the book comes in two halves. It “put probability’s modern mathematical formalism in place”, and it “also provided a philosophy of probability--an explanation of how the formalism can be connected to the world of experience”. Both halves arrived together, and the second half is the one every later section of this lesson keeps returning to. The axioms will not tell you which sample space you are in, whether two infant deaths in one family are independent events, or which class of days a forecast refers to. They tell you what follows once those choices are made.
Comparison
Mass, density, and cumulative probability
The three functions describe distributions in different ways. The distinctions are formal enough that a metrology standard writes them out one clause at a time. In the GUM the distribution function is “a function giving, for every value x, the probability that the random variable X be less than or equal to x”. That is the CDF, and the definition covers discrete and continuous variables alike. The probability density function is the derivative of that distribution function, with f(x)dx named the “probability element”. The probability mass function gives pi = Pr(X = xi) for a discrete variable.
A US federal agency states the same split independently. The NIST/SEMATECH e-Handbook of Statistical Methods writes the discrete case as P[X = x] = p(x), with the values summing to one. It writes the continuous case as p[a ≤ x ≤ b] = ∫f(x)dx, with ∫f(x)dx = 1 over the line. Two institutions, one boundary. The mass function hands you a probability. The density hands you probability per unit, and only its integral over an interval is a probability.
PMF
Assigns probability directly to discrete values.
- P(X=x) can be positive
- Values sum to one
- Used for counts and categories
- Example: Bernoulli outcomes
Assigns probability density to continuous values.
- Point probability is usually zero
- Interval probability is an integral
- Density may exceed one
- Units are inverse to the variable's unit
CDF
Gives P(X≤x) for discrete or continuous variables.
- Always ranges from zero to one
- Nondecreasing
- Encodes the full distribution
- Useful for quantiles and tail probabilities
Why density can be larger than one
A density is probability per unit of the variable. If a uniform variable lies between 0 and 0.1, its density is 10, so that the area over the interval equals one. The number 10 is not a probability. The NIST/SEMATECH e-Handbook of Statistical Methods puts the whole point in three sentences: “Probabilities are measured over intervals, not single points. That is, the area under the curve between two distinct points defines the probability for that interval. This means that the height of the probability function can in fact be greater than one.”
How much greater is a question of units, and the GUM works a case where the answer is spectacular. It takes the coefficient of linear thermal expansion of pure copper at 20 °C, 16,52 × 10⁻⁶ °C⁻¹, and models the possible values by “this symmetric rectangular distribution of possible values” of half-width a = 0,40 × 10⁻⁶ °C⁻¹. The height of that density is 1/(2a) = 1.25 × 10⁶ °C. Over a million, in an official worked example, and its integral is still exactly one. The variable itself is measured in millionths.
Confusing density with probability leads to incorrect likelihood interpretations and unit errors. A likelihood of 1.25 × 10⁶ is not a certainty. A likelihood ratio between two densities is only meaningful when both are expressed per the same unit. Likelihood values can exceed one for continuous models, for exactly the reason the copper example shows.
Example
Choosing the random experiment
One deployed setting can support several different probability models, and the choice of experiment decides what the resulting number even counts. Epic's proprietary sepsis prediction model was externally validated at Michigan Medicine over 2018–2019, and the verdict published in JAMA Internal Medicine in 2021 was blunt: “This external validation cohort study suggests that the ESM has poor discrimination and calibration in predicting the onset of sepsis.” The cohort is described two ways in the same sentence of the paper's own methods — 27,697 patients and 38,455 hospitalizations. Every headline figure below belongs to one of those units, not to both.
- One hospitalization: X indicates whether the model alerts during a single hospitalization, a Bernoulli variable whose sample space is one stay. In this cohort it equalled one for 18% of the 38,455 hospitalizations, which fixes the alert burden but says nothing yet about whether the alerts were right.
- One patient: the missed-case figure is reported on people, not stays: 1,709 of 2,552 septic patients, 67%, were not identified. A rate per patient and a rate per hospitalization are different random variables over different sample spaces, and 27,697 against 38,455 is the size of the difference.
- A ranking rather than an alarm: the area under the curve treats the score as an ordering and asks only whether sicker patients rank higher. Measured externally it was 0.63 (95% CI, 0.62–0.64), against the 0.76–0.83 range the vendor reported. Same model, different experiment and different population, and the number a buyer was shown is not the number this hospital got.
- Outcomes conditioned on a threshold: a different team ran the same model over 145,885 emergency-department encounters in two county hospitals. At the vendor-recommended alert threshold they measured sensitivity 14.7%, specificity 95.3%, positive predictive value 7.6% and negative predictive value 97.7%. Four numbers, one model, all of them conditional on where the cut was placed.
- An aggregate over a ward: S, the alert load a unit absorbs in a shift, is a sum of outcomes that are not independent of each other — they share staff, season, admission policy and the same scoring rule. Aggregating it requires a joint model, not independent marginals multiplied together.
Steps
Building a probability model from a question
Start with the uncertain process rather than a favorite distribution. The first four steps are the ones that get done. Step five, checking consequences against recorded frequency, is the one that gets skipped, and it is the only step that can catch a model that is coherent in every other respect.
That check was run on image classifiers in 2017, and the paper opens with the finding: “We discover that modern neural networks, unlike those from a decade ago, are poorly calibrated.” Guo and colleagues bin predicted probabilities into 15 bins and report expected calibration error. On CIFAR-100 a 110-layer ResNet is 16.53% off. A 5-layer LeNet on the same data is 4.85%. The older and less accurate model is the better probability model — “the average confidence of LeNet closely matches its accuracy, while the average confidence of the ResNet is substantially higher than its accuracy”. A single fitted parameter, temperature scaling, brings the ResNet from 16.53% to 1.26%. The ordering of its predictions was never the problem. The probabilities attached to that ordering were.
Step five also has to be repeated, because its findings expire. In 2021 Minderer and colleagues revisited the same question at a different venue and found that “the most recent models, notably those not using convolutions, are among the best calibrated”. The check is the deliverable, not the conclusion drawn from one run of it.
1. Define the experiment
State what repeats or what future outcome is uncertain.
2. Define outcomes and events
List the distinctions the model must preserve.
3. Choose random variables
Map outcomes to the values needed for prediction or decisions.
4. Propose a distribution
State support, dependencies, parameters, and time assumptions.
5. Check consequences
Compare simulated and observed frequencies, tails, and conditional patterns.
Key idea
Probability statements are always conditional on information
Even when notation omits it, a probability statement depends on a model, population, time, and available information. “The probability is 0.2” is incomplete without those conditions — and so, it turns out, is the most widely published probability in the world.
In autumn 2002 researchers stopped 750 pedestrians in five cities and asked what “There is a 30% chance of rain tomorrow” means: New York (n=103), Amsterdam (n=117), Berlin (n=219), Milan (n=203) and Athens (n=108). Only in New York did a majority, about two-thirds, pick the meteorologists' own reference class: rain on 30% of days like tomorrow. In each of the European cities that same option was the one most often judged the least appropriate. Gigerenzer and colleagues, writing in Risk Analysis in 2005, locate the fault in the statement rather than in the public: “Because the forecast is expressed as a single-event probability, however, it does not specify the class of events it refers to.”
An independent group reached the same place with its own participants. Joslyn and colleagues reported in the Bulletin of the American Meteorological Society in 2009 that “many people did not understand probability of precipitation (PoP)”, and that “the misunderstanding concerned the class of events to which the probability refers”.
Predictive systems estimate P(Y|X=x) under training and deployment assumptions, and the reference class is exactly what changes between the two. Epic's sepsis model kept its arithmetic and lost half its AUC when the population underneath it changed: 0.76–0.83 became 0.63. If the conditioning context changes, the probability can change without contradicting itself. Document the reference population and information set beside every operational probability, in the words a user will read, not only in the model card.
A probability is not a property of an event alone; it is a property of an event within a stated model and information state.
Key takeaways
- Probability models begin with outcomes and events; random variables map those outcomes into useful values, and the GUM gives each layer its own numbered clause precisely because each can fail on its own.
- PMFs assign probability directly, PDFs assign density whose f(x)dx is only a “probability element”, and CDFs give the probability that X is less than or equal to x; the NIST/SEMATECH e-Handbook states the same split independently.
- A density value is not a probability and may exceed one: the GUM's rectangular model for copper's expansion coefficient, half-width 0,40 × 10⁻⁶ °C⁻¹, has height 1.25 × 10⁶ °C and integral one.
- Probability statements depend on a model, population, time, and information set: of 750 pedestrians asked what “There is a 30% chance of rain tomorrow” means, only New York produced a majority for the forecasters' reference class, and in each European city surveyed that reading was most often judged the least appropriate.
- Different random variables summarize the same experiment for different decisions: the Epic sepsis validation counted 27,697 patients and 38,455 hospitalizations, and its 18% alert rate and its 67% of missed septic patients belong to different denominators.
- A probability model must be challenged against observed frequency rather than accepted from algebra: squaring 1 in 8,543 produced 1 in 73 million with no empirical warrant, and a 110-layer ResNet's 16.53% calibration error only fell to 1.26% once someone measured it.