Random variables and the cumulative distribution function: one function that tells you everything about a distribution
What a random variable, its distribution and the cumulative distribution function are, how discrete and continuous variables differ and how to estimate the distribution function from data.
Series AI basics Part 14 of 52
- Map of artificial intelligence: what is what and how it all fits together
- A brief history of artificial intelligence: from Turing to language models
- Data, model, training, inference: the basic terms on a single example
- How to read mathematical notation: symbols, indices, sums and quantifiers
- Sets and relations: the building blocks of definitions in AI
- Functions and mappings: why every AI model is a function
- Logic and proofs: the rules AI reasons by
- Graphs and trees: the structure that both search and neural networks stand on
- Linear algebra for machine learning: vectors, matrices and why AI mostly multiplies
- Derivatives, the gradient and the chain rule: how a model finds out which way to learn
- Gradient descent: how a model learns
- What probability is: from rolling dice to the Kolmogorov axioms
- Conditional probability and Bayes’ theorem: how to update your estimate when you learn something new
- Random variables and the cumulative distribution function: one function that tells you everything about a distribution
- Probability density and probability mass functions: why a continuous variable has zero probability at a point
- Expected value, variance and covariance: where a distribution lies, how wide it is and what goes with what
- Overview of probability distributions: Bernoulli, binomial, Poisson, uniform, normal and exponential
- Law of large numbers and central limit theorem: why averages behave so predictably
- Statistics and parameter estimation: maximum likelihood, MAP and confidence intervals
- Information theory: entropy, cross-entropy and KL divergence — where loss functions come from
- State-space search: BFS, DFS, UCS and A* with animations
- Games and adversaries: minimax, alpha-beta pruning and Monte Carlo tree search
- Constraint satisfaction: backtracking, constraint propagation and AC-3 on sudoku and a map of Czech regions
- Logic and knowledge systems: forward and backward chaining, resolution and expert systems
- Planning: STRIPS, the blocks world, heuristics from relaxation and planning in AI agents
- Local search and simulated annealing: a travelling salesman through the Czech regional capitals
- Genetic algorithms: population, crossover, mutation and selection on a backpack for a hike
- Evolution strategies and genetic programming: from the one-fifth rule to Kepler’s law
- Ant colony optimization: how a pheromone trail finds a short path
- Particle swarm optimisation: inertia, personal experience and the swarm’s experience
- Neuroevolution: evolving the weights and shape of neural networks, and the NEAT algorithm
- Fuzzy sets and membership functions: how to write down “somewhat warm”
- Fuzzy logic and probability: why “somewhat warm” does not mean “probably warm”
- Fuzzy logic: t-norms, implications and IF–THEN rules
- Fuzzy control: Mamdani and Sugeno from a fan to a pole on a cart
- Fuzzy clustering: the fuzzy c-means algorithm and points between clusters
- Neuro-fuzzy systems (ANFIS): fuzzy rules that learn from data
- Markov chains: the transition matrix, the stationary distribution and PageRank
- Hidden Markov models: the Viterbi algorithm and the dishonest casino
- Bayesian networks: why the grass is wet and what it means for the sprinkler
- The Kalman filter: how to estimate where a car is and how fast it goes from imprecise measurements
- Types of machine learning: supervised, unsupervised, semi-supervised and more
- Prompts, context and RAG: how to give a model the right information
- Variational autoencoders (VAE): new images from a continuous latent space
- Generative adversarial networks (GAN): the forger versus the detective
- Diffusion models: how pure noise becomes an image
- Markov decision processes: states, actions, rewards and the Bellman equations
- Q-learning and DQN: learning the value of actions, from a table to a neural network
- Policy gradient and PPO: learning the policy directly
- How an AI agent works: a language model in a loop with tools
- Programming with AI agents: the task, tests and review
- Evaluating and securing AI systems: how to measure and how to keep watch
Full series syllabus 52 of 83 topics published
- That a random variable is an ordinary function that assigns a number to the outcome of an experiment.
- What the cumulative distribution function is, what properties it has and how to use it to calculate the probability of an interval.
- How discrete and continuous variables differ and how to estimate the distribution function from data.
Useful to know first: What probability is: from rolling dice to the Kolmogorov axioms, Functions and mappings: why every AI model is a function
In the part What probability is we worked with events: “the sum is 7”, “a six came up”. But most of the time we do not care whether something happened — we care how much: how many minutes we will wait for the bus, what a share will cost, what temperature the thermometer will show. For that, mathematics has the random variable — and a function that tells you absolutely everything about it.
1. Random variable
Definition — probability space
Let Ω be a non-empty set (the sample space of a random experiment, see the part What probability is) and 2Ω the set of all its subsets. A system 𝓕 ⊆ 2Ω is a σ-algebra if and only if
- Ω ∈ 𝓕;
- if A ∈ 𝓕, then Ac = Ω ∖ A ∈ 𝓕;
- if A1, A2, … ∈ 𝓕, then ⋃i=1∞ Ai ∈ 𝓕.
Let 𝓕 ⊆ 2Ω be a σ-algebra; its elements are called events. A function P : 𝓕 → ℝ is a probability if and only if it satisfies the Kolmogorov axioms:
- P(A) ≥ 0 for every A ∈ 𝓕;
- P(Ω) = 1;
- for every sequence A1, A2, … ∈ 𝓕 with Ai ∩ Aj = ∅ for all i ≠ j, we have P(⋃i=1∞ Ai) = ∑i=1∞ P(Ai).
A probability space is a triple
(Ω, 𝓕, P),
where Ω is a non-empty set, 𝓕 ⊆ 2Ω is a σ-algebra and P : 𝓕 → ℝ is a probability. The axioms imply 0 ≤ P(A) ≤ 1 for every A ∈ 𝓕, so P maps into [0, 1].
Outcomes, the questions we are allowed to answer with a probability, and the probability itself. For two dice, 𝓕 is simply all 236 subsets of Ω. On infinite spaces (say, “a random point of a line segment”) probability cannot sensibly be assigned to every subset, and that is why 𝓕 is introduced at all: it contains only the sets you can calculate with — and it is closed under “not”, “or” (and therefore also “and”).
Definition — random variable
Let (Ω, 𝓕, P) be a probability space. A random variable is a function X : Ω → ℝ that satisfies
∀x ∈ ℝ : {ω ∈ Ω : X(ω) ≤ x} ∈ 𝓕.
So a function X is a random variable if and only if for every real x the set of outcomes for which X comes out at most x is an event. Instead of {ω ∈ Ω : X(ω) ≤ x} we write {X ≤ x} for short, and instead of P({X ≤ x}) just P(X ≤ x); likewise {X = x}, {X ∈ B} and so on.
A random variable is neither random nor a variable — it is an ordinary function that assigns a number to every outcome of an experiment. The randomness lives in the outcome ω; the variable merely turns it into a number you can calculate with. The condition in the definition guarantees that we can ask “what is the probability that X ≤ x?”.
One experiment can carry several variables. Rolling two dice has 36 outcomes; S(ω) is the sum of both dice, N(ω) the number of sixes. To the outcome (3, 6), S assigns the number 9 and N the number 1. The picture shows S as a function: every square on the left carries its value, and the column on the right shows how many squares land on that value.
Example — the event {S ≤ 3} as a set of outcomes
The notation {S ≤ 3} is short for {ω ∈ Ω : S(ω) ≤ 3} — the set of outcomes that the function S sends to a number at most 3 (it is called the preimage of the interval (−∞, 3]).
{S ≤ 3} = {(1, 1), (1, 2), (2, 1)}, P(S ≤ 3) = 3/36 = 1/12
{S ≤ 1} = ∅, {S ≤ 12} = Ω
For two dice every set of outcomes is an event, so the condition in the definition holds automatically.
2. Distribution of a random variable
Definition — distribution of a random variable
Let (Ω, 𝓕, P) be a probability space and X : Ω → ℝ a random variable. Denote by 𝓑 the Borel σ-algebra on ℝ — the smallest σ-algebra of subsets of ℝ that contains all intervals (−∞, x], x ∈ ℝ (it then also contains all other intervals, single-point sets and their countable unions). The definition of a random variable implies {ω ∈ Ω : X(ω) ∈ B} ∈ 𝓕 for every B ∈ 𝓑. The distribution of the random variable X is the function PX : 𝓑 → [0, 1],
PX(B) = P(X ∈ B) = P({ω ∈ Ω : X(ω) ∈ B}) for B ∈ 𝓑.
PX is a probability on (ℝ, 𝓑), i.e. (ℝ, 𝓑, PX) is a probability space. The distribution thus assigns to every set of numbers B the probability that the value of X lands in B.
The distribution tells you how the total probability of 1 is shared out among the possible values. For the sum of two dice, the value 7 gets six squares out of 36, i.e. 6/36, while 2 and 12 get just one each. The number of sixes N has a different distribution: 0 with probability 25/36, 1 with 10/36 and 2 with 1/36.
Once we know the distribution, the original outcomes ω no longer matter. Two completely different games can have variables with the same distribution — and for any calculation they are then indistinguishable.
PX(B) = P({ω ∈ Ω : X(ω) ∈ B})
- PX(B)
- the distribution — a probability directly on numbers; the thing we want to keep calculating with
- P
- the original probability — it can only measure events on Ω, so the new probability on ℝ “borrows” it
- {ω : X(ω) ∈ B}
- the preimage of the set B — all outcomes that the variable sends into B; this turns a question about numbers back into an event that P can measure
Definition — probability mass function
Let (Ω, 𝓕, P) be a probability space and X a discrete random variable (defined in the section Discrete and continuous random variables), i.e. there is an at most countable set H ⊆ ℝ with P(X ∈ H) = 1. The probability mass function of X is the function pX : ℝ → [0, 1],
pX(x) = P(X = x) = P({ω ∈ Ω : X(ω) = x}).
It determines the whole distribution: for every B ∈ 𝓑 we have P(X ∈ B) = ∑x ∈ B ∩ H pX(x) — we sum over the possible values that lie in B (the events {X = x} are mutually exclusive and there are at most countably many of them, so this follows from additivity).
Example — the distribution of the sum and of the number of sixes
The sum s = a + b comes from the pairs (a, s − a) with both numbers between 1 and 6. For s ≤ 7 there are s − 1 of them, for s ≥ 7 there are 13 − s; together
pS(s) = 6 − |s − 7|/36 for s = 2, 3, …, 12
pS(7) = 6/36, pS(4) = pS(10) = 3/36, ∑ = 1 + 2 + 3 + 4 + 5 + 6 + 5 + 4 + 3 + 2 + 1/36 = 36/36 = 1
The number of sixes N: no six means 5 options on each die, 5 · 5 = 25; exactly one six 2 · 5 = 10 (the six on the first or on the second die, the other one showing one of the 5 other numbers); two sixes 1. Check: 25 + 10 + 1 = 36.
For a finite sample space, the distribution can be computed by simple enumeration:
def rozdeleni(X, omega):
# omega: list of equally likely outcomes, X: function outcome → number
pocty = {}
for w in omega:
pocty[X(w)] = pocty.get(X(w), 0) + 1
return {x: k / len(omega) for x, k in sorted(pocty.items())}
3. Cumulative distribution function
Definition — cumulative distribution function
Let (Ω, 𝓕, P) be a probability space and X : Ω → ℝ a random variable. The cumulative distribution function (CDF) of X is the function FX : ℝ → [0, 1],
FX(x) = P(X ≤ x) = P({ω ∈ Ω : X(ω) ≤ x}) for x ∈ ℝ.
The probability on the right-hand side exists, because by the definition of a random variable {X ≤ x} ∈ 𝓕. The value FX(x) is thus the probability that X comes out at most x. Where it is clear which variable we mean, we write just F.
At the point x, the distribution function answers: “how likely is it that the result is at most x?” For the sum of two dice, F(7) = 21/36 ≈ 0.583 — a sum of 7 or less covers 1 + 2 + 3 + 4 + 5 + 6 = 21 squares.
For the sum of two dice, the distribution function is a staircase. Between the values nothing changes — F(7.5) is still 21/36, because a sum of 7.5 cannot come up. At every possible value the function jumps by exactly the probability of that value: at seven by 6/36. The filled dot shows what the function is at the jump; the open circle shows where it was heading from the left.
For a discrete variable, the distribution function is summed up from the probability mass function:
FX(x) = ∑xi ∈ (−∞, x] pX(xi)
- FX(x)
- the probability that the result is at most x
- ∑xi ∈ (−∞, x]
- we go through all possible values xi ≤ x, from the smallest up to and including x — the events {X = xi} exclude one another, so their probabilities may be added; the closed bracket “]” (i.e. ≤, not <) is the reason why the step at xi already belongs to the value F(xi)
- pX(xi)
- the probability of a single value — the height of the step at the point xi
F(7) = p(2) + p(3) + … + p(7) = 1 + 2 + 3 + 4 + 5 + 6/36 = 21/36 ≈ 0.583
F(2.5) = p(2) = 1/36, F(1.9) = 0 (empty sum), F(12) = 36/36 = 1
Theorem — the distribution function determines the distribution
Let X and Y be random variables (they may even be defined on different probability spaces) with distributions PX, PY and distribution functions FX, FY. Then
(∀B ∈ 𝓑 : PX(B) = PY(B)) ⇔ (∀x ∈ ℝ : FX(x) = FY(x)).
So two random variables have the same distribution if and only if they have the same distribution function.
A single function of a single variable carries everything there is to know about a distribution. It is called “cumulative” because it accumulates probability from left to right — it describes how probability is distributed along the number line.
4. Properties of the cumulative distribution function
Theorem — properties of the distribution function
Let X be a random variable and F = FX : ℝ → [0, 1] its distribution function. Then
- F is non-decreasing: ∀x, y ∈ ℝ : x ≤ y ⇒ F(x) ≤ F(y);
- limx→−∞ F(x) = 0 and limx→+∞ F(x) = 1;
- F is right-continuous: ∀x ∈ ℝ : limy→x⁺ F(y) = F(x).
Conversely: if G : ℝ → ℝ is any function with properties 1–3, then there is a probability space and a random variable X on it such that FX = G.
The staircase only goes up (the values that are “at most x” can only grow in number, never shrink), it starts at zero and ends at one (there is nothing on the far left, everything on the far right). Right-continuity is the filled dot at the top of each step: F(7) already includes the seven, because the definition uses ≤.
Theorem — probability of an interval
Let X be a random variable with distribution function F and a, b ∈ ℝ, a < b. Then
P(a < X ≤ b) = F(b) − F(a),
where {a < X ≤ b} = {ω ∈ Ω : a < X(ω) ≤ b}. The proof is below the breakdown of the formula.
Take “at most b”, subtract “at most a”, and you are left with “more than a but at most b”. A sum of 5, 6 or 7: F(7) − F(4) = 21/36 − 6/36 = 15/36 ≈ 0.417 (colours as in the formula below) — the orange segment on the right of the picture.
P(a < X ≤ b) = F(b) − F(a)
- P(a < X ≤ b)
- the probability of an interval — open on the left, closed on the right; for a discrete variable this matters
- F(b)
- everything up to and including b — the upper bound counts towards the interval, hence ≤
- F(a)
- we subtract everything up to a inclusive — that is why the lower bound is strict (<): the value a itself is not in the interval
Theorem — the probability of a single value is the height of the jump
Let X be a random variable with distribution function F and x ∈ ℝ. Denote by F(x⁻) = limy→x⁻ F(y) the limit from the left (it exists, because F is non-decreasing and bounded). Then F(x⁻) = P(X < x) and
P(X = x) = F(x) − F(x⁻).
Proof. For y < x we have F(x) − F(y) = P(y < X ≤ x); as y increases towards x, the intervals shrink to the single point {x} and their probabilities decrease to P(X = x) (continuity of probability, which follows from countable additivity). ∎
P(S = 7) = F(7) − F(7⁻) = 21/36 − 15/36 = 6/36 (F(7⁻) = F(6) = 15/36)
P(4 ≤ S ≤ 7) = F(7) − F(4⁻) = 21/36 − 3/36 = 18/36 = 0.5 — p(4) = 3/36 more than P(4 < S ≤ 7)
5. Discrete and continuous random variables
Definition — discrete random variable
Let (Ω, 𝓕, P) be a probability space and X : Ω → ℝ a random variable. X is discrete if and only if there is an at most countable (finite or countable) set H = {x1, x2, …} ⊆ ℝ of pairwise distinct numbers such that
P(X ∈ H) = ∑i P(X = xi) = 1.
So a discrete variable takes, with probability 1, only values from some finite or countable list.
The values can be counted off one by one (even if the counting never ends): the sum of dice, the number of e-mails per hour, the word a language model writes next. The distribution function is a staircase.
Definition — continuous random variable
Let X be a random variable with distribution function FX : ℝ → [0, 1]. X is continuous if and only if FX is continuous at every point, i.e.
∀x ∈ ℝ : limy→x FX(y) = FX(x).
By the theorem on the height of the jump, P(X = x) = FX(x) − FX(x⁻) = 0 for every x ∈ ℝ. (Some textbooks call a variable “continuous” only if it has a density — the topic of the next part; such a variable is continuous in this sense as well.)
The values fill a whole interval: time, length, temperature. The distribution function has no jumps at all — and a jump at the point x would be exactly P(X = x). That is why every single value has probability zero, even though it can occur.
An example: a bus comes every 10 minutes and you arrive at the stop at a random moment. Your waiting time X is continuous and equally likely to be anywhere between 0 and 10 minutes, so F(x) = x/10 for 0 ≤ x ≤ 10. The probability that you wait at most 3 minutes is F(3) = 0.3; that you wait 3 to 5 minutes, F(5) − F(3) = 0.2. But the probability that you wait exactly 3 minutes — not even a billionth of a second longer — is 0. How to calculate with that, and what the density function shows, is the topic of the next part.
Definition — uniform distribution on an interval
Let a, b ∈ ℝ, a < b, and let X be a random variable with distribution function F. X has the uniform distribution on the interval [a, b] if and only if for every x ∈ ℝ
F(x) = 0 for x < a, F(x) = x − a/b − a for a ≤ x ≤ b, F(x) = 1 for x > b.
The probability that X lands in a subinterval of [a, b] is thus its length divided by the length of [a, b].
The probability of a stretch is proportional only to its length, not to where it lies: (x − a) is the length of the stretch from the start, (b − a) the length of the whole interval. The bus is the case a = 0, b = 10.
Example — why P(X = 3) is exactly zero
The event {X = 3} lies in every interval (3 − ε, 3], however small ε > 0 is. The probability of a subset cannot be larger:
0 ≤ P(X = 3) ≤ F(3) − F(3 − ε) = 0.3 − 3 − ε/10 = ε/10
ε = 0.1 → at most 0.01; ε = 0.001 → at most 0.0001; … hence P(X = 3) = 0
The only number that is ≥ 0 and at the same time smaller than every positive ε/10 is zero.
6. Empirical distribution function
Definition — empirical distribution function
Let n ∈ ℕ, n ≥ 1, and let x1, …, xn ∈ ℝ be measured values (they may repeat). For a finite set M, |M| denotes the number of its elements. The empirical distribution function of these values is the function F̂n : ℝ → [0, 1],
F̂n(x) = |{i ∈ {1, …, n} : xi ≤ x}|/n for x ∈ ℝ.
F̂n(x) is thus the share of measured values that are at most x.
We often do not know the true distribution function — all we have is data. The empirical distribution function is its estimate from the data: what share of the measured values is at most x. Every measurement adds a step of height 1/n.
The same thing can be written with an indicator 𝟙[condition], which is 1 when the condition holds and 0 when it does not — counting thus turns into adding up:
F̂n(x) = 1/n · ∑i=1n 𝟙[xi ≤ x]
- F̂n(x)
- an estimate of the distribution function from n measurements — the hat marks an estimate, not the true F
- 1/n
- every measurement gets the same weight; dividing by n turns a count into a share, so the estimate runs from 0 to 1 like the true F
- ∑i=1n
- we go through all measurements — none is left out or counted twice
- 𝟙[xi ≤ x]
- the vote of a single measurement: 1 if it came out “at most x”, otherwise 0 — the same question that F(x) = P(X ≤ x) asks
We simulated 10, 100 and 1,000 waits for the bus. The dashed line is the true distribution function x/10, the coloured staircases are the empirical functions from the data:
With ten measurements the estimate is off from the truth by as much as 0.268, with a hundred by 0.085, and with a thousand by just 0.025. That the empirical distribution function hugs the true one more and more closely as data accumulate is the statement of the Glivenko–Cantelli theorem — a mathematical guarantee that a distribution can be learned from data.
Example — ten waits and the largest deviation
The simulation gave (sorted, rounded to hundredths of a minute) 0.03; 2.81; 4.26; 5.27; 6.13; 6.27; 7.21; 9.68; 9.81; 9.95.
F̂10(5) = 1/10 · (1 + 1 + 1 + 0 + … + 0) = 0.3, in truth F(5) = 0.5 → difference 0.2
just below 9.68: F̂10 = 1/10 · 7 = 0.7, F(9.68) ≈ 0.968 → difference ≈ 0.268
(colours as in the formula above; the first line has ten terms 𝟙[xi ≤ 5])
Between 7.21 and 9.68 no measurement fell, so the staircase stays at 0.7 there while the true F keeps rising — which is why the deviation is largest exactly there.
The largest deviation does not have to be searched for at every point of the axis. The staircase changes only at the measured values and F grows between them, so it is enough to compare F at each sorted measurement with the step just above it and just below it:
def nejvetsi_odchylka(data, F):
x = sorted(data)
n = len(x)
d = 0
for i in range(n): # i = 0, 1, …, n − 1
d = max(d, (i + 1) / n - F(x[i]), # step at x[i]: F̂ = (i + 1)/n
F(x[i]) - i / n) # just below x[i]: F̂ = i/n
return d
Theorem — Glivenko–Cantelli and how fast the deviation shrinks
Let (Ω, 𝓕, P) be a probability space, F a distribution function and X1, X2, … : Ω → ℝ random variables that
- all have the distribution function F: FXi = F for every i ≥ 1;
- are independent: for every n ≥ 1 and all x1, …, xn ∈ ℝ we have P(X1 ≤ x1, …, Xn ≤ xn) = F(x1) · … · F(xn) (compare independent events in the part Conditional probability and Bayes’ theorem).
For n ≥ 1 and ω ∈ Ω let F̂n be the empirical distribution function of the values X1(ω), …, Xn(ω) and
Dn = supx ∈ ℝ |F̂n(x) − F(x)|.
Then P(limn→∞ Dn = 0) = 1, i.e. with probability 1, Dn → 0 as n → ∞.
How fast is told by the Dvoretzky–Kiefer–Wolfowitz inequality (1956) with the constant 2, proved by P. Massart (1990): under the same assumptions, for every n ≥ 1 and every ε > 0
P(Dn > ε) ≤ 2 exp(−2nε2).
Setting the right-hand side to 5% gives ε = √ln 2/0.05/2n: with probability at least 95%, the deviation is below 0.429 for 10 measurements, below 0.136 for 100 and below 0.043 for 1,000. Our 0.268, 0.085 and 0.025 fit within that. The bound shrinks like 1/√n — ten times more data reduces the error only about three times. Even in our simulation, √n · deviation is roughly the same every time: 0.85, 0.85 and 0.80.
7. Random variables in artificial intelligence
- Data are random variables. A customer’s age, the price of a flat, the brightness of a pixel — a machine learning model assumes that its training data are values of random variables with some unknown distribution, and tries to estimate that distribution (or part of it) from them.
- Generating random numbers from any distribution. What a computer is good at is mainly a uniform number U between 0 and 1. Take the smallest x for which F(x) ≥ U, and you get a value with distribution F. For U = 0.6 and the sum of dice: F(7) ≈ 0.583 is still too little, F(8) = 26/36 ≈ 0.722 is enough — the result is 8. This is also how a language model picks its next word.
- Quantiles and the median. The median is the value where F first reaches 0.5: for the sum of dice it is 7. When a server is said to have “95% of requests answered within 200 ms”, that means F(200 ms) ≥ 0.95.
- Generative models (diffusion models, VAEs) start from random noise — a vector of random variables with a known distribution — and learn to turn it into an image or text.
Quantiles and sampling from a distribution
Definition — quantile function
Let F : ℝ → [0, 1] be a distribution function (of some random variable). The quantile function (the generalised inverse of F) is the function F−1 : (0, 1) → ℝ,
F−1(u) = min {x ∈ ℝ : F(x) ≥ u} for u ∈ (0, 1).
The minimum exists: the set {x ∈ ℝ : F(x) ≥ u} is non-empty (because F(x) → 1 > u as x → +∞), bounded below (because F(x) → 0 < u as x → −∞), and thanks to the monotonicity and right-continuity of F it is an interval of the form [c, ∞), which contains its infimum c.
For u ∈ (0, 1), the value F−1(u) is the u-quantile of the distribution with distribution function F; F−1(0.5) is the median. A quantile is thus the smallest number for which the probability of “at most that much” is at least u.
The distribution function answers “what is the chance that the result is at most x?”, the quantile function the opposite question: “how far do I have to go to have a chance of at least u?”. Where F is increasing and continuous, it is an ordinary inverse function; on a staircase you take the first step that reaches u. The median of the sum: F(6) = 15/36 ≈ 0.417 is not enough, F(7) ≈ 0.583 is — the median is 7.
Theorem — inverse transform method
Let F : ℝ → [0, 1] be a distribution function, F−1 : (0, 1) → ℝ its quantile function and U : Ω → (0, 1) a random variable with the uniform distribution on [0, 1] (the values 0 and 1 have probability 0, so we may leave them out). Then X = F−1 ∘ U, i.e. X(ω) = F−1(U(ω)), is a random variable and
FX(x) = F(x) for every x ∈ ℝ.
Proof. The definition of the minimum and the monotonicity of F give F−1(u) ≤ x ⇔ u ≤ F(x). Hence P(X ≤ x) = P(U ≤ F(x)) = F(x), because for a uniform U, P(U ≤ t) = t. ∎
def vzorek(hodnoty, F, u):
# hodnoty in ascending order, F(x) = P(X ≤ x), u = uniform random number from (0, 1)
for x in hodnoty:
if F(x) >= u: # the first step that reaches u
return x
sum of dice, u = 0.6: F(7) = 21/36 ≈ 0.583 < 0.6, F(8) = 26/36 ≈ 0.722 ≥ 0.6 → 8
waiting for the bus: u = F(x) = x/10 ⇒ F−1(u) = 10u, u = 0.6 → 6 minutes; the median is 5 minutes
8. Summary
- A random variable is a function that assigns a number to the outcome of an experiment.
- The distribution tells you how probability is shared out among the values; the distribution function F(x) = P(X ≤ x) determines it completely.
- F is non-decreasing, goes from 0 to 1, is right-continuous, and P(a < X ≤ b) = F(b) − F(a).
- A discrete variable has a staircase F; a continuous one has F without jumps, and every single value has probability 0.
- The empirical distribution function estimates F from data and gets closer to it as the number of measurements grows.
Do you see it differently? Write to support@coden-app.com.