Variance
Part of Math Camp: An Introduction to Mathematics and Statistics with Applications in Economics.
Main Stam4Econ site | View this section in the book | Author: Fan Wang | DOI: 10.5281/zenodo.24696926
Date: 2026-11-30 | HTML | PDF | QMD
1 Variance
1.1 Variance of a discrete random variable
The variance of a discrete random variable \(X\) is defined as:
\[ Var(X) = E[(X - E(X))^2] = \sum_{x_i \in \text{Support of } X} (x_i - E(X))^2 P(X = x_i) \]
where \(E(X)\) is the expectation of \(X\).
1.2 Variance of a continuous random variable
The variance of a continuous random variable \(X\) is defined as:
\[ Var(X) = E[(X - E(X))^2] = \int_{-\infty}^{\infty} (x - E(X))^2 f_X(x) dx \]
where \(f_X(x)\) is the probability density function of \(X\).
1.3 Variance transformation of a random variable
Suppose \(Y = g(X) = X \cdot \delta + \gamma\), then the variance of \(Y\) is:
\[ Var(Y) = Var(g(X)) = Var(X \cdot \delta + \gamma) = \delta^2 Var(X) \]
1.4 Variance decomposition
Total variance is equal to the sum of the expected conditional variance and the variance of the conditional expectation:
\[ Var(X) = E(Var(X|Y)) + Var(E(X|Y)) \]
We can write these out in integral form:
\[ Var(X) = \int \int \left(x - \int x dF(x|y) \right)^2 dF(x|y) dF(y) + \int \left( \int x dF(x|y) - \int x dF(x) \right)^2 dF(y) \]
1.5 Variance decomposition derivation
There is a sample with \(N\) individuals, where \(P(n)\) is the sample weight such that \(\sum_{n=1}^N P(n)=1\). These individuals belong to \(S>1\) mutually exclusive and exhaustive counties in the United States, denoted as \(\left\{C_s\right\}_{s=1}^S\), where \(s\) is the county-index. This means that \(\cup_{s=1}^{S} C_s = \left\{ n \in \mathbb{N} : 0 < n \le N \right\}\) and \(C_s \cap C_{s'} = \emptyset\) for all \(s\neq s'\).
Alternatively, we can think of \(N\) as the count for all locations in a world (degree square by longitude and latitude for example), \(P(n)\) is the share of population in each location among world population, and \(S\) is the number of countries in the world, with \(C_s\) as the set containing all locations for each country.
As another example, we can think of \(N\) as the count for all counties in a country, \(P(n)\) is the share of population in each county with respect to the country. And \(S\) is the number of regions in the country.
Let \(\mu = \sum_{s=1}^{S} \sum_{n\in C_s} P(n)\cdot X_n\) be the overall weighted mean. And let \(\mu_s\) be the weighted mean for group \(s\):
\[ \begin{aligned} \mu_s = \sum_{n\in C_s} \frac{P(n)}{\sum_{\widehat{n}\in C_s} P(\widehat{n})} \cdot X_n \end{aligned} \]
The overall variance can be decomposed as follows:
\[ \begin{aligned} \sum_{s=1}^{S} \sum_{n\in C_s} P(n) \left(X_n - \mu \right)^2 = \sum_{s=1}^{S} \sum_{n\in C_s} P(n) \left(X_n - \mu_s\right)^2 + 2\sum_{s=1}^{S} \sum_{n\in C_s} P(n) \left(X_n - \mu_s\right)\left(\mu_s - \mu\right) + \sum_{s=1}^{S} \sum_{n\in C_s} P(n) \left(\mu_s - \mu\right)^2 \end{aligned} \]
The first term in the summation above is the within-group component of variance and is equal to the weighted sum across groups of each group-specific within-group variance:
\[ \begin{aligned} \sum_{s=1}^{S} \sum_{n\in C_s} P(n) \left(X_n - \mu_s\right)^2 = \sum_{s=1}^{S} \left(\sum_{n\in C_s} P(n)\right) \left( \sum_{n\in C_s} \frac{P(n)}{\sum_{\widehat{n}\in C_s} P(\widehat{n})} \left(X_n - \mu_s\right)^2 \right) \end{aligned} \]
The third term in the summation earlier provides the across-group component of variance and is equal to:
\[ \begin{aligned} &\sum_{s=1}^{S} \sum_{n\in C_s} P(n) \left(\mu_s - \mu\right)^2\\ =&\sum_{s=1}^{S} \left( \left(\mu_s - \mu\right)^2\cdot \sum_{n\in C_s} P(n) \right)\\ \end{aligned} \]
The middle term divided by \(2\) in the summation earlier is equal to zero, which means the overall variance is equal to the weighted sum of within-group variances and across-group variance just derived above. Specifically, the middle term divided by \(2\) is equal to zero as shown via the derivations below:
\[ \begin{aligned} &\sum_{s=1}^S \sum_{n\in C_s} P(n)\,(X_n - \mu_s)(\mu_s - \mu) \\ =& \sum_{s=1}^S (\mu_s - \mu) \sum_{n\in C_s} P(n)(X_n - \mu_s) \\ =& \sum_{s=1}^S (\mu_s - \mu) \left(\sum_{n\in C_s} P(n)X_n - \mu_s \sum_{n\in C_s} P(n)\right) \\ =& 0 \end{aligned} \]
This is because, by the definition of \(\mu_s\), \(\sum_{n\in C_s} P(n)X_n = \mu_s\sum_{n\in C_s} P(n)\) for each group \(s\), so each bracketed term is zero.
Therefore, the total variance is the weighted sum of within-group variances plus the across-group variance.