Interactive statistics

56 free interactive lessons: from mean and median to A/B tests and Bayes. Drag the charts and build intuition. No sign-up.

Module 2: Probability

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)

ΠžΡ‚ΠΊΡƒΠ΄Π° бСрётся Οƒ/√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) β€” ковариация, ΠΌΠ΅Ρ€Π° ΠΈΡ… совмСстного отклонСния. ИмСнно эту ΠΊΠΎΠ²Π°Ρ€ΠΈΠ°Ρ†ΠΈΡŽ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ сниТСния диспСрсии: ΠΏΠΎΠ΄ΠΎΠ±Ρ€Π°Π² Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½ΡƒΡŽ Π²Π΅Π»ΠΈΡ‡ΠΈΠ½Ρƒ, тСсно ΡΠ²ΡΠ·Π°Π½Π½ΡƒΡŽ с ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊΠΎΠΉ, ΠΈΠ· диспСрсии ΠΎΡ†Π΅Π½ΠΊΠΈ Π²Ρ‹Ρ‡ΠΈΡ‚Π°ΡŽΡ‚ лишний разброс.

Next β†’
Enjoying the materials?

This site is built by the DataSlice Telegram channel: data analytics in plain words β€” real cases, metrics, careers. The channel is in Russian.

Open the Telegram channel