Econometrics basics · foundations
Expectation, variance
& covariance
Free study notes from Econometrics basics (first-year foundations).
The expectation is the probability-weighted average of a random variable; the variance is the average squared distance from it. The covariance is the average product of two variables' deviations from their means, and its sign says whether they move together. Standard errors and the OLS slope are built from these three with a few rules, collected in the table below.
Variance and covariance rules in one table
Each row of the table gives a rule, the condition it needs and the reason in one line. \(X\) and \(Y\) are random variables; \(a\), \(b\), \(c\) and \(d\) are constants.
| Rule | Condition | Why |
|---|---|---|
| \(E[a + bX] = a + bE[X]\) | Any \(X\) | A weighted average of \(a + bX\) is \(a\) plus \(b\) times that of \(X\). |
| \(E[X + Y] = E[X] + E[Y]\) | Any \(X\) and \(Y\), related or not | Summed over the joint distribution, \(x + y\) splits into two sums, each using one variable's own probabilities. |
| \(\operatorname{Var}(X)\) \(= E[X^2] - (E[X])^2\) | Any \(X\) | Expand \((X - \mu)^2\) and take expectations term by term. |
| \(\operatorname{Var}(a + bX) = b^2\operatorname{Var}(X)\) | Any \(X\) | \(a\) moves every value and the mean alike; \(b\) multiplies each deviation by \(b\), each squared deviation by \(b^2\). |
| \(\operatorname{Cov}(X, Y)\) \(= E[XY] - E[X]E[Y]\) | Any \(X\) and \(Y\) | Expand \((X - \mu_X)(Y - \mu_Y)\) and take expectations term by term. |
| \(\operatorname{Cov}(a + bX, c + dY)\) \(= bd\operatorname{Cov}(X, Y)\) | Any \(X\) and \(Y\) | \(a\) and \(c\) drop out of the deviations, and \(b\) and \(d\) multiply them, so their product is multiplied by \(bd\). |
| \(\operatorname{Var}(X + Y)\) \(= \operatorname{Var}(X) + \operatorname{Var}(Y)\) \(+ 2\operatorname{Cov}(X, Y)\) | Any \(X\) and \(Y\) | The squared deviation of a sum is two squared deviations plus twice their product (derivation). |
| \(\operatorname{Var}(X - Y)\) \(= \operatorname{Var}(X) + \operatorname{Var}(Y)\) \(- 2\operatorname{Cov}(X, Y)\) | Any \(X\) and \(Y\) | The row above with \(-Y\) for \(Y\), since \(\operatorname{Cov}(X, -Y)\) \(= -\operatorname{Cov}(X, Y)\). |
| \(\operatorname{Var}(X \pm Y)\) \(= \operatorname{Var}(X) + \operatorname{Var}(Y)\) | \(X\) and \(Y\) uncorrelated, for example independent | The covariance term in the two rows above is zero. |
| \(\operatorname{Corr}(X, Y) = \dfrac{\operatorname{Cov}(X, Y)}{\sigma_X\sigma_Y}\), and \(-1 \le \operatorname{Corr}(X, Y) \le 1\) | \(\sigma_X\) and \(\sigma_Y\) above zero | Dividing by both standard deviations cancels the units, and \(\operatorname{Var}(X/\sigma_X \pm Y/\sigma_Y)\) \(= 2 \pm 2\operatorname{Corr}(X, Y)\) cannot be negative. |
| \(\operatorname{Var}(\bar X) = \sigma^2/n\) | \(n\) independent draws, each with variance \(\sigma^2\) | Their sum has variance \(n\sigma^2\), with no covariance terms, and \(1/n\) comes out squared. |
Every rule assumes that the expectations and variances in it are finite. A capital letter is a random variable and the lower-case letter a value it takes. \(E[X]\), also written \(\mu\) or \(\mu_X\), is the expectation of \(X\), \(\sigma_X\) its standard deviation and \(\bar X\) the mean of \(n\) observations. Books also write \(\mathbb{E}[X]\) for \(E[X]\), \(\sigma_X^2\) for \(\operatorname{Var}(X)\) and \(\sigma_{XY}\) for \(\operatorname{Cov}(X, Y)\); the choice of letters is cosmetic. Lesson 3 of the course takes the slower route, on real data: expectation, variance, covariance, correlation, the variance of a sum and why a sample variance divides by n - 1.
What students say
“Nicky is an excellent econometrics tutor. He explains complex concepts clearly and makes them much easier to understand.”
“I was completely lost in my economics class, and then I started working Nicky and he totally saved me. He was excellent at explaining the material and extremely accommodating to meet with me many times despite us being in different time zones! Highly recommend working with Nicky!”
“Nicky is a very good and thorough teacher. He has excellent knowledge of econometrics and takes the time to work through your questions. Highly recommended!”
“Really great tutor! Encouraging, knowledgeable, friendly”
“Very good lesson, Nicky is very helpful.”
“Very helpful and clear.”
“I gather it was very useful, thank you!”
“Fantastic!”
Expectation: a probability-weighted average
The expectation says in one number where a random variable is centred.
For a discrete random variable \(X\), the expectation is
$$ E[X] = \sum_x x\,P(X = x) , $$
where the sum runs over every value \(x\) that \(X\) can take. For a continuous random variable with density \(f(x)\) the sum becomes an integral, \(E[X] = \int x f(x)\,dx\).
Remarks. In words: each value weighted by its probability, then added up. The expectation is also called the population mean. It is a fixed feature of the distribution, not the mean of a sample, which changes from one sample to the next.
For one fair die, \(E[X] = (1 + 2 + \dots + 6)/6 = 3.5\), a score the die cannot show. Constants come out of a weighted sum (the probabilities add up to 1, so \(a\) comes out whole), which gives the first row of the table. The second row needs no independence: the expectation of \(X + Y\) splits into a sum over the probabilities of \(X\) and one over those of \(Y\), so how the two are related does not enter.
Variance and standard deviation
To measure how far a random variable lies from its expectation, the deviations cannot simply be averaged. Those above the mean cancel those below, so the average deviation is zero for every distribution, \(E[X - \mu] = E[X] - \mu = 0\), and cannot measure spread. A square is never negative, so squared deviations cannot cancel; and squares, unlike plain distances, give the variance of a sum the simple form of row 7, on which the standard error rests. So we square the deviations before averaging them.
$$ \begin{aligned} \operatorname{Var}(X) &= E[(X - \mu)^2] , \\ \sigma &= \sqrt{\operatorname{Var}(X)} . \end{aligned} $$
Remarks. In words: the variance is the average squared distance from the mean, and the standard deviation \(\sigma\) is its square root. A variance is in squared units, percent squared for returns in percent. The square root returns it to the units of the data, so \(\sigma\) can be read as a typical distance from the mean, although it is the root of the average squared distance, not the average distance.
The third row of the table is the quicker way to compute it. For one fair die the squared scores 1, 4, 9, 16, 25 and 36 average 91/6, so
$$ \operatorname{Var}(X) = \frac{91}{6} - 3.5^2 = \frac{35}{12} = 2.92 , $$
and \(\sigma = \sqrt{35/12} = 1.71\), a little more than the average distance of a score from 3.5, which is 1.5.
Why \(b^2\) in \(\operatorname{Var}(a + bX) = b^2\operatorname{Var}(X)\)? Adding \(a\) moves every value and the mean alike, so no deviation changes. Multiplying by \(b\) multiplies every deviation by \(b\), so every squared deviation by \(b^2\) and the standard deviation by \(|b|\): a standard deviation of £2 is one of 200 pence, and a variance of 4 pounds squared is one of 40,000 pence squared.
Covariance and correlation: what is the difference?
The covariance says whether two random variables move together, and the correlation says how closely, on a scale without units.
$$ \begin{aligned} &\operatorname{Cov}(X, Y) \\ &\quad = E[(X - \mu_X)(Y - \mu_Y)] , \\ &\operatorname{Corr}(X, Y) = \frac{\operatorname{Cov}(X, Y)}{\sigma_X\sigma_Y} . \end{aligned} $$
Remarks. In words: the covariance is the average product of the two deviations from their means, and the correlation divides it by both standard deviations. \(\operatorname{Cov}(X, X) = \operatorname{Var}(X)\). A covariance of zero does not make \(X\) and \(Y\) independent.
The product of the deviations is positive when both variables are above their means or both below, and negative when one is above and the other below. So the covariance is positive when, on average, high values of one go with high values of the other, and negative when high values go with low.
A covariance is in the units of \(X\) times the units of \(Y\). Record \(X\) in pence instead of pounds and every deviation of \(X\) is 100 times as large, so the covariance is too. Its standard deviation \(\sigma_X\) is also 100 times as large, so the correlation is unchanged. The correlation has no units; it lies between -1 and 1, and it is -1 or 1 only when \(Y\) is an exact straight-line function of \(X\).
Figure 1 shows what a covariance can and cannot detect, in four simulated scatters of 200 points.
Figure 1. A covariance picks up straight-line association only. Each panel is titled with its sample covariance and correlation: positive linear 0.98 and 0.83; negative linear -0.93 and -0.82; independent 0.05 and 0.04; \(y = x^2\) plus noise 0.02 and 0.01, although the points follow a clear U. In the population the covariances, and the correlations, are 0.8, -0.8, 0 and 0; the sample values differ from them by chance. Simulated, 200 points a panel: \(x\) standard normal, with \(y = 0.8x + 0.6e\), \(y = -0.8x + 0.6e\) (\(e\) standard normal) or \(y\) an independent standard normal; in the last panel \(x\) uniform on -2 to 2 and \(y = x^2 + e\), \(e\) normal with standard deviation 0.3. Exact recipes at the foot of the page.
In the fourth panel \(y\) is close to a function of \(x\): the correlation of \(y\) with \(x^2\) is 0.97. Yet its covariance with \(x\) is 0.02. A point at \(x\) and one at \(-x\) are equally likely and have the same expected \(y\), so their products of deviations cancel, and in the population the covariance is 0. So zero covariance does not imply independence, although the reverse holds: if \(X\) and \(Y\) are independent, \(E[XY] = E[X]E[Y]\) and the covariance is zero. The least-squares line of \(Y\) on \(X\) has slope equal to the covariance divided by the variance of \(X\), and its sample version is the OLS slope. So a zero covariance means that this line is flat, which does not rule out a curve.
Var(X + Y): the variance of a sum, on a real portfolio
Unlike its expectation, the variance of a sum depends on how the two variables move together:
$$ \begin{aligned} \operatorname{Var}(X + Y) &= \operatorname{Var}(X) + \operatorname{Var}(Y) \\ &\quad + 2\operatorname{Cov}(X, Y) . \end{aligned} $$
In words: the variance of a sum is the sum of the two variances plus twice their covariance.
When the two are above or below their means together, their deviations reinforce each other and the sum varies more; when one is above while the other is below, the deviations partly offset and the sum varies less. Lesson 3 works through a case with a negative covariance, home and away goals.
Show where the rule comes from
- The deviation of the sum. \(X + Y\) has mean \(\mu_X + \mu_Y\), so its deviation from its mean is \((X - \mu_X) + (Y - \mu_Y)\).
- Square it. $$ \begin{aligned} &[(X - \mu_X) + (Y - \mu_Y)]^2 \\ &= (X - \mu_X)^2 + (Y - \mu_Y)^2 \\ &\quad + 2(X - \mu_X)(Y - \mu_Y) . \end{aligned} $$
- Take expectations, term by term. The expectation of the squared deviation of the sum is \(\operatorname{Var}(X + Y)\), and the three terms give \(\operatorname{Var}(X)\), \(\operatorname{Var}(Y)\) and \(2\operatorname{Cov}(X, Y)\).
With \(-Y\) in place of \(Y\) the cross term changes sign, which gives the rule for \(X - Y\).
When \(X\) and \(Y\) are uncorrelated, for example independent, the covariance term is zero and the variances add. Take a real case, in which the covariance is not zero: monthly excess returns (the return minus that month's one-month US Treasury bill rate), in percent, on two US industry portfolios from Kenneth French's data library, Utilities and Business Equipment (computers, software and electronic equipment), over the 207 months from January 2000 to March 2017.
Over the 207 months the variances of the monthly returns are 17.71 for Utilities and 51.63 for Business Equipment, in percent squared; their covariance is 6.92, also in percent squared, and their correlation 0.23. The standard deviations are 4.21% and 7.19% a month.
A mix of half of each has return \(M = 0.5X + 0.5Y\), where \(X\) and \(Y\) are the two returns. Rows 4, 6 and 7 of the table put \(0.5^2 = 0.25\) on each variance and \(2 \times 0.5 \times 0.5 = 0.5\) on the covariance. With three decimals carried, so that the parts add up,
$$ \begin{aligned} \operatorname{Var}(M) &= 0.25 \times 17.708 \\ &\quad + 0.25 \times 51.629 \\ &\quad + 0.5 \times 6.918 \\ &= 4.427 + 12.907 + 3.459 \\ &= 20.793 . \end{aligned} $$
The variance of the mix's 207 monthly returns, computed directly, is the same 20.793: the rules hold exactly for the variances and covariances of a set of data when every term uses the same divisor. The mix's standard deviation is 4.56% a month.
Figure 2. Half in each industry: a variance of 20.8, between the two industries. Variance of monthly excess returns, in percent squared: Utilities 17.7, Business Equipment 51.6 and the half-and-half mix 20.8, whose bar is split into 0.25 Var1 = 4.4, 0.25 Var2 = 12.9 and 0.5 Cov = 3.5, rounded to one decimal (at two decimals the rounded parts would not add up to the total). Source: Kenneth R. French data library, 12 industry portfolios, January 2000 to March 2017; own calculations.
The mix is far less variable than Business Equipment alone (20.8 against 51.6), but more variable than Utilities alone (17.7). How much mixing gains depends on the covariance. Were the correlation 1, with the same two variances, the covariance would take its largest possible value, the product of the two standard deviations, and the mix's standard deviation would be the plain average of the two, 5.70% a month (variance 32.45). With a correlation of 0.23 the covariance term is only 3.46, and the standard deviation, 4.56%, is 20% below that average. With zero covariance the variance would be 17.33, a little below Utilities alone. This is the arithmetic of diversification over these 207 months, not a forecast of future returns or advice on what to hold.
Two dice: the rules against all 36 outcomes
With two dice every outcome can be listed, so the rules can be checked against the whole distribution. One fair die has \(E[X] = 3.5\) and \(\operatorname{Var}(X) = 35/12 = 2.92\).
By the rules. The total of two dice, \(T = X_1 + X_2\), has \(E[T] = 3.5 + 3.5 = 7\). The two throws are independent, so their covariance is zero and the variances add: \(\operatorname{Var}(T) = 35/12 + 35/12 = 35/6 = 5.83\).
From the table. Each of the 36 pairs of scores has probability 1/36. Grouping the pairs by their total gives the distribution of \(T\): a total \(t\) has probability (ways)/36, from 1/36 for 2 or 12 to 6/36 for 7. The table gives, for each total, its number of ways and its squared distance from 7.
| Total \(t\) | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Ways out of 36 | 1 | 2 | 3 | 4 | 5 | 6 | 5 | 4 | 3 | 2 | 1 |
| \((t - 7)^2\) | 25 | 16 | 9 | 4 | 1 | 0 | 1 | 4 | 9 | 16 | 25 |
Each total times its number of ways adds up to 252, and each squared distance times its number of ways to 210, so
$$ \begin{aligned} E[T] &= \sum_t t\,P(T = t) = \frac{252}{36} = 7 , \\ \operatorname{Var}(T) &= \sum_t (t - 7)^2\,P(T = t) \\ &= \frac{210}{36} = \frac{35}{6} = 5.83 . \end{aligned} $$
Both agree with the rules. The standard deviation of the total is \(\sqrt{35/6} = 2.42\), not 1.71 + 1.71 = 3.42: for independent variables the variances add, and the standard deviations do not.
From a sum to a sample mean
Why does the mean of \(n\) observations vary less than one observation does? Suppose \(X_1, \dots, X_n\) are \(n\) independent draws from a population with variance \(\sigma^2\) (random sampling). Independence makes every covariance between two draws zero, so their sum has variance \(n\sigma^2\). The sample mean \(\bar X\) is the sum times \(1/n\), and a constant comes out of a variance squared:
$$ \operatorname{Var}(\bar X) = \frac{n\sigma^2}{n^2} = \frac{\sigma^2}{n} . $$
In words: the variance of the sample mean is the variance of one observation divided by the number of observations.
Intuitively, in a mean the high draws and the low ones largely offset one another, so the mean strays less from \(\mu\) than one draw does. One die shows 1 or 6 with probability 2/6; the mean of two dice is 1 or 6 only when both dice show the same extreme, with probability 2/36. For two dice, the mean score \(T/2\) has variance \((35/6)/4 = 35/24 = 1.46\), half the 2.92 of one die. The result holds for every \(n\), not only in large samples. Independence is used at one step, to remove the covariance terms. For data correlated over time those terms stay, and when the observations are positively correlated with one another the variance of the mean is larger than \(\sigma^2/n\) (see estimating the mean of a time series).
The square root, \(\sigma/\sqrt{n}\), is the standard deviation of the sample mean, in the units of the data. Lesson 4 derives it step by step and checks it against simulated samples; lesson 5 puts the sample standard deviation \(s\) in place of \(\sigma\), which gives the standard error of the mean.
Check your understanding
If \(\operatorname{Var}(X) = 4\), what is \(\operatorname{Var}(3X - 5)\)?
\(3^2 \times 4 = 36\), so the standard deviation goes from 2 to 6. Subtracting 5 moves every value and the mean alike, so it leaves the spread unchanged.
The monthly returns on one share of each of two companies, in pounds, each have variance 0.04 (pounds squared), and their covariance is 0.01. What is the variance of the total return on one share of each? And with a covariance of -0.01?
\(0.04 + 0.04 + 2 \times 0.01 = 0.10\). With a covariance of -0.01 it is \(0.04 + 0.04 - 0.02 = 0.06\): low returns on one share go with high returns on the other, so the two partly offset.
Does zero covariance mean that \(X\) and \(Y\) are independent?
No. Let \(X\) be symmetric about zero and \(Y = X^2\). Then \(E[X] = 0\) and \(E[XY] = E[X^3] = 0\), so the covariance is 0, yet \(Y\) is known as soon as \(X\) is. The fourth panel of Figure 1 shows the same with noise added.
Two variables have standard deviations 4 and 5 and covariance -6. What is their correlation, and what changes if the first is recorded in pence instead of pounds?
\(-6/(4 \times 5) = -0.3\). In pence the first standard deviation is 400 and the covariance -600, but the correlation is \(-600/(400 \times 5) = -0.3\) again.
\(n = 25\) independent observations each have variance 100. What is the variance of their mean?
\(100/25 = 4\), so the standard deviation of the mean is 2, against 10 for one observation. Independence is what removes the covariance terms; with correlated observations \(\sigma^2/n\) does not follow.
Questions about variance and covariance
What is the formula for variance and covariance?
The variance is Var(X) = E[(X - μ)²], the average squared distance from the mean, computed as E[X²] - μ². The covariance is Cov(X, Y) = E[(X - E[X])(Y - E[Y])], computed as E[XY] - E[X]E[Y]. For one fair die, E[X²] = 91/6 and μ = 3.5, so the variance is 35/12 = 2.92.
What is Var(X + Y)?
Var(X + Y) = Var(X) + Var(Y) + 2Cov(X, Y). If X and Y are uncorrelated, for example independent, the covariance term is zero and the variances add: the total of two dice has variance 35/12 + 35/12 = 5.83. For the two industry returns on this page the covariance is 6.92, so the term adds 13.84 percent squared.
What is the difference between covariance and correlation?
Correlation is covariance divided by both standard deviations. A covariance is in the units of X times the units of Y, so it changes when the units change; a correlation has no units and lies between -1 and 1. For the Utilities and Business Equipment returns on this page the covariance is 6.92 percent squared and the correlation 0.23.
Does zero covariance mean independence?
No. Independence implies zero covariance, but zero covariance only means that the least-squares line of Y on X is flat. If X is symmetric about zero and Y = X², the covariance is 0, yet Y is known once X is. In the simulation on this page, y = x² plus noise has a covariance of 0.02 with x.
Related notes
Data and simulation. Returns: Kenneth R. French data library, 12 industry portfolios (value-weighted, monthly), Utilities and Business Equipment, in excess of the one-month Treasury bill rate, January 2000 to March 2017; variances and covariances with divisor n - 1; results quoted, data not republished. Figure 1: 200 points a panel, each panel from a fresh numpy default_rng(2026), draws in this order: positive and negative panels x = rng.normal(0, 1, size=200), then e = rng.normal(0, 1, size=200), with y = 0.8*x + 0.6*e or y = -0.8*x + 0.6*e; independent panel x = rng.normal(0, 1, size=200), then y = rng.normal(0, 1, size=200); fourth panel x = rng.uniform(-2, 2, size=200), then e = rng.normal(0, 0.3, size=200) and y = x**2 + e; sample covariances and correlations with divisor n - 1. Dice: exact probabilities.
Learning this for a
course or exam?
I tutor statistics and econometrics from first principles through to postgraduate level, with worked examples at your pace. The first consultation is free and lasts 30 minutes.
