Covariance
Do students who spend more time on their phones sleep less? Put each student on a scatter plot as a point (screen hours, sleep hours) and the cloud slopes down. Do the same with height and shoe size and the cloud slopes up. The covariance is one number that summarizes which way the cloud leans. By the end of this page you will be able to predict that sign for the phone study and to compute covariance by hand.
Which way does the cloud lean?
Start with the center of gravity of the data, the point of means $(\bar{x}, \bar{y})$. It splits the plot into four regions.
For each data point, look at how far $x$ is from $\bar{x}$ and how far $y$ is from $\bar{y}$. If both are above their means (upper right), or both are below (lower left), the product $(x - \bar{x})(y - \bar{y})$ is positive. If one is above and the other below (upper left or lower right), the product is negative.
The covariance is the average of those products.
Here $N$ is the number of data pairs. (Some statistics courses divide by $N - 1$ for a sample covariance. The problems on this page divide by $N$.)
In a sports performance investigation, the number of weekly training hours ($X$) is related to the time in minutes an athlete takes to complete a $10$ mile race ($Y$).…
In a sports performance investigation, the number of weekly training hours ($X$) is related to the time in minutes an athlete takes to complete a $10$ mile race ($Y$). What sign do you expect the covariance $s_{xy}$ to have? Briefly reason your answer.
When studying the relationship between the amount of fertilizer applied to a plant (in grams) and its weekly growth (in inches), a covariance of $24,6$ is obtained. What…
When studying the relationship between the amount of fertilizer applied to a plant (in grams) and its weekly growth (in inches), a covariance of $24,6$ is obtained. What does the sign of this statistical parameter indicate about the relationship between the fertilizer and the growth?
The computing formula
Subtracting the means for every point is tedious. There is a shortcut. Expand $(x - \bar{x})(y - \bar{y}) = xy - x\bar{y} - \bar{x}y + \bar{x}\bar{y}$ and average each piece. Everything collapses to:
Careful: $\sum x_i y_i$ means multiply each pair first, then add up.
In a two-dimensional study on $25$ individuals, the means $\bar{x} = 8$ and $\bar{y} = 15$ have been obtained. Knowing that the sum of the products of the variables is…
In a two-dimensional study on $25$ individuals, the means $\bar{x} = 8$ and $\bar{y} = 15$ have been obtained. Knowing that the sum of the products of the variables is $\sum x_i y_i = 3200$, calculate the covariance $s_{xy}$.
Given the following table with three pairs of values corresponding to the variables $X$ and $Y$: | $X$ | 2 | 4 | 6 | |:---:|:---:|:---:|:---:| | $Y$ | 3 | 5 | 10 |…
Given the following table with three pairs of values corresponding to the variables $X$ and $Y$:
| $X$ | 2 | 4 | 6 |
|---|---|---|---|
| $Y$ | 3 | 5 | 10 |
Calculate the center of gravity $(\bar{x}, \bar{y})$ and the covariance of the distribution.
The temperature $X$ (in $^\circ\text{C}$) and the resistance $Y$ (in MPa) of a new plastic material have been measured in $5$ different tests, obtaining the following…
The temperature $X$ (in $^\circ\text{C}$) and the resistance $Y$ (in MPa) of a new plastic material have been measured in $5$ different tests, obtaining the following results:
| Temperature ($X$) | 10 | 20 | 30 | 40 | 50 |
|---|---|---|---|---|---|
| Resistance ($Y$) | 85 | 78 | 65 | 50 | 32 |
Calculate the covariance of this two-dimensional distribution and interpret its sign in the context of the problem.
Working from sums and means
Often a problem gives you summary numbers instead of the data. Use these links:
-
$\bar{x} = \dfrac{\sum x_i}{N}$ and $\bar{y} = \dfrac{\sum y_i}{N}$
-
$s_{xy} = \dfrac{\sum x_i y_i}{N} - \bar{x}\bar{y}$
-
Solving for the sum of products: $\sum x_i y_i = N\,(s_{xy} + \bar{x}\bar{y})$
The center of gravity of a two-dimensional distribution is $(5, 9)$. If the arithmetic mean of the products of the values of both variables is…
The center of gravity of a two-dimensional distribution is $(5, 9)$. If the arithmetic mean of the products of the values of both variables is $\frac{\sum x_i y_i}{N} = 42$, determine the value of the covariance.
For a set of $40$ two-dimensional data, it is known that $\bar{x} = 12$, $\bar{y} = 25$ and the covariance is $s_{xy} = -8,5$. Find the value of the sum of the products…
For a set of $40$ two-dimensional data, it is known that $\bar{x} = 12$, $\bar{y} = 25$ and the covariance is $s_{xy} = -8,5$. Find the value of the sum of the products $\sum x_i y_i$.
From a two-dimensional statistical variable $(X,Y)$ composed of $8$ observations, the following data are known: $\sum x_i = 40$, $\sum y_i = 64$, and…
From a two-dimensional statistical variable $(X,Y)$ composed of $8$ observations, the following data are known:
$\sum x_i = 40$, $\sum y_i = 64$, and $\sum x_i y_i = 280$.
Calculate the center of gravity and the covariance.
Solving for a missing piece
Since covariance is an ordinary formula, a missing number is just an unknown in an equation. Write $\bar{y}$ and $\sum xy$ in terms of the unknown, plug into the formula, and solve.
Another useful trick: what happens if you add one more point that sits exactly at the center of gravity? The means do not change, but $N$ grows by $1$ and $\sum xy$ grows by $\bar{x}\bar{y}$.
In a two-dimensional distribution of $3$ pairs of values, two of them are known: $(1, 2)$ and $(4, 6)$. The third pair is $(2, a)$, where $a$ is an unknown value. If it…
In a two-dimensional distribution of $3$ pairs of values, two of them are known: $(1, 2)$ and $(4, 6)$. The third pair is $(2, a)$, where $a$ is an unknown value. If it is known that the covariance of the distribution is $s_{xy} = 2$, set up an equation and find the value of $a$.
A set of $10$ pairs of two-dimensional data has means $\bar{x} = 6$ and $\bar{y} = 8$, and its covariance is $s_{xy} = 4$. If it is discovered that an eleventh pair of…
A set of $10$ pairs of two-dimensional data has means $\bar{x} = 6$ and $\bar{y} = 8$, and its covariance is $s_{xy} = 4$. If it is discovered that an eleventh pair of data is missing which coincides exactly with the center of gravity, that is, the pair $(6, 8)$, calculate the new covariance of the set of $11$ data.
Frequency tables
When the same pair appears several times, we use frequencies. A pair $(x_i, y_j)$ that appears $f_{ij}$ times contributes its product $f_{ij}$ times.
For the means, use the totals of rows and columns: $\bar{x} = \dfrac{\sum x_i f_{i\cdot}}{N}$ and $\bar{y} = \dfrac{\sum y_j f_{\cdot j}}{N}$.
Calculate the covariance of the following two-dimensional distribution expressed in a table of absolute frequencies $f_i$: | $X$ | $Y$ | $f_i$ | |:---:|:---:|:---:| | 1…
Calculate the covariance of the following two-dimensional distribution expressed in a table of absolute frequencies $f_i$:
| $X$ | $Y$ | $f_i$ |
|---|---|---|
| 1 | 4 | 10 |
| 5 | 8 | 10 |
A survey has been carried out on $20$ families about the number of vehicles they own ($X$) and the number of parking spaces they own ($Y$). The results are summarized in…
A survey has been carried out on $20$ families about the number of vehicles they own ($X$) and the number of parking spaces they own ($Y$). The results are summarized in the following two-way table:
| $X \backslash Y$ | 0 | 1 | 2 |
|---|---|---|---|
| 1 | 4 | 6 | 0 |
| 2 | 1 | 5 | 4 |
Calculate the center of gravity and the covariance $s_{xy}$.
A new drug has been tested on a group of patients. The variable $X$ represents the administered dose (in mg) and the variable $Y$ the reduction in blood pressure (in…
A new drug has been tested on a group of patients. The variable $X$ represents the administered dose (in mg) and the variable $Y$ the reduction in blood pressure (in mmHg). The results are shown in the following two-way table:
| $X \backslash Y$ | 5 | 10 | 15 |
|---|---|---|---|
| 10 | 3 | 2 | 0 |
| 20 | 1 | 4 | 1 |
| 30 | 0 | 2 | 5 |
Calculate the covariance of this distribution and explain what the result suggests about the efficacy of the drug.
Data from graphs, lists, and grouped intervals
Problems don't always hand you a neat table. Three common disguises:
A scatter plot. Read the coordinates of each point, write them as a table of pairs, then use the formula.
A list of pairs. Just apply the formula, as in the study-time example.
Grouped intervals. When $X$ is given in intervals like $[20, 40)$, replace each interval by its class mark, the midpoint, then treat the data as a frequency table.
Observe the following scatter graph representing four observations obtained in a laboratory experiment: From the integer coordinates of the points shown in the graph,…
Observe the following scatter graph representing four observations obtained in a laboratory experiment:
From the integer coordinates of the points shown in the graph, determine the table of values and calculate the covariance of the distribution.
In a study on screen time, the age of the respondents ($X$) has been grouped into intervals, relating it to the number of smart devices they own ($Y$): | Age ($X$) |…
In a study on screen time, the age of the respondents ($X$) has been grouped into intervals, relating it to the number of smart devices they own ($Y$):
| Age ($X$) | $[10, 20)$ | $[20, 30)$ | $[30, 40)$ |
|---|---|---|---|
| Devices ($Y$) | 3 | 4 | 2 |
| Frequency ($f_i$) | 15 | 25 | 10 |
Using the class marks for the variable $X$, calculate the covariance of the distribution.
In an economic study on the relationship between the inflation rate ($X$, in $\%$) and the unemployment rate ($Y$, in $\%$) of a country over $5$ consecutive years, the…
In an economic study on the relationship between the inflation rate ($X$, in $\%$) and the unemployment rate ($Y$, in $\%$) of a country over $5$ consecutive years, the following pairs of values were recorded: $(2, 8)$, $(3, 6)$, $(4, 5)$, $(5, 4)$, $(6, 2)$. Calculate the covariance and indicate whether the results support a direct or inverse relationship between both rates.
Shifting and rescaling the data
What happens to the covariance if you change units, or shift every value by a constant?
In a thermodynamics experiment, the covariance between the pressure and the volume of a gas under certain conditions is $s_{xy} = -15,4$. If, to facilitate the…
In a thermodynamics experiment, the covariance between the pressure and the volume of a gas under certain conditions is $s_{xy} = -15,4$. If, to facilitate the calculations, the researcher decides to add $2$ to all the pressure values and subtract $5$ from all the volume values, what will be the new value of the covariance?
In an architecture study, the covariance between the length of a beam $X$ (measured in meters) and its maximum deformation $Y$ (measured in millimeters) is…
In an architecture study, the covariance between the length of a beam $X$ (measured in meters) and its maximum deformation $Y$ (measured in millimeters) is $s_{xy} = 3,5$. If it is decided to express the length in centimeters ($1\text{ m} = 100\text{ cm}$) and the deformation in micrometers ($1\text{ mm} = 1000\,\mu\text{m}$), calculate the new value of the covariance.
A team of biologists has measured the weight $X$ (in kg) and the length $Y$ (in cm) of a reptile species, obtaining a covariance of $s_{xy} = 45$. For an international…
A team of biologists has measured the weight $X$ (in kg) and the length $Y$ (in cm) of a reptile species, obtaining a covariance of $s_{xy} = 45$. For an international publication, they decide to transform the data: the weight will be expressed in pounds ($1\text{ lb} = 2,2\text{ lb}$) and the length in meters ($1\text{ ft} = 100\text{ in}$). Furthermore, due to an adjustment of the measuring equipment, they subtract $0,5\text{ ft}$ from all the lengths. What will be the value of the covariance with the new units?
Combining variables and exact linear relationships
Some problems also use the variance of $X$ or $Y$. You can get it from sums with the same shortcut we used for covariance.
Notice that the covariance only needed $\sum x_i y_i$ and the means. If a problem lists sums of squares too, they are there for the variances, so pick the ones the question asks for.
Now covariance has three handy rules. Let $s_x^2$ be the variance of $X$ (with the same $N$ in the denominator).
Exact linear relationship. If every pair satisfies $y = mx + b$, then $y - \bar{y} = m(x - \bar{x})$, so
$$s_{xy} = \frac{\sum (x - \bar{x}) \cdot m(x - \bar{x})}{N} = m \cdot \frac{\sum (x - \bar{x})^2}{N} = m \, s_x^2.$$The covariance is the slope times the variance of $X$. The sign matches the sign of the slope.
Given a two-dimensional variable $(X,Y)$, it is known that there is an exact linear functional relationship given by the equation $y_i = -3x_i + 5$ for all pairs in the…
Given a two-dimensional variable $(X,Y)$, it is known that there is an exact linear functional relationship given by the equation $y_i = -3x_i + 5$ for all pairs in the distribution. Knowing that the variance of the variable $X$ is $s_x^2 = 4$, prove analytically and calculate the numerical value of the covariance $s_{xy}$.
In a company, the relationship between the employees' years of seniority ($X$) and their monthly salary in hundreds of dollars ($Y$) is studied. The following data are…
In a company, the relationship between the employees' years of seniority ($X$) and their monthly salary in hundreds of dollars ($Y$) is studied. The following data are known: $\bar{x} = 10$, $\bar{y} = 20$, the variance of the seniority is $s_x^2 = 16$ and the covariance is $s_{xy} = 24$. It is decided to create a "total assessment" index defined as $Z = X + Y$. Calculate the covariance between the seniority ($X$) and this new index ($Z$).
A marketing department analyzes the advertising expenditure $X$ (in thousands of dollars) and the sales generated $Y$ (in thousands of dollars) in $10$ different…
A marketing department analyzes the advertising expenditure $X$ (in thousands of dollars) and the sales generated $Y$ (in thousands of dollars) in $10$ different campaigns. The following sums are available:
$\sum x_i = 150$, $\sum y_i = 800$, $\sum x_i^2 = 2500$, $\sum y_i^2 = 70000$, $\sum x_i y_i = 12500$.
Calculate the original covariance. If for the next year it is decided that all advertising expenditures will increase by $10\%$ and the expected sales will increase by $20\%$, what will be the estimated covariance of the transformed data?
Limits of covariance
Covariance is useful, but it has three weak spots.
1. Its size depends on units. Weight in grams and height in cm might give $s_{xy} = 15{,}000$, and the same data in kg and m give $0.15$. The relationship is identical. So only the sign is directly meaningful. Measuring strength needs the correlation coefficient $r$, which removes the units.
2. A zero covariance doesn't mean "no relationship." It only means no linear trend. Take $(-1, 1)$, $(0, 0)$, $(1, 1)$. Here $\bar{x} = 0$ and $\bar{y} = \frac{2}{3}$, and $\sum xy = -1 + 0 + 1 = 0$, so $s_{xy} = 0 - 0 = 0$, yet $y = x^2$ exactly.
If two variables are independent, their covariance is $0$. But the reverse is false, as the parabola shows: $s_{xy} = 0$ does not prove independence.
3. One outlier can take over. Four clustered points $(1, 2)$, $(2, 1)$, $(3, 3)$, $(4, 2)$ have $\sum x = 10$, $\sum y = 8$, $\sum xy = 21$, so $s_{xy} = \frac{21}{4} - 2.5 \cdot 2 = 0.25$. Add a far-away point $(20, 20)$: now $\sum x = 30$, $\sum y = 28$, $\sum xy = 421$, and $s_{xy} = \frac{421}{5} - 6 \cdot 5.6 = 84.2 - 33.6 = 50.6$. One point multiplied the covariance by about $200$.
The trajectory of an object is analysed using $5$ points whose coordinates $(X,Y)$ are: $(-2, 4)$, $(-1, 1)$, $(0, 0)$, $(1, 1)$ and $(2, 4)$. Calculate the covariance…
The trajectory of an object is analysed using $5$ points whose coordinates $(X,Y)$ are: $(-2, 4)$, $(-1, 1)$, $(0, 0)$, $(1, 1)$ and $(2, 4)$.
Calculate the covariance of this two-dimensional distribution. In view of the result, can it be stated that the variables $X$ and $Y$ are statistically independent? Justify your answer by relating it to the graph.
A two-dimensional data set consists of the following $5$ strongly clustered points: $(1, 1)$, $(2, 2)$, $(2, 1)$, $(3, 2)$, $(3, 3)$; and an outlier: $(13, 15)$.…
A two-dimensional data set consists of the following $5$ strongly clustered points: $(1, 1)$, $(2, 2)$, $(2, 1)$, $(3, 2)$, $(3, 3)$; and an outlier: $(13, 15)$.
Calculate the covariance of the complete set of $6$ points. Next, calculate the covariance excluding the outlier and compare the results to explain the sensitivity of the covariance to extreme values.
Back to the start: for screen time versus sleep, the cloud slopes down, so we expect a negative covariance. We could only compare how strong that is with other studies once the units are removed (correlation, coming in the next section).