Interactive statistics
Module 2: Probability
Progresscompleted 0 / 63

Random variables, expectation and variance

So far we talked about probabilities of events. But in data we usually care about NUMBERS: how many items, how much money, how long. A random variable is exactly that โ€” "a number that depends on chance". It has two main descriptors: the expectation (where its center is) and the variance (how widely it wanders around that center). These two concepts are the foundation everything that follows is built on.

12345E[X] = 3.00
E[X] = 3.00 (balance point)Var[X] = 1.20ฯƒ = 1.10
Outcome probabilities (drag the weights):

E[X] is the "center of gravity" of the values weighted by probability. Var[X] = E[(Xโˆ’E[X])ยฒ] is the mean squared deviation. For a sum of INDEPENDENT variables both E and Var add up โ€” which yields ฯƒ/โˆšn for the mean and the bell of the CLT.

A random variable assigns a number to every random outcome. A die roll โ†’ the number shown; a user โ†’ how much they spent; a request โ†’ how many milliseconds the server took. Before you is a variable with five outcomes; bar height is the probability of each value. Drag the weights โ€” the distribution changes.

Why an analyst needs this

Expectation and variance are an analyst's working language. "How much will a user bring on average" is E[X]. "How unpredictable is revenue" is ฯƒ. Sample-size, confidence-interval and power calculations are the arithmetic of estimator variances.

The variance-addition rule explains why averaging calms noise: add n independent observations, divide by n โ€” the mean's variance comes out n times smaller than a single observation's. Hence the ฯƒ/โˆšn that will chase us through the whole course.

Where it shows up

A stock portfolio: expected return is E[X], risk is ฯƒ. Diversification works precisely through variance addition: uncorrelated assets damp the total spread.

Reliability engineering and queueing: the expected number of events and its variance (Poisson) let you size capacity and price the risk of overload.

Definitions

Random variable
a number that takes one value or another depending on the random outcome.
Expectation E[X]E[X]=โˆ‘xiโ€‰piE[X] = \sum x_i\, p_i
the variable's average over a long series of repeats: multiply each value xแตข by its probability pแตข and sum. It is the center of the distribution.
Variance Var[X]Var(X)=E[(Xโˆ’E[X])2]\mathrm{Var}(X) = E\big[(X - E[X])^2\big]
the average squared deviation from the expectation; ฯƒ = โˆšVar is the spread in original units.
Adding variancesVar(X+Y)=Var(X)+Var(Y)\mathrm{Var}(X+Y) = \mathrm{Var}(X) + \mathrm{Var}(Y)
the variances of independent variables add up. The foundation of ฯƒ/โˆšn, the CLT and ANOVA.
Independence
the outcome of one variable does not affect the distribution of the other. Without it, variance addition breaks.
Deep dive: the math and the mechanism (optional)

Where ฯƒ/โˆšn comes from โ€” the precision of the mean. Add n independent observations: their variances add, so the sum has variance nยทฯƒยฒ. The mean is that same sum, divided by n. And when you divide a quantity by a constant c, its variance is divided by cยฒ (the spread shrinks faster than the value itself). So the variance of the mean = nยทฯƒยฒ / nยฒ = ฯƒยฒ/n, and the standard deviation of the mean (called the standard error) = ฯƒ/โˆšn. That is why a larger sample gives a more precise mean โ€” and why precision grows not like n but like โˆšn.

An important asymmetry between the two rules. Expectation is linear ALWAYS: E[aX + b] = aยทE[X] + b, and E[X + Y] = E[X] + E[Y] even for dependent quantities. Variances, however, add ONLY for independent ones. In general Var(X + Y) = Var(X) + Var(Y) + 2ยทCov(X, Y), where Cov(X, Y) is the covariance, a measure of how they deviate together. It is exactly this covariance that variance-reduction methods exploit: pick an auxiliary quantity closely tied to the metric, and the surplus spread is subtracted from the variance of the estimate.

Next โ†’
Breakdowns like this live in the channel

Data analytics in plain words: how to count metrics, how not to fool yourself in an A/B test, what gets asked in interviews and how this site gets built. The channel is in Russian.

Open the Telegram channel