Foundations to Frontier
Tests
A. Mathematical Foundations › A4 Probability Theory › Basics

Expectation, Variance, Covariance and Correlation

Expectation is the long-run average and the balance point of a distribution. It's linear even for dependent variables. Variance measures spread, covariance measures joint linear variation, and correlation rescales covariance to [−1, 1]. Together they decide how errors combine: Var(wᵀX) = wᵀΣw tells you how to fuse sensors, why correlated errors don't average away, and why heavy tails can break averages altogether.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The long-run average

Roll a die thousands of times and average the results. You’ll get close to 3.5, even though no single roll is ever 3.5. That long-run average is the expectation. Picture the probabilities as weights on a see-saw: the expectation is where it balances.

The average alone isn’t enough. A bus that’s always 5 minutes late and a bus that’s either on time or 10 minutes late have the same average delay, but very different reliability. Variance measures how spread out the values are.

Expectation is a balance point; correlation is linear association
123456
E[X] = 3.500 (the fulcrum) · Var X = E[X²] − E[X]² = 2.917 · σ = 1.708 (shaded ±σ)
The mean is where the bar chart balances. Pile weight at both ends and the variance grows while the mean can stay put. A fair die has mean 3.5 and variance 35/12 ≈ 2.917.
Why engineers care

A navigation system averages several noisy sensors. How much does averaging help? Variance and covariance give the exact answer, and they show that sensors whose errors move together help much less than independent ones.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The average of a fair die is…
  2. 2. Variance measures…
  3. 3. Win $5 half the time, lose $3 otherwise. Expected gain?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Definitions

  • E[X]=∑xx p(x)\mathbb E[X] = \sum_xx\,p(x) (discrete), or ∫x f(x) dx\int x\,f(x)\,dx (continuous).
  • For a function, E[g(X)]=∑g(x)p(x)\mathbb E[g(X)] = \sum g(x)p(x). You don’t need the distribution of g(X)g(X) first.
  • Var⁡X=E[(X−μ)2]=E[X2]−μ2\operatorname{Var}X = \mathbb E[(X - \mu)^2] = \mathbb E[X^2] - \mu^2, and σ=Var⁡X\sigma = \sqrt{\operatorname{Var}X}.
  • Cov⁡(X,Y)=E[(X−μX)(Y−μY)]=E[XY]−μXμY\operatorname{Cov}(X,Y) = \mathbb E[(X - \mu_X)(Y - \mu_Y)] = \mathbb E[XY] - \mu_X\mu_Y.
  • ρ=Corr⁡(X,Y)=Cov⁡(X,Y)σXσY∈[−1,1]\rho = \operatorname{Corr}(X,Y) = \frac{\operatorname{Cov}(X,Y)}{\sigma_X\sigma_Y}\in[-1,1].
Rule Holds when
E[aX+bY+c]=aEX+bEY+c\mathbb E[aX + bY + c] = a\mathbb E X + b\mathbb E Y + c always
Var⁡(aX+b)=a2Var⁡X\operatorname{Var}(aX + b) = a^2\operatorname{Var}X always
Var⁡(X+Y)=Var⁡X+Var⁡Y+2Cov⁡(X,Y)\operatorname{Var}(X + Y) = \operatorname{Var}X + \operatorname{Var}Y + 2\operatorname{Cov}(X,Y) always
E[XY]=EX EY\mathbb E[XY] = \mathbb E X\,\mathbb E Y (Cov = 0) if independent

A die: E=3.5\mathbb E = 3.5 and E[X2]=91/6\mathbb E[X^2] = 91/6, so Var⁡=91/6−12.25=35/12≈2.92\operatorname{Var} = 91/6 - 12.25 = 35/12\approx2.92.

📝 Quick check (Level 1)
0/3 answered
  1. 1. E[X] = 4. E[2X + 3] = ?
  2. 2. Var X = 2. Var(3X) = ?
  3. 3. Var(X + 7) vs Var X?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Linearity is a superpower

E[∑Xi]=∑E[Xi]\mathbb E[\sum X_i] = \sum\mathbb E[X_i] holds with or without independence. To find an expected count, write it as a sum of indicators (A4.1-5):

  • Expected sixes in 12 rolls: 12⋅16=212\cdot\frac16 = 2.
  • Expected fixed points of a random permutation: n⋅1n=1n\cdot\frac1n = 1, for every nn (Practice Code 3).
  • Expected number of pairs sharing a birthday among nn people: (n2)/365\binom n2/365.

