c12 · Section 1
Random variables
How do you attach a number to an outcome?
L1Core
The idea, one concrete case and enough to use it. Every simplification is marked and linked to the precise statement.
A hospital ward keeps a chart with one column headed times the bell rang last night. For each patient the entry is a whole number from 0 to 5. Nobody writes "often", and nobody writes "twice, but it felt like more". Before any arithmetic begins, the chart has already made a decision: it turned a night into a count.
That decision is this section's question, and it sits underneath the chapter's question about how far one average can be trusted. A random variable is a rule that reads an outcome and returns a number [S:141:245]. The outcome is what happened; the number is what you agree to write down. The same night supports several rules, because the count of rings, the minutes slept and a single mark for "pressed at all" are three different numbers built from one sequence of events. !Eight equally likely sequences from three tosses stand on the left, and the bars on the right are the distribution. With the rule 'count the heads', TTT gives 0, three sequences give 1, three give 2 and HHH gives 3, so the two middle values carry 3/8 each. With the rule 'did the first toss show heads', the same eight sequences split four and four. The chips do not move; the arrows do. Status: synthetic.
Write the rule in words and let x stand for one value it takes. The rule is fixed before you look, and a number chosen after the outcome is known is not a random variable, whatever quantity it measures. This book uses capital X for the space of possible inputs, the set of outcomes the rule reads, so the rule itself is a sentence and x is a value. The Deepen explains why other books name the rule X. !A count lands on separated values: a ward recording 0 to 5 rings has six possible answers and nothing between 2 and 3. Hours slept fill the gaps. The lower strip is a band rather than six ticks, and the wedge expands the hour from 6 to 7 to show values inside an interval that a count would leave empty. Status: schematic.
The jar example makes the step visible. A jar holds one red, one white and one blue marble, so the sample space is those three colours. Let the recorded number be one when the drawn marble is red and zero otherwise [S:141:246]. The outcomes are three and the values are two, so nothing is lost for the question you asked and everything about the colour disappears from the record, for this one rule. Two rules can throw away different things and still give the same table, and then neither table tells you how the two move together.
A variable whose values you obtain by counting is discrete; one whose values you obtain by measuring is continuous [S:141:246]. Rings are counted, so the count stops at whole numbers. Hours slept are measured, so between six hours and seven hours sit infinitely many other possible answers.
For a rule that lands on separate values, the list of values together with their probabilities is a probability distribution. It obeys two rules: each probability lies between zero and one, and the probabilities add to one [S:135:241]. A measured rule breaks the table form, because the chance of any single value is zero. Its description is a density, a curve whose area over a range gives the probability of that range, and the area under the whole curve is one [S:135:327].
Worked example. Toss three fair coins and record the number of heads [S:141:246]. Each toss has two outcomes, so three tosses give two times two times two, which is eight sequences, from TTT to HHH, and a fair coin makes all eight equally likely. Sort the eight by the number of heads they contain.
| heads | sequences | probability |
|---|---|---|
| 0 | TTT | 1/8 |
| 1 | HTT, THT, TTH | 3/8 |
| 2 | HHT, HTH, THH | 3/8 |
| 3 | HHH | 1/8 |
Three sequences carry one head and three carry two [S:141:246], so the probability of exactly one head is 3/8, which is 0.375, and the probability of no heads at all is 1/8, which is 0.125. The four entries add to 8/8, as the second rule demands. Nothing in the table is surprising once the rule is stated, because a count over three coins can only land on four values, and the middle values have more sequences behind them.
Notice what the table does not contain. It says nothing about the order of heads and tails, because the rule was a count and counts do not remember order. Change the rule to "did the first toss show heads" and four of the eight sequences begin with H, so the same eight outcomes collapse to two values, each with probability 4/8. Both tables are correct while answering entirely different questions.
Stop and try
roll one die and let x be 1 when the roll is even and 0 when it is odd. Write the distribution as a table, and say whether x is discrete.
Key idea
A random variable is a rule that turns an outcome into a number, fixed before the outcome is known. For a rule with separate values, its distribution lists each value with its probability, and those probabilities add to one. Because the rule is yours to choose, the number and every average built from it depend on that choice.
The idea costs something at the moment you report a number. A count records one feature of a night and discards the rest, so an average over counts cannot recover what the coding dropped. Coding death as 1 and survival as 0 is a legitimate random variable whose average is a mortality rate, and a hundred different wards can share that rate while sharing almost nothing else. The rule also fixes what counts as an outcome: if the ward's 5 means "five or more", the value is a capped count, with every night of five or more rings written as 5. Its average is not the average number of rings, so read the coding before you read the average.
L2Deepen
The formal statement, the derivation and the edge cases. It refines L1 and never contradicts it.
The formal statement. Fix a probability space: a set of outcomes, a collection of events, and a probability on those events that obeys the Kolmogorov axioms [S:60:13]. A random variable is a function from the outcomes to the real numbers with one extra condition: for every real number, the set of outcomes whose value falls at or below it is an event [S:81:31]. That condition is measurability, and it is what lets the question "what is the probability that the value is below this number" have an answer. The distribution of the rule is the probability it pushes forward onto the real line: the probability of a set of values is the probability of the outcomes that map into that set [S:81:31].
The derivation. For a discrete rule, the pushed-forward probability of a value v is the probability of the event that the rule equals v. The events that the rule equals different values are disjoint and together cover every outcome, so their probabilities add to one [S:135:241], and each of them is a probability, so it lies between zero and one [S:135:241]. Nothing about the shape of the rule enters this argument, which is why the table form covers every rule that lands on separate values, including a count, a capped count and an indicator.
The continuous case. For every rule the pushed-forward law is a probability measure: the probability of a set of values lies between zero and one, and the probability of the whole line is one. The table is the discrete special case. A continuous rule assigns probability zero to each single value, so no table of values can describe it. Its law is a density, which is non-negative, integrates to one over the line, and may be greater than one at a point [S:74:463]. The probability of an interval is then the area under the density over that interval [S:135:327]. The two rules you carry away are the measure rules; the table is one way of writing them down.
The edge case. Let f be one when the first toss of a fair coin is heads and zero otherwise. Let g be one when the second toss is heads. Both rules take the two values zero and one, and they give those values the same probabilities, so they have the same distribution. They are different variables, and their two distributions do not determine the distribution of their sum. The pushed-forward law keeps each rule's own probabilities and discards the pairing between the two tosses. The core's sentence about the colour is right for one rule; read as a claim about a table of several rules, it is misleading.
What the core hid. Two things. The first is measurability: the definition admits only rules whose preimages are events [S:81:31]. Every rule in the core is built from finite sets or intervals, so the restriction never bites there. The second is the outcome space itself. The core treats the night in the ward as the outcome; formally the outcome is a point, and the night is a description you chose to write down.
Where the notation breaks. Many texts write a capital letter for the rule, as OpenStax does [S:141:245]. This book keeps the capital X for the input space and writes the rule as a sentence, so when a name is needed the rule is f here. When you read another book, translate the letter before you compare formulas. The object being named is a function, and the letter is a convention.
L3Research
Full rigour, the original sources and the open questions. This is the research frontier.
Original sources. The school definition is OpenStax: a random variable is a variable whose values are the numerical outcomes of a probability experiment, described in words and then given in numbers [S:141:245]. The measure-theoretic definition is Definition 2.2 of Lattimore and Szepesvári, which makes the rule a measurable function and names its distribution the pushforward of the probability [S:81:31]. The axioms that make a pushforward a probability are Kolmogorov's, stated as Definition 1.3 in Krause and Hübotter [S:60:13].
An open question. A model that returns one number and a model that returns a distribution over numbers are both random variables, and there is no general rule for when the second earns its cost. The practical version is the split between aleatoric and epistemic uncertainty, and Krause and Hübotter call the allocation between them a modelling choice [S:60:54]. Evidence that would settle a case: calibrated predictive distributions and decision costs on held-out data, compared with a point predictor of the same size and training budget. Until that comparison exists, the choice is a design decision and not a theorem.
A frontier result. The reparameterisation trick writes a draw from a learned distribution as a fixed function of independent noise. You sample a noise value from a distribution that does not depend on the parameters, then transform it with a deterministic and differentiable function [S:62:309]. In the language of 12.1, the model supplies the rule, the noise supplies the outcome, and the sample is the number. Gradients pass through the transformation because the randomness sits entirely in the noise, which is the separation between rule and draw that the core asked you to keep.
What to read next. Read section 2.1 of Lattimore and Szepesvári for measurable maps and pushforwards [S:81:31], then chapter 4 of OpenStax for the discrete case and its tables [S:141:245]. Read section 6.3.5 of Murphy for the reparameterisation trick [S:62:309]. The order runs from the definition, to the table, to the use.