Random variables and distributions
Turn outcomes into quantities, distinguish mass from density, and calculate the mean and variability of a count.
On this page
The question for today
What you’ll understand
- Explain a random variable as a numerical function of an outcome.
- Distinguish a probability mass function from a density.
- Calculate binomial probabilities, expectation, and variance with their assumptions.
A random variable assigns a number to each outcome: failed-request counts, waiting times, or measurements. Its distribution assigns probabilities to those numerical values. Separating outcomes from quantities lets us compare systems using a mean and spread. Those summaries remain incomplete: two distributions can share both while having very different tails.
A distribution describes numerical outcomes
For a discrete random variable, a probability mass function assigns probability directly to each possible value. The masses are nonnegative and sum to one. A Bernoulli variable is one for success and zero for failure. If we count successes in a fixed number of independent Bernoulli trials with the same success probability, the count has a binomial distribution. Changing these assumptions can change the distribution even if the average success rate stays the same.
The binomial coefficient counts which trial positions contain the successes. Factorial notation means , with . For four trials and two successes, the coefficient is . At , the two-success probability is therefore . The factor six groups all successful-position arrangements; omit it when the question specifies just one exact ordered sequence.
A density is not a point probability
A continuous density assigns probability through area over an interval, not through its height at a single point. Its integral over the full line is one, but its height can exceed one without violating probability rules. For example, a uniform density over an interval of length one half has height two. The units of density are inverse units of the measured quantity, so multiplying by an interval width produces a dimensionless probability.
For an absolutely continuous variable, an individual exact value has probability zero even though some value is observed. Practical measurements have finite resolution, so intervals are usually the operational events. A normal density is useful for many additive-noise models, but it is not a universal law of data. Heavy tails, bounded quantities, multimodality, and dependent observations all require attention before a familiar bell curve is selected.
Summaries are useful but incomplete
Expectation is a probability-weighted average, not necessarily a likely or even possible outcome. A binomial count can have a noninteger mean despite taking only integer values. Variance measures the expected squared deviation from that mean; standard deviation returns to the original units. For independent Bernoulli trials the binomial mean is and variance is . Those compact formulas encode the independence assumption.
Expectation is linear even when variables are dependent. Variance needs covariance terms unless dependence vanishes in the relevant way: strongly correlated failures can produce much larger count variability than the binomial model predicts. In infrastructure engineering, the tail probability of a bad burst can matter more than average failures. In machine learning, an average loss similarly cannot reveal every subgroup error. Read summaries as answers to specific questions rather than complete portraits.
Work it through
Count successes in four independent attempts
Each of four independent attempts succeeds with probability 0.25. Find the probability of at least one success, the expected count, and its variance.
Let . It is easier to calculate the complement: all four failures have probability .
Subtract from one: . Independence justifies multiplying the four failure probabilities.
Compute the mean and variance . The standard deviation is .
At least one success occurs with probability about 68.36%. An expected count of one does not mean every four-attempt run contains exactly one success.
The living notebook
Explore the model
Interactive lab · probability
Explore an exact binomial distribution
Set p=0.25 and n=4 to check the worked example's probability bars, mean np, and variance np(1−p). Then keep n fixed while moving p toward either endpoint. The displayed bars are exact model probabilities, not a histogram of resampled outcomes. Playback changes the illustration without supplying new experimental data.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forChanging p shifts both the expected count and its spread; the full bars contain more information than either summary.
Pause & reason
Check your understanding
Your turn
Try it yourself
Two Bernoulli variables each have success probability 0.5, but they are always identical. Find the mean and variance of their sum and compare with two independent trials.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The dependent sum is either zero or two, each with probability one half.
Compare with the solution
The mean is . Its variance is . Two independent trials would instead have variance . Equal marginal success probabilities preserve the mean but do not determine the variability of the sum.
Keep the idea
Take it with you
- A random variable assigns numbers; its distribution assigns probabilities to those numbers.
- Discrete masses are point probabilities, while continuous densities require integration.
- Means are linear, but dependence changes variance and tail behavior.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.