Vectors and covariance matrices

For a random vector X\mathbf X, the mean is μ=EX\boldsymbol\mu = \mathbb E\mathbf X and the covariance is Σ=E[(X−μ)(X−μ)⊤]\Sigma = \mathbb E[(\mathbf X - \boldsymbol\mu)(\mathbf X - \boldsymbol\mu)^\top], which is symmetric and PSD. For any weights,

E[w⊤X]=w⊤μ,Var⁡(w⊤X)=w⊤Σw,Cov⁡(AX)=AΣA⊤\mathbb E[\mathbf w^\top\mathbf X] = \mathbf w^\top\boldsymbol\mu, \qquad \operatorname{Var}(\mathbf w^\top\mathbf X) = \mathbf w^\top\Sigma\mathbf w, \qquad \operatorname{Cov}(A\mathbf X) = A\Sigma A^\top

This one formula covers portfolio risk, error budgets, the Kalman filter’s covariance propagation, and PCA (A2.3).

Correlation’s blind spot

ρ\rho measures linear association only. If XX is symmetric about 0 and Y=X2Y = X^2, then Cov⁡=E[X3]=0\operatorname{Cov} = \mathbb E[X^3] = 0, though YY is a function of XX. Independent ⇒ uncorrelated, but not conversely, except for jointly Gaussian variables (A4.2-4).

🐍 Exercise 1: moments from a joint table
Compute means, variances, covariance and correlation from a joint PMF. Verify linearity, variance addition for independent dice, Cov(X, X + Y) = Var X, and E[XY] = E[X]E[Y]. Then find a pair that's uncorrelated but dependent.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Independent X, Y with Var 2 and 3. Var(X − Y) = ?
  2. 2. Var(wᵀX) = ?
  3. 3. Uncorrelated implies independent?

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proofs

  • Linearity. E[X+Y]=∑x,y(x+y)p(x,y)=∑xx pX(x)+∑yy pY(y)\mathbb E[X + Y] = \sum_{x,y}(x + y)p(x,y) = \sum_xx\,p_X(x) + \sum_yy\,p_Y(y), by summing the joint PMF over the other variable. No independence is needed. ∎
  • Variance of a sum. Expand E[((X−μX)+(Y−μY))2]\mathbb E[((X - \mu_X) + (Y - \mu_Y))^2] to get Var⁡X+Var⁡Y+2Cov⁡\operatorname{Var}X + \operatorname{Var}Y + 2\operatorname{Cov}. ∎
  • ∣ρ∣≤1|\rho|\le1. Cauchy–Schwarz (A3.5-5) in the inner product ⟨U,V⟩=E[UV]\langle U, V\rangle = \mathbb E[UV] on centred variables gives ∣Cov⁡∣≤σXσY|\operatorname{Cov}|\le\sigma_X\sigma_Y. Equality holds iff Y−μY=c(X−μX)Y - \mu_Y = c(X - \mu_X) almost surely, i.e. an exact linear relation. ∎
  • Independent ⇒ E[XY]=EX EY\mathbb E[XY] = \mathbb E X\,\mathbb E Y. ∑xy pX(x)pY(y)\sum xy\,p_X(x)p_Y(y) factorizes. ∎

Expectations can fail to exist

The Cauchy distribution has E∣X∣=∫∣x∣π(1+x2)=∞\mathbb E|X| = \int\frac{|x|}{\pi(1+x^2)} = \infty. Its sample means don’t converge: the average of nn Cauchys is again standard Cauchy (Practice Code 5). The St. Petersburg game has an infinite expected payoff. Heavy tails, such as sensor glitches, multipath GPS errors or financial returns, call for medians and robust losses (Huber, A3.3-4) instead of means.

Variance as squared distance

Var⁡X=min⁡cE[(X−c)2]\operatorname{Var}X = \min_c\mathbb E[(X - c)^2], attained at c=EXc = \mathbb E X. So the mean is the best constant predictor under squared error, and the median is the best under absolute error. That’s the probabilistic version of least squares, and why MSE-trained regressors predict conditional means (A4.1-8).

