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.
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.
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)
ΠΡΠΊΡΠ΄Π° Π±Π΅ΡΡΡΡΡ Ο/βn β ΡΠΎΡΠ½ΠΎΡΡΡ ΡΡΠ΅Π΄Π½Π΅Π³ΠΎ. Π‘Π»ΠΎΠΆΠΈΠΌ n Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΡΡ Π½Π°Π±Π»ΡΠ΄Π΅Π½ΠΈΠΉ: ΠΈΡ Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΠΈ ΡΠΊΠ»Π°Π΄ΡΠ²Π°ΡΡΡΡ, ΠΏΠΎΡΡΠΎΠΌΡ Ρ ΡΡΠΌΠΌΡ Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΡ ΡΠ°Π²Π½Π° nΒ·ΟΒ². Π‘ΡΠ΅Π΄Π½Π΅Π΅ β ΡΡΠΎ ΡΠ° ΠΆΠ΅ ΡΡΠΌΠΌΠ°, Π½ΠΎ Π΄Π΅Π»ΡΠ½Π½Π°Ρ Π½Π° n. Π ΠΏΡΠΈ Π΄Π΅Π»Π΅Π½ΠΈΠΈ Π²Π΅Π»ΠΈΡΠΈΠ½Ρ Π½Π° ΠΊΠΎΠ½ΡΡΠ°Π½ΡΡ c Π΅Ρ Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΡ Π΄Π΅Π»ΠΈΡΡΡ Π½Π° cΒ² (ΡΠ°Π·Π±ΡΠΎΡ ΡΠΆΠΈΠΌΠ°Π΅ΡΡΡ ΡΠΈΠ»ΡΠ½Π΅Π΅ ΡΠ°ΠΌΠΎΠ³ΠΎ Π·Π½Π°ΡΠ΅Π½ΠΈΡ). ΠΠ½Π°ΡΠΈΡ Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΡ ΡΡΠ΅Π΄Π½Π΅Π³ΠΎ = nΒ·ΟΒ² / nΒ² = ΟΒ²/n, Π° ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎΠ΅ ΠΎΡΠΊΠ»ΠΎΠ½Π΅Π½ΠΈΠ΅ ΡΡΠ΅Π΄Π½Π΅Π³ΠΎ (Π΅Π³ΠΎ Π½Π°Π·ΡΠ²Π°ΡΡ ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎΠΉ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ) = Ο/βn. ΠΠΎΡ ΠΏΠΎΡΠ΅ΠΌΡ ΡΠ΅ΠΌ Π±ΠΎΠ»ΡΡΠ΅ Π²ΡΠ±ΠΎΡΠΊΠ°, ΡΠ΅ΠΌ ΡΠΎΡΠ½Π΅Π΅ ΡΡΠ΅Π΄Π½Π΅Π΅ β ΠΈ ΠΏΠΎΡΠ΅ΠΌΡ ΡΠΎΡΠ½ΠΎΡΡΡ ΡΠ°ΡΡΡΡ Π½Π΅ ΠΊΠ°ΠΊ n, Π° ΠΊΠ°ΠΊ βn.
ΠΠ°ΠΆΠ½Π°Ρ Π°ΡΠΈΠΌΠΌΠ΅ΡΡΠΈΡ Π΄Π²ΡΡ ΠΏΡΠ°Π²ΠΈΠ». ΠΠ°ΡΠ΅ΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠ΅ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΠ΅ Π»ΠΈΠ½Π΅ΠΉΠ½ΠΎ ΠΠ‘ΠΠΠΠ: E[aX + b] = aΒ·E[X] + b, ΠΈ E[X + Y] = E[X] + E[Y] Π΄Π°ΠΆΠ΅ Π΄Π»Ρ Π·Π°Π²ΠΈΡΠΈΠΌΡΡ Π²Π΅Π»ΠΈΡΠΈΠ½. Π Π²ΠΎΡ Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΠΈ ΡΠΊΠ»Π°Π΄ΡΠ²Π°ΡΡΡΡ Π’ΠΠΠ¬ΠΠ Ρ Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΡΡ Π²Π΅Π»ΠΈΡΠΈΠ½. Π ΠΎΠ±ΡΠ΅ΠΌ ΡΠ»ΡΡΠ°Π΅ Var(X + Y) = Var(X) + Var(Y) + 2Β·Cov(X, Y), Π³Π΄Π΅ Cov(X, Y) β ΠΊΠΎΠ²Π°ΡΠΈΠ°ΡΠΈΡ, ΠΌΠ΅ΡΠ° ΠΈΡ ΡΠΎΠ²ΠΌΠ΅ΡΡΠ½ΠΎΠ³ΠΎ ΠΎΡΠΊΠ»ΠΎΠ½Π΅Π½ΠΈΡ. ΠΠΌΠ΅Π½Π½ΠΎ ΡΡΡ ΠΊΠΎΠ²Π°ΡΠΈΠ°ΡΠΈΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡΡ ΠΌΠ΅ΡΠΎΠ΄Ρ ΡΠ½ΠΈΠΆΠ΅Π½ΠΈΡ Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΠΈ: ΠΏΠΎΠ΄ΠΎΠ±ΡΠ°Π² Π²ΡΠΏΠΎΠΌΠΎΠ³Π°ΡΠ΅Π»ΡΠ½ΡΡ Π²Π΅Π»ΠΈΡΠΈΠ½Ρ, ΡΠ΅ΡΠ½ΠΎ ΡΠ²ΡΠ·Π°Π½Π½ΡΡ Ρ ΠΌΠ΅ΡΡΠΈΠΊΠΎΠΉ, ΠΈΠ· Π΄ΠΈΡΠΏΠ΅ΡΡΠΈΠΈ ΠΎΡΠ΅Π½ΠΊΠΈ Π²ΡΡΠΈΡΠ°ΡΡ Π»ΠΈΡΠ½ΠΈΠΉ ΡΠ°Π·Π±ΡΠΎΡ.