core20 min studyLesson 18 in Mathematics

Random variables and distributions

Turn outcomes into quantities, distinguish mass from density, and calculate the mean and variability of a count.

On this page

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 n!=n(n−1)⋯1n!=n(n-1)\cdots1, with 0!=10!=1. For four trials and two successes, the coefficient is 4!/(2!2!)=64!/(2!2!)=6. At p=0.25p=0.25, the two-success probability is therefore 6(0.25)2(0.75)2=0.21093756(0.25)^2(0.75)^2=0.2109375. The factor six groups all successful-position arrangements; omit it when the question specifies just one exact ordered sequence.

P(X=k)=(nk)pk(1−p)n−k,(nk)=n!k!(n−k)!,k=0,1,…,nP(X=k)=\binom nk p^k(1-p)^{n-k},\qquad \binom nk=\frac{n!}{k!(n-k)!},\quad k=0,1,\ldots,n
This is the binomial count model: n fixed independent trials, each with the same success probability p between zero and one. Outcomes at the endpoint probabilities are interpreted directly.↔ Scroll wide equations horizontally.

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.

P(a≤X≤b)=∫abfX(x) dx,fX(x)≥0,∫−∞∞fX(x) dx=1P(a\le X\le b)=\int_a^b f_X(x)\,dx,\qquad f_X(x)\ge0,\quad\int_{-\infty}^{\infty}f_X(x)\,dx=1
These formulas assume X has an ordinary probability density. They do not cover a discrete or mixed distribution by themselves.↔ Scroll wide equations horizontally.

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 npnp and variance is np(1−p)np(1-p). 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.

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.

  1. Let X∼Binomial⁡(4,0.25)X\sim\operatorname{Binomial}(4,0.25). It is easier to calculate the complement: all four failures have probability 0.754=0.316406250.75^4=0.31640625.

  2. Subtract from one: P(X≥1)=1−0.31640625=0.68359375P(X\ge1)=1-0.31640625=0.68359375. Independence justifies multiplying the four failure probabilities.

  3. Compute the mean np=4(0.25)=1np=4(0.25)=1 and variance np(1−p)=4(0.25)(0.75)=0.75np(1-p)=4(0.25)(0.75)=0.75. The standard deviation is 0.75≈0.866\sqrt{0.75}\approx0.866.

The result

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.

Explore the model

Interactive lab

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.

Explore an exact binomial distributionThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

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.

Check your understanding

Can a continuous probability density take the value 2?

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 0(0.5)+2(0.5)=10(0.5)+2(0.5)=1. Its variance is 0.5(0−1)2+0.5(2−1)2=10.5(0-1)^2+0.5(2-1)^2=1. Two independent trials would instead have variance 2(0.5)(0.5)=0.52(0.5)(0.5)=0.5. Equal marginal success probabilities preserve the mean but do not determine the variability of the sum.

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.