Exercise 3.1: Show that E[(X − c)²] is minimized at c = E[X]

E[(X−c)2]=Var⁡X+(EX−c)2\mathbb E[(X - c)^2] = \operatorname{Var}X + (\mathbb E X - c)^2. The cross term vanishes because E[X−EX]=0\mathbb E[X - \mathbb E X] = 0. The second term is minimized, at 0, when c=EXc = \mathbb E X.

📝 Quick check (Level 3)
0/3 answered
  1. 1. |ρ| = 1 exactly when…
  2. 2. The best constant predictor under squared error is the…
  3. 3. Sample means of Cauchy data…

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Fusing sensors: covariance decides everything

Several unbiased sensors measure the same quantity with error covariance Σ\Sigma. Among unbiased linear combinations w⊤z\mathbf w^\top\mathbf z with ∑wi=1\sum w_i = 1, the variance w⊤Σw\mathbf w^\top\Sigma\mathbf w is minimized by w=Σ−111⊤Σ−11\mathbf w = \frac{\Sigma^{-1}\mathbf 1}{\mathbf 1^\top\Sigma^{-1}\mathbf 1}. That’s the best linear unbiased estimator (BLUE; Aitken, 1935).

  • Independent sensors get inverse-variance weights.
  • Equicorrelated sensors: averaging nn sensors with pairwise correlation ρ\rho gives variance σ21+(n−1)ρn→ρσ2\sigma^2\frac{1 + (n-1)\rho}n\to\rho\sigma^2. Ten thousand IMUs with ρ = 0.2 are barely better than five.
  • Correlated pairs: two sensors sharing an error source should split one sensor’s worth of weight (Exercise 2).

This is why redundant navigation systems prize dissimilar sensors, such as GPS plus inertial plus vision. Their errors are less correlated.

🐍 Exercise 2 (research): optimal sensor fusion and the correlation floor
Show that the variance of an average of equicorrelated sensors floors at ρσ². Compute BLUE weights Σ⁻¹1/(1ᵀΣ⁻¹1) for independent and correlated sensors, and verify wᵀΣw by simulation.

Moments everywhere

  • Kalman filters propagate means and covariances, P←FPF⊤+QP\leftarrow FPF^\top + Q. They’re the optimal linear estimators, which minimize expected squared error (Kalman, 1960).
  • Bias–variance decomposition. Expected test error is bias² + variance + noise. It’s the same algebra as Exercise 3.1, applied to a learned predictor (Geman, Bienenstock and Doursat, 1992; B2).
  • Variance reduction in learning. Policy-gradient baselines, control variates and antithetic sampling all exploit covariance to reduce estimator variance without bias (Greensmith, Bartlett and Baxter, 2004). Batch averaging reduces SGD noise only to the extent that per-example gradients aren’t correlated.
  • Ensembles work because of imperfect correlation. An ensemble of MM models with error correlation ρ\rho has error variance σ2(ρ+(1−ρ)/M)\sigma^2(\rho + (1-\rho)/M). Diversity is the point (Lakshminarayanan, Pritzel and Blundell, 2017).

References

  1. D. Bertsekas, J. Tsitsiklis (2008). Introduction to Probability, 2nd ed., Ch. 2, 4. Athena Scientific.
  2. A. Aitken (1935). “On least squares and linear combination of observations.” Proceedings of the Royal Society of Edinburgh, 55.
  3. R. E. Kalman (1960). “A new approach to linear filtering and prediction problems.” Journal of Basic Engineering, 82.
  4. S. Geman, E. Bienenstock, R. Doursat (1992). “Neural networks and the bias/variance dilemma.” Neural Computation, 4(1).
  5. E. Greensmith, P. Bartlett, J. Baxter (2004). “Variance reduction techniques for gradient estimates in reinforcement learning.” JMLR, 5.
  6. B. Lakshminarayanan, A. Pritzel, C. Blundell (2017). “Simple and scalable predictive uncertainty estimation using deep ensembles.” NeurIPS.
  7. P. Huber (1964). “Robust estimation of a location parameter.” Annals of Mathematical Statistics, 35(1).
  8. P. Groves (2013). Principles of GNSS, Inertial, and Multisensor Integrated Navigation Systems, 2nd ed. Artech House.