Random variables and their distributions
"Measurable functions" showed how a function on a space can be measured: when is measurable, the set is an event for every Borel set , and the image measure records how much of the space is sent into . "Probability spaces and Kolmogorov's axioms" then supplied the spaces on which this will happen: two dice, a dart thrown at a square, a uniform number in , an endless sequence of coin tosses. This lesson puts the two together. A random variable is a measurable function on a probability space, a score, a count, a waiting time, and its distribution is its image measure, a probability measure on the number line that says how the values are spread. The lesson explains why one increasing function, the distribution function, describes the whole distribution, how atoms and densities appear in it, which distributions turn up most often, and how the inverse of the distribution function turns uniform numbers into draws from any distribution at all.
Random variables
Let be a probability space. A random variable is a measurable function . By "Measurable functions" this means that is an event for every Borel set , and by the half-line test it is enough that is an event for every real number . The name is old and slightly misleading: is neither random nor a variable. It is a fixed function that attaches a number to every outcome, and the randomness lies in which outcome the experiment produces. Writing is shorthand for .
Measurability is exactly what is needed to ask the questions one wants to ask. The number exists only if is an event. Take a die whose observer sees only the parity of the face, with the σ-algebra . For this observer the event "the face is at most 2" does not exist, since is not in the σ-algebra, so the face itself cannot be a random variable on this space, while "face mod 2" can. A random variable has to be computable from the information the events stand for.
Four examples, each on a model from "Probability spaces and Kolmogorov's axioms", show how varied random variables are.
- The sum of two dice. On the 36 outcomes , each with probability , let . When every subset of is an event, every function is measurable. The value 7 comes from six outcomes, , so , while the value 2 comes from only , so .
- Functions of a uniform number. On with Lebesgue measure, is a random variable, and so are and , which is only at the single outcome of probability 0. The event is , so . The event is , so its probability is .
- Heads among the first tosses. On the coin model, where the tosses are the binary digits of , let count the digits equal to 1 among the first . It depends on finitely many digits, so it is constant on dyadic intervals and measurable. Among the eight equally likely patterns of three tosses, three have exactly two heads, so . For ten tosses, .
- The distance of a dart from the centre. For a dart uniform on the unit square, let be its distance from the centre. The set is a disc of radius around the centre, and for the disc lies inside the square, so its area is . Hence and .
New random variables come from old ones by the rules of "Measurable functions". If is a random variable and is a Borel function, such as a continuous or monotone function, then is a random variable, because . Sums, products, maxima and limits of random variables are random variables, which is why and above needed no separate check.
The distribution of a random variable
A random variable moves probability from onto the number line. Think of one unit of sand spread over , with the probability of an event as the amount of sand in it, and let carry every grain from to the position . The distribution of , also called its law, is the image measure of under , as defined in "Measurable functions":
It tells how much sand ends up in . It is a probability measure on the Borel sets: the whole line receives , and disjoint sets have disjoint preimages, so countable additivity of carries over. For the sum of two dice the distribution is a collection of point masses, , in the notation of "Measuring the size of sets": masses at . For on the uniform space, .
The distribution forgets which outcome produced which value. It keeps only how the values are spread, and different random variables can have exactly the same distribution. On the variables and satisfy and , and the same holds for every interval, so they have the same distribution. Yet they are different functions: they agree only at , and they differ by more than exactly when or , which has probability . For two dice, , and is again a uniform face, so and have the same distribution while agreeing only when .
Two random variables with the same distribution are called equal in distribution, written . This is much weaker than : the first says that the values are spread alike, the second that they agree outcome by outcome. Random variables on different probability spaces can be equal in distribution as well. That is why a model is usually specified through a distribution, as in " is exponential with mean 2", without saying what is.
The distribution function
A distribution is a function on sets, a large object. One number for each real turns out to be enough. The distribution function of is
In sand terms, is the amount of sand at or to the left of . For the uniform , on , to the left and to the right. For it is on . For a fair die it is the staircase on , which stays at before the first face and at from the last face on. Four properties hold for every random variable, and each one follows from a rule of "Measuring the size of sets".
- Non-decreasing. If then , so by monotonicity.
- Limits 0 and 1. The events increase to , so by continuity from below. The events decrease to , so by continuity from above, which is allowed because the total mass is finite.
- Right-continuous. The event is the intersection of the decreasing events , so , again by continuity from above.
- Left limits. The event is the increasing union of , so the limit from the left is . It can be smaller than , because the point itself belongs to . This is why is continuous from the right but not necessarily from the left.
On the die, while just to the left of 3, : a jump of size at 3, with the value at the top of the jump. The properties let one read off probabilities. Since is the disjoint union of and for ,
The second formula says that the probability of a single value is the size of the jump of there. For the die, and .
The function determines the whole distribution. Two distributions with the same agree on every interval . By the uniqueness argument of "Lebesgue measure and null sets", two probability measures that agree on a family of sets closed under intersection agree on the σ-algebra generated by it, and the half-open intervals generate the Borel sets of "σ-algebras and Borel sets". So is a complete description of . The converse also holds: every function that is non-decreasing and right-continuous with limits and is the distribution function of some random variable. Section 7 constructs it.
Atoms, densities and mixed laws
A value with is an atom of the distribution: a point carrying a positive amount of sand, which shows as a jump of . This word has nothing to do with the atoms of a σ-algebra, the blocks of a partition. A distribution has at most countably many atoms, because at most values can have probability at least , since the total is 1. A distribution with all its mass on atoms is discrete, and the die and the sum of two dice are examples. Its distribution function is a staircase.
At the other extreme, a distribution has a density if for all , with and total area . Then is continuous, and where is continuous, . The density is the thickness of the sand layer, like the rod with density in "Measuring the size of sets": the mass in a short interval of width near is about . The exponential distribution with mean 1 has density for , so and .
A density value is not a probability. It can exceed 1: the uniform distribution on has density 2 there. Every single value has probability , because the area under a curve over one point is zero, and so has no jumps.
The two kinds can be mixed. Someone arrives at a traffic light. With probability it is green and the wait is minutes; otherwise the wait is exponential with mean 2 minutes. The wait has
The function jumps by at , so and is the only atom, and then it rises smoothly with slope towards 1. In sand terms the distribution is plus times an exponential layer. Most drivers do not wait at all, yet the waits of the others are spread over a continuum of values.
A fourth shape exists, and it is rare outside examples. Let be the tosses of the coin model, for tails and for heads, and let . The base-3 digits of are or , so always lies in the Cantor set of "Lebesgue measure and null sets". Its distribution function is the Cantor function: on the whole removed middle third , on , on , and constant on every removed interval. The removed intervals have total length 1, so is flat almost everywhere, yet it climbs from 0 to 1, and all of the climb happens on , which has length 0. This is continuous, so there are no atoms, and there is no density either: a density would give the probability , since has length zero, but . Such distributions are called singular.
A catalogue of common laws
A handful of distributions account for most of the cases one meets. Each comes from a short story, and recognising the story is the quickest way to know the distribution.
- Bernoulli($p$). One toss of a coin that shows heads with probability : and . This is the indicator of an event with .
- Binomial($n$, $p$). The number of heads in tosses of such a coin, the tosses not influencing each other: for . For a fair coin and , .
- Geometric($p$). The number of tosses up to and including the first head: for . For a fair coin , the pattern tails, tails, heads. On the coin model, means that the first binary digits of are all 0, which is the interval , so .
- Poisson($\lambda$). The number of events in a unit of time when they occur at random at an average rate : for . For , and .
- Uniform($a$, $b$). A number with all positions in equally likely: density on and there. The number of "Probability spaces and Kolmogorov's axioms" is Uniform(, ).
- Exponential(rate $\theta$). A waiting time without memory: density and for . Its mean is , so mean 2 means rate .
- Normal($\mu$, $\sigma^2$). The bell curve, centred at with spread : density . Its distribution function has no closed formula. For and , and . A later lesson of this track explains why sums of many small contributions look like this.
The Poisson distribution is a limit of binomial ones. Cut the unit of time into short pieces and suppose that each piece contains one event with probability , the pieces not influencing each other. The number of events is then binomial(, ), and for a fixed ,
The second factor tends to 1, since it is a product of factors each close to 1; the third tends to ; the fourth tends to 1. For and the binomial probabilities are for , for and for , approaching the Poisson value .
The exponential distribution has no memory. Its tail is , so . In words: among the waits longer than , the share that last more than further is , the same share as for a wait that has just begun. A wait that has already lasted minutes is no closer to its end. With mean 2, and , , and indeed .
Quantiles
Turning around answers a different question: below which value does stay with probability ? When is continuous and strictly increasing, there is exactly one such value, the inverse function . For the exponential distribution with mean 1, , so the median, , is , and the quartiles and are and .
Jumps and flat parts break this. On the die, no has , because jumps from to at 3. For the Cantor variable, every in has . The quantile function repairs both with the smallest suitable value:
In words: the first point at which has stayed below with probability at least . The infimum is needed because the set of such has no smallest element in general, and it is a minimum here because is right-continuous: the set contains its left end, so . For the die, gives and so . In fact every gives 3, and while . For the Cantor variable , and the quantile function skips the whole gap up to .
For the traffic light, for every , because the atom at 0 already makes . Above , solving gives , so minutes. The median is : more than half of the drivers do not wait.
The one fact about that matters below is an equivalence for every and every :
If , then belongs to the set whose infimum defines , so . If , then , using that is non-decreasing and that . The equivalence shows that is non-decreasing, hence measurable by "Measurable functions".
Inverse transform sampling
The quantile function also runs in the other direction. Let be uniform on , the number of the uniform model, and let be any distribution function. Then has distribution function :
The first equality is the equivalence above, and the second holds because for . By section 3, then determines the distribution of , and this also proves the converse promised there: every function with the four properties is a distribution function. In sand terms, the uniform interval is cut into pieces and mapped onto the number line. A jump of size in collects a piece of -values of length and sends all of them to one value, and a flat part of is skipped.
Examples show how it works. For the die, , and each face receives a piece of length of the -axis. For the exponential distribution with mean 2, , so , and gives minutes. For the traffic light, gives a wait of and gives minutes. A computer produces uniform numbers and nothing else, and this is how every other distribution is made from them.
The figure shows one uniform number at a time. Choose a distribution and move on the vertical axis: the guide runs across to and down to the value , and the readouts show that value and the probability of the atom there. The histogram collects 1,000 draws , each from its own uniform number, and the last two readouts compare their average with the exact mean. At the default, the exponential distribution and , the value is , there is no atom, and the average of the 1,000 draws is against the exact mean . Switch to the traffic light: at the guide hits the jump, the value is and the atom is ; of the 1,000 draws, 674 are exactly . On the die, gives the value with atom .
- u
- 0.50
- F⁻¹(u)
- 0.693
- P(X = F⁻¹(u))
- 0.000
- Mean of 1,000 draws
- 1.049
- Exact mean
- 1.000
Each draw is F⁻¹ of a uniform number: a jump of F collects a whole interval of u, a flat part is skipped.
If is continuous, the step also runs backwards: is uniform on , because . This probability integral transform fails when has jumps: for the traffic light, with probability .
Means: a first look
The last two readouts of the figure compare an average of draws with an exact number. The average is easy to compute from draws: add them up and divide by 1,000. The exact number is what such averages settle on as the number of draws grows. For the die it is , and the 1,000 draws of the figure averaged . For the traffic light it is minutes, since 70% of the drivers wait nothing and the others wait 2 minutes on average, and the draws averaged . For the exponential distribution with mean 1 it is , against . The gap shrinks as the number of draws grows.
Making this precise needs an integral against , and this is the topic of the next lesson, "Expectation, variance and inequalities". It defines the mean as an integral over , shows how to compute it from the distribution function, a density or a mixed law, and measures how widely draws scatter around it.
Summary
- A random variable is a measurable function on a probability space; its distribution is the image measure, a probability measure on the Borel sets that forgets which outcome gave which value.
- The distribution function is non-decreasing and right-continuous with limits and , and it determines the distribution: and .
- Jumps of are atoms and slopes are densities; a distribution can be discrete, have a density, be mixed like the traffic light, or, rarely, be continuous without a density like the Cantor function.
- The common distributions, Bernoulli, binomial, geometric, Poisson, uniform, exponential and normal, each come from a short story, and the Poisson distribution is the limit of binomial(, ).
- The quantile function satisfies , so has distribution function for a uniform : inverse transform sampling.