Covariance answers one question: when X is above its average, is Y usually above its average too? Everything else is bookkeeping. This page builds the formula from that question, one step at a time, draws it as areas you can click, proves the shortcut, and settles why zero covariance is weaker than independence. 5 past-paper questions at the end.
Ashanagar is an invented district. The statistics lessons use it for every worked example, so you meet the same households again as the ideas build: first as a list of numbers, then as a spread, then as a population to sample from.
It has 60 households, each with a monthly income in rupees. Unless a page says otherwise, those 60 are the whole population, and a “sample” means a few of them drawn at random. Where a page needs two variables, it uses a smaller set of 12 households with the head’s years of schooling beside income.
The figures are illustrative, made up once and fixed. They are not official statistics.
Tap a symbol.
Two variables can be unrelated, can rise together, or can pull in opposite directions. Covariance is a number for which of the three it is, and by how much. It does not ask whether y is big, only whether y is bigger than usual when x is bigger than usual.
That wording hides a design. To say “bigger than usual” you must first fix what usual is, which is the average, and then measure every value by how far it sits from it. That distance is the deviation. Every step that follows is a decision about what to do with the deviations of x and of y.
The derivation below builds the definition in six steps. Open them one at a time. The fourth has a lab: each household’s deviations form a rectangle, and the covariance is the average of their signed areas.
Take 12 Ashanagar households and, for each, the head’s years of schooling (x) and the monthly income in thousands of rupees (y). We want one number that is positive when households with more schooling than average tend to have more income than average, negative when they tend to have less, and near zero when there is no such tendency. It should also get bigger as the tendency gets stronger.
The averages are x̄ = 10.42 years and ȳ = ₹23 thousand. Subtract them to get each household’s deviations, how far it sits from the average on each variable:
Household 1 has 5 years of schooling and an income of ₹15 thousand, so dx = 5 − 10.42 = −5.42 and dy = 15 − 23 = −8. It is below average on both.
Add all the dx and you always get zero, because Σ(xi − x̄) = Σxi − n x̄ = 0. The deviations cancel by construction, so a sum cannot measure anything. What matters is whether the two deviations of the same household point the same way. Multiply them:
| dx | dy | Product | Meaning |
|---|---|---|---|
| + | + | + | above average on both |
| − | − | + | below average on both |
| + | − | − | they pull apart |
| − | + | − | they pull apart |
The sign of the product is exactly the “move together or apart” test, and a bigger deviation on either side makes the product bigger.
Mark the point of means on the scatter. For each household draw the rectangle from that point to the household: its width is dx, its height dy, and its area is the product. Blue rectangles lie in the two quadrants where both deviations share a sign, red ones in the other two. Click through the households, then try the other two scatters.
The total signed area is the sum of all the products, and dividing by n turns a total into an average, so the number does not grow just because there are more households. That gives the formula. For the 12 households the products add to 262, and
The units are years of schooling times thousands of rupees, so the size of the number depends on the units chosen. That is the reason the covariance is usually divided by both standard deviations to give the correlation.
For the twelve households the covariance is 21.83. Its sign says the pattern is positive. Its size, on its own, says very little, since it depends on the units. Dividing by the two standard deviations (3.33 years and ₹7.55 thousand) gives the correlation, r = 0.87, which can be judged against 1.
The definition needs a deviation for every observation. When you are given a table of probabilities, or a handful of sums, there is a quicker route that gives the same number. It comes from opening the bracket.
Write μX = E[X] and μY = E[Y]. The definition is Cov = E[(X − μX)(Y − μY)]. Multiply out the bracket, as in (a − b)(c − d) = ac − ad − bc + bd:
The average of a sum is the sum of the averages, and a constant comes out in front of an average. Here μX and μY are constants, since they are fixed numbers. So
Two of the three last terms are the same product with a minus sign, and the third is the same product with a plus. They leave one copy with a minus:
JNU 2021 gives a joint table: X takes 1 or 3, Y takes −3, 2 or 4. The row totals give E[X] = 0.5 × 1 + 0.5 × 3 = 2, the column totals give E[Y] = (−3)(0.4) + (2)(0.3) + (4)(0.3) = 0.6, and multiplying each cell by its x and y gives E[XY] = 0. Then
That is the key, option D. The shortcut needs only one pass for E[XY] and the two means, instead of computing a deviation for every cell.
Most covariance questions in papers are not about computing from data. They give a few covariances and variances and ask for another one. Three rules, each easy to see from the rectangles, are enough.
Adding a constant b to every x moves the average by b too, so xi + b − (x̄ + b) = xi − x̄. The deviations, and so every rectangle, are unchanged. Measuring income in rupees from zero or from some other base makes no difference.
Multiplying every x by a multiplies every deviation by a, and so every rectangle’s width, so every area, by a. The same holds for c on the y side, which is why Cov(aX, cY) = ac Cov(X, Y). Change income from rupees to thousands of rupees, a factor of 1000, and the covariance changes by 1000 too.
The deviation of a sum is the sum of the deviations: (x + z) − (x̄ + z̄) = (x − x̄) + (z − z̄). Multiply by (y − ȳ) and average, and the covariance splits in two:
The same holds in the second argument. A covariance of a variable with a constant is zero, since a constant has no deviations.
JNU 2018: y = 2w + 4u, var(w) = 5 and cov(w, u) = 1. What is cov(w, y)? Split it, then pull out the constants, then use Cov(w, w) = Var(w):
The same splitting, applied to Cov(X + Y, X + Y), is how the variance of a sum, Var(X) + Var(Y) + 2 Cov(X, Y), is derived in the correlation lesson.
The rules give the most-used result in the module, the variance of a combination. Expanding (aU + bV)² and averaging each term yields a cross term, and the cross term is a covariance. The derivation below, from the correlation lesson, also draws it as four areas.
Write U = X − μX and V = Y − μY for the deviations from the means. The mean of aX + bY is aμX + bμY, so the deviation of the combination from its own mean is aU + bV.
This is the ordinary expansion of (p + q)². Nothing about statistics has happened yet.
The average of U² is σX² and of V² is σY², by the definition of variance, and the average of UV is Cov(X, Y), by the definition of covariance. That gives the formula. The cross term is there because the squared bracket has a middle term, and it carries a factor of 2 for the same reason.
Draw a square of side aσX and another of side bσY, and put the two rectangles between them. Their areas are a²σX², b²σY² and two copies of abσXσY. The covariance is ρσXσY, so each rectangle is filled in only to the fraction ρ. Move ρ to 1 and the pieces make one big square, (aσX + bσY)². Move it to 0 and the rectangles vanish.
Two words, “independent” and “uncorrelated”, are often used as if they meant the same thing. They do not, and papers ask about the gap. Uncorrelated means the covariance is zero. Independent means the whole joint distribution factors into the two separate ones.
For independent discrete variables, P(X = x, Y = y) = P(X = x) P(Y = y) for every pair. The average of the product is the double sum over all pairs:
The double sum splits into a product because each x multiplies the whole sum over y. By the shortcut, Cov = E[XY] − E[X]E[Y] = 0.
Let X be −1, 0 or 1, each with probability 1/3, and let Y = X². Y is completely decided by X, so they are as dependent as two variables can be. But E[X] = 0, E[XY] = E[X³] = (−1 + 0 + 1) ÷ 3 = 0, and so Cov = 0 − 0 × E[Y] = 0.
The rectangles explain it: the points lie on a U shape, and for every point on the right arm there is a mirror point on the left arm with the opposite sign of dx but the same dy, so the areas cancel. Covariance sees only the straight-line part of a relationship.
DSE 2012: X is uniform on [−1, 1]. Find Cov(X, X²). The same argument gives E[X] = 0 and E[X³] = 0, since X³ is an odd function and the interval is symmetric, so the covariance is 0 even though X² is a function of X.
Independent implies uncorrelated. Uncorrelated does not imply independent, except for a jointly normal pair.
A covariance of 21.83 is hard to read, because multiplying income by 1000 would make it 21,830. Dividing by both standard deviations cancels the units. That leaves a number that always lies between −1 and 1, and the next derivation shows why.
Standardise each variable: and . Two facts follow at once. By the definition of the standard deviation the average of zx² is 1, and so is the average of zy². And the correlation is the average product of the two z scores:
For each household the gap zx − zy squared is at least 0, so its average is too. Expand it:
So 2 − 2r ≥ 0, which says r ≤ 1. For the twelve households r = 0.869 and the average squared gap is 2 − 2 × 0.869 = 0.262.
So 2 + 2r ≥ 0, which says r ≥ −1. Both bounds come from nothing more than the fact that a square cannot be negative. The picture shows what the two averages measure: how far the standardised points stray from the line y = x and from the line y = −x.
An average of squares is 0 only if every square is 0. So r = 1 means zx = zy for every household, which is the straight line y = ȳ + (σY ÷ σX)(x − x̄) with a positive slope. In the same way r = −1 forces zx = −zy, a straight line sloping down. Any scatter that is not exactly a straight line leaves some gap, and then r is strictly inside the interval.
One more link. The slope of the least-squares line of y on x is b = Cov(X, Y) ÷ Var(X), the covariance measured per unit of x’s variance. The regression primer derives it. The correlation lesson uses this page’s results in full, and the joint distributions lesson applies them to tables.
Use the definitions from this page. The first two use a tiny data set so every deviation can be done by hand.
Definitions, directions and one-step sums. Most CUET, UGC NET and Hyderabad questions sit here.
Classification traps, multi-step numericals and statement questions, up to the hardest JNU, JAM and GATE items.
The Delhi School entrance asks this topic harder than any other exam. These questions are kept apart from the ordinary sets.
These are questions from the TestStop bank. A free account answers 10 a day, each with its worked solution; All-Access opens every set with no daily limit.
Covariance measures whether two variables tend to be above their averages together and below their averages together. It is the average, over all observations, of the product of each variable's deviation from its mean. It is positive when they move together, negative when they move in opposite directions, and near zero when there is no straight-line tendency.
Cov(X, Y) = (1 ÷ n) Σ (xᵢ − x̄)(yᵢ − ȳ) for a population, or the same sum divided by n − 1 for a sample. An equivalent shortcut is Cov(X, Y) = E[XY] − E[X]E[Y], the mean of the products minus the product of the means.
The deviations in a sample are measured from the sample mean, which is itself fitted to the data and uses up one degree of freedom, so dividing by n slightly understates the average. Dividing by n − 1 corrects this, just as for the sample variance. The correlation coefficient is the same either way.
No. Independent variables always have zero covariance, but zero covariance only rules out a straight-line relationship. If X is symmetric about zero and Y = X², then Y is completely determined by X, yet the covariance is zero. The exception is a pair of jointly normal variables, for which zero covariance does imply independence.
Correlation is the covariance divided by the product of the two standard deviations. This removes the units, so the correlation always lies between −1 and 1 and does not change when you rescale a variable, while the covariance changes with the units.
The variance of a variable is its covariance with itself: Cov(X, X) = Var(X). In general, Var(X + Y) = Var(X) + Var(Y) + 2 Cov(X, Y), which is why variances add only when the covariance is zero.