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.
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
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.