Expectation and Variance: Linearity Is Free, Additivity Is Not
Published:
Expectation
For a discrete variable \(\mathbb{E}[X]=\sum_x x\,p(x)\); for a continuous one \(\mathbb{E}[X]=\int x\,p(x)\,dx\). Both are the same object, an integral against the distribution, and both can fail to exist when the tails are heavy enough, as for the Cauchy.
The property that matters is linearity:
for any \(a,b\) and any joint distribution of \(X\) and \(Y\). Dependence is irrelevant because the identity is a statement about the integral, which is linear before any probabilistic structure is imposed.
That freedom is what makes indicator decompositions so effective. Take a uniformly random permutation of \(n\) items and count fixed points, elements left in their own position. Let \(I_i = 1\) if item \(i\) is fixed. The \(I_i\) are heavily dependent, but \(\mathbb{E}[I_i] = P(\text{item } i \text{ fixed}) = 1/n\), so
for every \(n\). No inclusion–exclusion, no derangement formula. Whenever a quantity is a count, write it as a sum of indicators before doing anything else.
Variance and the covariance term
Variance is the expected squared deviation, \(\operatorname{Var}(X)=\mathbb{E}[(X-\mathbb{E}X)^2] = \mathbb{E}[X^2]-(\mathbb{E}X)^2\). It is not linear: \(\operatorname{Var}(aX)=a^2\operatorname{Var}(X)\), and constants shift the mean without moving the spread.
Expanding the square of a sum leaves a cross term:
The cross term is why averaging \(n\) model predictions reduces variance by a factor of \(n\) only when their errors are uncorrelated. For an equally weighted ensemble with common variance \(\sigma^2\) and pairwise correlation \(\rho\), the variance of the average is \(\sigma^2\!\left[\rho + (1-\rho)/n\right]\), which floors at \(\rho\sigma^2\) however many members you add. Ensembling buys nothing beyond that floor, which is why diversity, not count, is the design objective.
Correlation normalises covariance onto \([-1,1]\):
The bound is Cauchy–Schwarz, and \(\lvert \rho\rvert=1\) exactly when \(Y\) is an affine function of \(X\). Correlation is a measure of linear association, nothing more.
Uncorrelated does not mean independent
Let \(X\) be uniform on \(\{-1,0,1\}\) and set \(Y = X^2\). Then \(\mathbb{E}[X]=0\) and \(\mathbb{E}[XY]=\mathbb{E}[X^3] = \tfrac13(-1+0+1) = 0\), so
Yet \(Y\) is a deterministic function of \(X\). Concretely, \(P(Y=0)=\tfrac13\) while \(P(Y=0\mid X=1)=0\), so the two are as dependent as it is possible to be. The same works for \(X\sim\mathcal{N}(0,1)\), \(Y=X^2\), since \(\mathbb{E}[X^3]=0\) by symmetry.
The converse direction does hold: independence implies \(\mathbb{E}[XY]=\mathbb{E}X\,\mathbb{E}Y\), hence zero covariance. The one place the implication reverses is the jointly Gaussian case, for a multivariate normal, zero covariance really does mean independence, which is why the trap is so easy to fall into after a term of working with Gaussians.
Conditioning: total expectation and total variance
Conditioning gives two decompositions that are used constantly. The law of total expectation:
, average within groups, then average the group averages, weighted by group size. The law of total variance splits spread the same way:
A worked case: a value comes from one of two groups with equal probability; group 0 has mean 0 and variance 1, group 1 has mean 4 and variance 1. Within-group term: \(\mathbb{E}[\operatorname{Var}(Y\mid X)] = 1\). Between-group term: the conditional means are 0 and 4 with probability \(\tfrac12\) each, so their variance is \(8 - 2^2 = 4\). Total: \(\operatorname{Var}(Y) = 1 + 4 = 5\). Checking directly, \(\mathbb{E}[Y]=2\) and \(\mathbb{E}[Y^2] = \tfrac12(1+0)+\tfrac12(1+16) = 9\), giving \(9-4=5\).
Where this goes next
Means and variances for the standard families are tabulated in common distributions; what happens to a sample mean as \(n\) grows is limit theorems.
Recap
- Linearity of expectation holds for any dependence; \(\mathbb{E}[XY]=\mathbb{E}X\,\mathbb{E}Y\) does not.
- \(\operatorname{Var}(X+Y)=\operatorname{Var}X+\operatorname{Var}Y+2\operatorname{Cov}(X,Y)\); ensemble averaging floors at \(\rho\sigma^2\).
- Correlation captures linear association only: \(X\) uniform on \(\{-1,0,1\}\) with \(Y=X^2\) has \(\rho=0\) and total dependence.
- Independence \(\Rightarrow\) uncorrelated, never the reverse, except for jointly Gaussian variables.
- Total variance splits into within-group (aleatoric) and between-group (epistemic) parts.
References
- Ross, S. M. A First Course in Probability, 10th ed. Pearson, 2018.
- Wasserman, L. All of Statistics: A Concise Course in Statistical Inference. Springer, 2004.
- Lakshminarayanan, B., Pritzel, A. & Blundell, C. Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles. NeurIPS 2017.
- Kendall, A. & Gal, Y. What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision? NeurIPS 2017.
