In the last two lessons we worked with events described in words: "the receipt is paid by card", "the order arrives late". But data analysis gains power when chance is translated into numbers: instead of asking about one specific event, we describe in one go the probabilities of all the possible values of an uncertain quantity. That object is called a random variable, and its "identity card" is its probability distribution. In this lesson you will learn to distinguish discrete from continuous random variables, to read and build the distribution table of a discrete one, to compute its expected value and variance (with a direct business application: deciding whether a Club Nova promotion is profitable), and to understand what the density function and the distribution function are in the continuous case — no integrals, just the intuition of the histogram. We close with the idea that gives Module 4 its name: distribution models as reusable templates.
Contents
- What a random variable is; discrete vs continuous
- The probability mass function and the distribution table
- Expected value: the long-run average
- Variance and standard deviation of a random variable
- Expected value as a decision criterion: the Club Nova promotion
- Continuous variables: probability density function and cumulative distribution function
- Distribution models: templates for chance
What a random variable is; discrete vs continuous
A random variable (r.v.) is a rule that assigns a number to the outcome of a random experiment. It is denoted with capital letters (\( X, Y, Z \)) and its specific values with lowercase letters (\( x, y, z \)). Before the experiment is carried out, \( X \) is uncertain; afterwards, it takes a specific value.
| NovaMarket experiment | Random variable | Possible values | Type |
|---|---|---|---|
| A customer goes through checkout | \( X \) = receipt amount (€) | any value > 0 | Continuous |
| A receipt is observed | \( Y \) = 1 if paid by card, 0 if not | {0, 1} | Discrete |
| One hour on the website | \( N \) = no. of orders received | {0, 1, 2, …} | Discrete |
| An order is shipped | \( T \) = hours until delivery | any value ≥ 0 | Continuous |
| A member receives a coupon | \( C \) = 1 if they redeem it, 0 if not | {0, 1} | Discrete |
The classification mirrors the data types from Module 1, now with probabilities attached:
- Discrete: its possible values can be listed (finite or countably infinite). It usually arises from counting.
- Continuous: it can take any value within an interval. It usually arises from measuring (amounts, times, weights).
The distinction matters because the mathematical tools differ: a discrete variable is assigned probability value by value; a continuous one, over intervals.
The probability mass function and the distribution table
For a discrete r.v. \( X \), the probability mass function (pmf) assigns each possible value its probability:
\[ p(x) = P(X = x) \]
It must satisfy two conditions (a direct inheritance from Kolmogorov's axioms): \( p(x) \geq 0 \) for every \( x \), and \( \sum_x p(x) = 1 \). In practice it is presented as a distribution table.
NovaMarket example: reusable bags. At checkout, reusable bags are offered for €1. Analyzing millions of receipts, Marta's team estimates the probabilities of the number of bags \( X \) that a customer buys:
| \( x \) (no. of bags) | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| \( p(x) = P(X = x) \) | 0.60 | 0.25 | 0.10 | 0.05 |
Check: \( 0.60 + 0.25 + 0.10 + 0.05 = 1 \). ✔ Note the parallel with Module 2: this table is like a relative frequency table, except that it describes probabilities of what will happen, not frequencies of what has already been observed. The frequentist approach from lesson 03-01 is the bridge between the two.
From the table you can extract the probability of any event about \( X \) by adding the values that make it up:
- \( P(X \geq 1) = 0.25 + 0.10 + 0.05 = 0.40 \) — or better, via the complement: \( 1 - P(X=0) = 1 - 0.60 = 0.40 \).
- \( P(1 \leq X \leq 2) = 0.25 + 0.10 = 0.35 \).
Expected value: the long-run average
The expected value of a discrete r.v. is the mean of its possible values weighted by their probabilities:
\[ E(X) = \mu = \sum_x x \cdot p(x) \]
It is the natural extension of Module 2's weighted mean, with probabilities as the weights. Key interpretation: it is the long-run average value, what we would obtain on average if the experiment were repeated a great many times. It is not "the most likely value", and it need not even be a possible value.
With the bags:
\[ E(X) = 0 \times 0.60 + 1 \times 0.25 + 2 \times 0.10 + 3 \times 0.05 = 0 + 0.25 + 0.20 + 0.15 = 0.60 \text{ bags} \]
No customer buys 0.6 bags, but the figure is gold for operations: with about 2,000 customers a day at Madrid-Centro, we can expect to sell around \( 2{,}000 \times 0.60 = 1{,}200 \) bags per day — the basis for the replenishment order.
Two useful properties (stated without proof): if \( a \) and \( b \) are constants, \( E(aX + b) = a,E(X) + b \). For example, if each bag yields a €0.40 margin, the margin per customer is the r.v. \( 0.40 \cdot X \), with expected value \( 0.40 \times 0.60 = 0.24 \) euros.
Variance and standard deviation of a random variable
Just as in Module 2 the mean needed the standard deviation, the expected value needs a measure of dispersion. The variance of an r.v. measures how far its values stray from the expected value, on a probability-weighted average:
\[ \operatorname{Var}(X) = \sigma^2 = \sum_x (x - \mu)^2 , p(x) \qquad \sigma = \sqrt{\operatorname{Var}(X)} \]
Step-by-step calculation with the bags (\( \mu = 0.60 \)):
| \( x \) | \( p(x) \) | \( x - \mu \) | \( (x-\mu)^2 \) | \( (x-\mu)^2 , p(x) \) |
|---|---|---|---|---|
| 0 | 0.60 | −0.60 | 0.36 | 0.2160 |
| 1 | 0.25 | 0.40 | 0.16 | 0.0400 |
| 2 | 0.10 | 1.40 | 1.96 | 0.1960 |
| 3 | 0.05 | 2.40 | 5.76 | 0.2880 |
| Sum: | 0.7400 |
\[ \operatorname{Var}(X) = 0.74 \qquad \sigma = \sqrt{0.74} \approx 0.86 \text{ bags} \]
Reading: the number of bags per customer typically fluctuates by ±0.86 around 0.60. Notice that here we use \( \sigma \) (a parameter of the model), not \( s \): we are not estimating from a sample by dividing by \( n-1 \), we are computing the distribution's theoretical dispersion. The sample \( s \) from Module 2 is the empirical estimate of this theoretical \( \sigma \).
Expected value as a decision criterion: the Club Nova promotion
Here the theory turns into money. Let's pick up the thread of the retention exercise from the previous lesson, now with an offensive campaign: Marta is weighing sending a €5 discount coupon on purchases over €40 to Club Nova's 380,000 members. Figures estimated by the team (from pilot campaigns):
- Issuing and communication cost per coupon sent: €0.30.
- Probability that a member redeems the coupon: 0.18.
- If they redeem, the associated purchase yields an average gross margin of €7.50 (already net of the €5 coupon); an estimated 60% of those redemptions are incremental sales (they would not have happened without the coupon), while the remaining 40% would have happened anyway, so for them the coupon eats into margin: in those cases the net effect is −€2.10.
Define \( G \) = net gain per coupon sent. Its distribution table (applying the previous lesson's multiplication rule to the redemption branches):
| Scenario | Probability | \( g \) (€) |
|---|---|---|
| Does not redeem | 0.82 | −0.30 |
| Redeems, incremental sale | \( 0.18 \times 0.60 = 0.108 \) | \( 7.50 - 0.30 = 7.20 \) |
| Redeems, sale that would happen anyway | \( 0.18 \times 0.40 = 0.072 \) | \( -2.10 - 0.30 = -2.40 \) |
Check: \( 0.82 + 0.108 + 0.072 = 1 \). ✔ Expected value:
\[ E(G) = (-0.30)(0.82) + (7.20)(0.108) + (-2.40)(0.072) = -0.246 + 0.7776 - 0.1728 \approx \text{€}0.36 \]
Each coupon sent is worth, on average, about +€0.36. Across 380,000 members, the campaign's expected result is \( 380{,}000 \times 0.36 \approx 136{,}800 \) euros: go ahead. Three analyst's observations:
- Most coupons (82%) lose money individually; the campaign is profitable because the incremental redemptions more than make up for it. Deciding based on the most likely case instead of the expected value would have killed a profitable campaign.
- The expected value is reliable here because it will be applied many times (380,000 mailings): the law of large numbers guarantees that the actual result will land close to the expected one. For a one-off, unrepeatable decision, the expected value is still a useful guide, but dispersion and risk tolerance weigh more.
- The conclusion is sensitive to the estimates (the 0.18 and the 60% incremental come from pilots, that is, from samples). How much confidence those estimates deserve is exactly the subject of Module 5.
Continuous variables: probability density function and cumulative distribution function
For a continuous r.v. such as \( T \) = "hours until an order is delivered", asking for \( P(T = 25.5) \) is not usefully meaningful: among infinitely many possible values with unlimited decimals, the probability of any exact value is 0. With continuous variables you always ask about intervals: \( P(T < 48) \), \( P(24 \leq T \leq 36) \).
The tool is the probability density function \( f(x) \): a curve such that the probability of an interval is the area under the curve over that interval. Intuition from Module 2: picture the histogram of delivery times with ever-narrower bars (as we accumulate more and more orders); the silhouette that histogram tends towards is the density. Properties:
- \( f(x) \geq 0 \) (the curve never dips below the axis).
- The total area under the curve is 1 (the certain event).
- \( f(x) \) is not a probability: it can exceed 1 over narrow regions; only areas are probabilities.
Its companion is the cumulative distribution function (CDF):
\[ F(x) = P(X \leq x) \]
which accumulates the area from the left up to \( x \). It is the theoretical version of Module 2's cumulative percentages and percentiles, and it also exists for discrete variables (where it rises in jumps). With it, any interval is solved by subtracting:
\[ P(a < X \leq b) = F(b) - F(a) \]
NovaMarket example. From the delivery analysis we know that the median is 25.5 h and that the SLA requires 90% in under 48 h. In CDF language: \( F(25.5) = 0.50 \) (the median is the point that accumulates 50%) and the target is \( F(48) \geq 0.90 \). If, in addition, \( F(24) = 0.45 \), then:
\[ P(24 < T \leq 48) = F(48) - F(24) = 0.90 - 0.45 = 0.45 \]
45% of orders are delivered between 24 and 48 hours. Notice that we are working with probabilities of \( T \) without knowing the formula of its density: just by reading the CDF. In Module 4, when the density has a known shape (the normal bell curve), \( F \) will come tabulated and this subtraction game will be our daily routine.
| Discrete r.v. | Continuous r.v. | |
|---|---|---|
| Arises from… | counting | measuring |
| Point probability \( P(X=x) \) | \( p(x) \), can be > 0 | always 0 |
| Object that spreads the probability | pmf \( p(x) \) (table) | density \( f(x) \) (curve; areas = probabilities) |
| \( P(X \leq x) \) | sum of \( p \) up to \( x \) | accumulated area up to \( x \) |
| Expected value | \( \sum x , p(x) \) | weighted area under the curve (same idea, with an integral) |
Distribution models: templates for chance
We built the bags table empirically, value by value. But many chance situations repeat identical structural patterns, even when the numbers change:
- "I repeat an experiment with two outcomes \( n \) times (redeems/doesn't redeem, card/no card) and count the successes" — whether with coupons, payments or deliveries within the SLA.
- "I count how many events occur in a time interval (orders per hour, complaints per day)".
- "I measure a quantity that results from adding up many small independent effects (a store's daily sales)".
For these patterns, statistics offers distribution models: families of distributions with a known formula, governed by a few parameters that are fitted to each specific case. Instead of estimating a whole table from data, it is enough to identify the pattern and set the parameters (for example, \( n = 380{,}000 \) mailings and redemption probability \( \pi = 0.18 \)), and the model hands you all the probabilities, the expected value and the variance for free. They are reusable, battle-tested templates: the statistical equivalent of not redesigning the wheel for every analysis.
The three patterns on the list have names of their own — binomial, Poisson and normal — and they are exactly the content of Module 4. Module 1's distinction between parameter and statistic culminates here: the parameters of these models (\( \mu, \sigma, \pi \)) are the ones we will later learn, in Module 5, to estimate from samples.
Common Mistakes and Tips
- Confusing the expected value with "the most likely value". \( E(X) = 0.6 \) bags, yet the most likely value is 0. The expected value is a long-run average; it can be a value impossible to observe in any individual case.
- Forgetting to check that the probabilities add up to 1 before computing anything from a distribution table. It is the cheapest check and the one that catches the most errors (including badly multiplied tree branches).
- Deducting the cost only in some scenarios. In the promotion, the €0.30 is paid always, whether the member redeems or not. Misallocating fixed costs across scenarios is the most common accounting error in payoff tables.
- Reading the density as a probability. \( f(x) = 1.3 \) does not mean "probability 130%"; a continuous variable's probabilities are areas, and \( P(X = x) = 0 \) for any exact value.
- Being careless with "≤" and "<". For continuous variables it makes no difference (\( P(X \leq 48) = P(X < 48) \) because the exact point weighs 0), but for discrete ones it does: \( P(X < 2) = P(X \leq 1) \neq P(X \leq 2) \).
- Deciding on the expected value alone, ignoring dispersion. Two campaigns with the same \( E(G) \) can carry very different risks; always report the standard deviation alongside the expected value, just as in Module 2 we reported the mean together with \( s \).
Exercises
Exercise 1. At the express checkout in Valencia-Ruzafa, the number \( X \) of items rejected by the scanner on a receipt has this distribution: \( P(X=0) = 0.70 \), \( P(X=1) = 0.20 \), \( P(X=2) = 0.08 \), \( P(X=3) = a \). (a) Find \( a \). (b) Compute \( P(X \geq 1) \) and \( P(X < 2) \). (c) Compute \( E(X) \), \( \operatorname{Var}(X) \) and \( \sigma \).
Exercise 2. NovaMarket is studying a delivery guarantee for online orders priced at €1.50: if the order takes more than 48 h, the customer receives a €10 voucher. With current data, the probability of exceeding 48 h is 0.101 (computed in the previous lesson). Let \( G \) be NovaMarket's gain per guarantee sold. (a) Build the distribution table of \( G \). (b) Compute \( E(G) \) and interpret the result. (c) What delay probability would make the guarantee stop being profitable?
Exercise 3. For the delivery time \( T \) (in hours) we know that \( F(11) = 0.10 \), \( F(25.5) = 0.50 \), \( F(36) = 0.75 \) and \( F(48) = 0.899 \). (a) Compute \( P(11 < T \leq 36) \) and interpret what it has to do with the 11-hour IQR… does it square with what you knew from Module 2? (b) Compute \( P(T > 48) \). Is NovaMarket meeting its SLA? (c) Why don't we ask for \( P(T = 25.5) \)?
Solutions
Solution 1. (a) The probabilities must add up to 1: \( a = 1 - 0.70 - 0.20 - 0.08 = 0.02 \). (b) \( P(X \geq 1) = 1 - 0.70 = 0.30 \); \( P(X < 2) = P(X \leq 1) = 0.70 + 0.20 = 0.90 \). (c) \( E(X) = 0(0.70) + 1(0.20) + 2(0.08) + 3(0.02) = 0.42 \). Variance: \( (0-0.42)^2(0.70) + (1-0.42)^2(0.20) + (2-0.42)^2(0.08) + (3-0.42)^2(0.02) = 0.1235 + 0.0673 + 0.1997 + 0.1332 \approx 0.524 \); \( \sigma \approx 0.72 \) items. Common mistake: in (b), treating \( P(X<2) \) as \( P(X \leq 2) \) — with discrete variables the boundary matters.
Solution 2. (a) Two scenarios: the order arrives on time (probability 0.899): NovaMarket collects €1.50; it arrives late (0.101): NovaMarket collects €1.50 but pays out the voucher, a gain of \( 1.50 - 10 = -8.50 \) euros. Table: \( P(G = 1.50) = 0.899 \), \( P(G = -8.50) = 0.101 \). (b) \( E(G) = 1.50 \times 0.899 + (-8.50) \times 0.101 = 1.3485 - 0.8585 = 0.49 \) euros: each guarantee sold yields about 49 cents on average; at scale, the product is profitable (although — a business nuance — a €10 voucher is not a pure €10 cost if it gets spent on products with margin; the prudent calculation treats it as a full cost). (c) We look for \( p \) such that \( E(G) = 1.50 - 10p = 0 \Rightarrow p = 0.15 \). If delays exceeded 15%, the guarantee would lose money: the product's profitability depends on keeping the logistics operation in shape. Common mistake: writing the bad scenario's gain as −€10, forgetting that the €1.50 is collected in every case.
Solution 3. (a) \( P(11 < T \leq 36) = F(36) - F(11) = 0.75 - 0.10 = 0.65 \). Module 2's IQR ran from the 25th to the 75th percentile; this stretch runs from the 10th to the 75th, which is why it accumulates 65% rather than 50%: it squares, but it is not the IQR (comparing specific percentiles avoids confusion). (b) \( P(T > 48) = 1 - F(48) = 1 - 0.899 = 0.101 \): 89.9% arrive within the deadline, one tenth of a point below the 90% SLA — consistent with the previous lesson's carrier analysis, and an argument for renegotiating with RápidoSur. (c) Because \( T \) is continuous: the probability of an exact value is 0; the informative statement is \( F(25.5) = 0.50 \), which identifies 25.5 h as the median. Feedback: if you answered 0.899 in (b), reread the question — it asked for the right tail; sketching the curve and shading the requested area before calculating prevents this slip.
Conclusion
We have made the leap from events to numbers: a random variable condenses an experiment into a quantity, and its probability distribution — table and pmf for discrete variables, density and CDF for continuous ones — contains everything that can be known about it before observing the outcome. The expected value \( E(X) \) gives us the long-run average (and with it, the expected-value criterion that turned the Club Nova promotion into a calculated +€136,800 decision), and the variance \( \sigma^2 \) measures the risk around that average, the theoretical mirror of Module 2's sample \( s \).
And the decisive idea has been planted: many chance phenomena follow repeated patterns that do not need to be modeled from scratch, because templates with a name of their own already exist. In Module 4 we will meet them one by one, starting with the most natural one for NovaMarket: counting successes in \( n \) independent trials — how many of the 380,000 coupons get redeemed, how many of the next 20 receipts are paid by card. That is the Binomial Distribution, the first template in our toolbox.
Statistics Course
Module 1: Introduction to Statistics
Module 2: Describing Data
- Measures of Central Tendency
- Measures of Dispersion
- Measures of Position and Outliers
- Graphical Representation of Data
Module 3: Probability
Module 4: Probability Distributions
- The Binomial Distribution
- The Normal Distribution
- Other Important Distributions
- The Central Limit Theorem
Module 5: Statistical Inference
Module 6: Data Analysis
- Correlation Analysis
- Regression Analysis
- Analysis of Variance (ANOVA)
- Categorical Data Analysis: Chi-Square
