Covariance and Correlation
Jayden's basketball coach says, "The more you practice free throws, the more you make." Is that true for your team? How strong is the pattern? And can you trust a prediction like "practice 30 hours a week and you'll never miss"? In this page we turn "tends to go up together" into numbers you can calculate, compare, and use to predict.
Relationships and scatter plots
Some relationships have an exact formula. The perimeter of a square is $P = 4s$, and 3 lb of apples at $\$1.50$ per pound always cost exactly $\$4.50$. These are functional relationships: one value of $x$ gives exactly one value of $y$.
Most real-life relationships are not like that. Two students can study the same number of hours and get different quiz scores. There is still a trend (more study time tends to mean higher scores), but no exact formula. This is a statistical relationship, also called a correlation.
The direction of the cloud tells you the sign of the correlation.
-
Positive correlation: $y$ tends to increase when $x$ increases (temperature and air-conditioner use).
-
Negative correlation: $y$ tends to decrease when $x$ increases (age of a phone and its resale price).
-
Uncorrelated: no visible trend (shoe size and math grade).
In statistics, it is essential to distinguish between a relationship that can be calculated with an exact formula and one that only shows a trend. State whether the…
In statistics, it is essential to distinguish between a relationship that can be calculated with an exact formula and one that only shows a trend. State whether the relationship between the following pairs of variables is functional or statistical (correlation):
- a) The number of hours a 12th grade student spends playing video games and their grade in the Economics exam.
- b) The side length of a square and its perimeter.
- c) The gallons of gas put into a car and the total amount to pay at the gas station.
- d) The height of a teenager and their body weight.
The direction of the relationship between two variables tells us how one varies when the other changes. Determine whether there is a positive correlation, negative…
The direction of the relationship between two variables tells us how one varies when the other changes. Determine whether there is a positive correlation, negative correlation, or if the variables are uncorrelated in the following cases:
- a) The number of absences from class and the final grade for the course.
- b) A person's shoe size and their average grade in Math.
- c) The outside temperature in summer and the energy consumption of air conditioning units.
- d) The age in years of a mobile phone and its resale price on the second-hand market.
Observe the following scatter plot representing the relationship between weekly training hours ($X$) and the points scored in a season by a group of basketball players…
Observe the following scatter plot representing the relationship between weekly training hours ($X$) and the points scored in a season by a group of basketball players ($Y$).
Based on the shape of the scatter plot, answer:
- a) Is it a direct or inverse relationship?
- b) How would you describe the strength of the correlation: strong or weak?
- c) What sign do you expect the covariance $\sigma_{xy}$ to have for this data?
Strength of a cloud and a line by eye
Direction is only half the story. Look at how tightly the points hug an imaginary line: that is the strength of the correlation.
When the cloud looks linear, you can sketch a line of best fit by eye. Draw a line through the middle of the cloud, with about as many points above it as below, passing near the point whose coordinates are the means of $X$ and $Y$. Then use it to estimate. Later on this page you will learn how to compute that line exactly.
We compare two scatter plots represented in the following charts. Both show a direct relationship between the variables. a) In which of the two graphs are the points…
We compare two scatter plots represented in the following charts. Both show a direct relationship between the variables.
- a) In which of the two graphs are the points closer to a possible regression line?
- b) Which of the two will have a correlation coefficient $r$ closer to $1$?
- c) If in graph A the value of $r$ is $1$, what reasonable value (between $0$ and $1$) could you assign to graph B?
A small study has been carried out on the number of books read per year ($X$) and the grade in English ($Y$) of five students. The data obtained is as follows:…
A small study has been carried out on the number of books read per year ($X$) and the grade in English ($Y$) of five students. The data obtained is as follows:
$(2, 5), (4, 6), (5, 8), (7, 8), (10, 9)$
Draw a scatter plot for this data in your notebook. Then, draw a freehand line of best fit (regression line) and comment on whether the relationship appears linear to you.
The centroid and the covariance
To measure a trend with a number, start with the "middle" of the cloud.
Now draw a vertical line at $\bar{x}$ and a horizontal line at $\bar{y}$. They cut the plot into four quadrants. For a point in the upper right, both $x - \bar{x}$ and $y - \bar{y}$ are positive, so their product is positive. In the lower left both are negative, so the product is positive again. In the other two quadrants the product is negative.
If most points sit in the "+" quadrants, the average of these products is positive and the variables rise together. If most sit in the "−" quadrants, the average is negative. That average is the covariance.
In the same way, the variance is $s_x^2 = \dfrac{\sum x_i^2}{n} - \bar{x}^2$ and $s_y^2 = \dfrac{\sum y_i^2}{n} - \bar{y}^2$.
The "center of gravity" of a bivariate distribution is the point formed by the means of both variables, denoted as $(\bar{x}, \bar{y})$. A group of friends has recorded…
The "center of gravity" of a bivariate distribution is the point formed by the means of both variables, denoted as $(\bar{x}, \bar{y})$. A group of friends has recorded the time they spend on social media per day ($X$, in minutes) and their mobile phone battery life ($Y$, in hours):
$(45, 18), (60, 16), (90, 14), (120, 10), (150, 7)$
Calculate the coordinates of the center of gravity of this distribution.
The covariance $\sigma_{xy}$ informs us about the direction of the joint variation of two variables. Without performing all the complex calculations, observe the…
The covariance $\sigma_{xy}$ informs us about the direction of the joint variation of two variables. Without performing all the complex calculations, observe the following data relating the temperature of a soft drink ($X$, in $^\circ C$) and the time it has been out of the fridge ($Y$, in minutes):
| Time ($Y$) | 5 | 10 | 15 | 20 | 25 |
|---|---|---|---|---|---|
| Temperature ($X$) | 6 | 9 | 13 | 18 | 22 |
- a) As time increases, does the temperature tend to increase or decrease?
- b) Justify, according to your previous answer, whether the covariance will be positive, negative, or zero.
An e-sports club wishes to analyze whether there is a relationship between the weekly hours its players dedicate to individual training ($X$) and their accuracy index in…
An e-sports club wishes to analyze whether there is a relationship between the weekly hours its players dedicate to individual training ($X$) and their accuracy index in competitive matches ($Y$), measured out of 100. The data for a sample of 6 players are as follows:
| Training hours ($X$) | 10 | 15 | 12 | 20 | 8 | 18 |
|---|---|---|---|---|---|---|
| Accuracy index ($Y$) | 72 | 81 | 75 | 92 | 68 | 88 |
For this study:
-
Represent the scatter plot associated with this two-dimensional distribution.
-
Calculate the center of gravity of the distribution.
-
Determine the covariance $s_{xy}$ and interpret the sign obtained in the context of the problem.
Covariance from a two-way frequency table
Sometimes the data come as a two-way table of joint frequencies $f_{ij}$ (how many individuals have $X = x_i$ and $Y = y_j$). The row totals form the marginal distribution of $X$. The column totals form the marginal distribution of $Y$. If data are grouped in intervals, use the class midpoints as the values.
The table below shows 15 band members. $X$ is daily practice (1, 2, or 3 hours) and $Y$ is the rating at an audition (1 = low, 3 = high).
| $X \backslash Y$ | 1 | 2 | 3 | Total |
|---|---|---|---|---|
| 1 | 4 | 1 | 0 | 5 |
| 2 | 1 | 3 | 1 | 5 |
| 3 | 0 | 1 | 4 | 5 |
| Total | 5 | 5 | 5 | 15 |
A survey was carried out on the number of children ($X$) and the number of bedrooms in the home ($Y$) in an apartment building. The results are presented in the…
A survey was carried out on the number of children ($X$) and the number of bedrooms in the home ($Y$) in an apartment building. The results are presented in the following joint frequency table (two-way table):
| $X \setminus Y$ | 1 | 2 | 3 |
|---|---|---|---|
| 0 | 5 | 3 | 0 |
| 1 | 2 | 8 | 4 |
| 2 | 0 | 3 | 10 |
-
Find the marginal distributions of $X$ and $Y$.
-
Calculate the marginal mean of children ($\bar{x}$) and the marginal mean of bedrooms ($\bar{y}$).
-
Is there a dependence between the two variables? Reason your answer by observing the frequencies in the table.
The heights of a sample of couples (man, woman) have been organized in the following two-way table (data in cm): | Man ($X$) \ Woman ($Y$) | [150, 160) | [160, 170) |…
The heights of a sample of couples (man, woman) have been organized in the following two-way table (data in cm):
| Man ($X$) \ Woman ($Y$) | [150, 160) | [160, 170) | [170, 180) |
|---|---|---|---|
| [165, 175) | 4 | 2 | 0 |
| [175, 185) | 1 | 6 | 3 |
| [185, 195) | 0 | 2 | 5 |
Using the class midpoints:
- a) Calculate the covariance of the distribution.
- b) Calculate the Pearson correlation coefficient.
- c) Is there a strong relationship between the heights of the members of the couple in this sample?
Changing units: what happens to the covariance
What if you measure time in minutes instead of hours, or add bonus points to every score? A linear change has a simple effect on the covariance.
Variances behave similarly: $s_{x'}^2 = a^2 s_x^2$, so $s_{x'} = |a|\, s_x$.
A sociological study analyzes the relationship between the number of books read per year ($X$) and the score in a mental agility test ($Y$). The covariance is $12,5$. By…
A sociological study analyzes the relationship between the number of books read per year ($X$) and the score in a mental agility test ($Y$). The covariance is $12,5$. By doubling the number of books read by all respondents and adding 5 points to everyone in the mental agility test, you are asked to:
- a) Reason what happens to the new covariance $\sigma'_{xy}$.
- b) If the original correlation coefficient was $r = 0,75$, what will the new coefficient $r'$ be after the changes? Justify your answer analytically.
- c) Will the reliability of the predictions change after these modifications to the data?
Pearson's correlation coefficient
To remove the units, divide the covariance by both standard deviations.
A rough guide: $|r|$ above $0.8$ is strong, between $0.5$ and $0.8$ moderate, and below about $0.3$ weak. Context matters, so treat these cutoffs as a rule of thumb. $r = 1$ or $r = -1$ means all points lie exactly on a line.
The Pearson correlation coefficient, $r$, is a dimensionless measure that ranges within a specific interval. From the following values, state which ones are not possible…
The Pearson correlation coefficient, $r$, is a dimensionless measure that ranges within a specific interval. From the following values, state which ones are not possible for a correlation coefficient and explain why:
- a) $r = 0,85$
- b) $r = -1,2$
- c) $r = 2,5$
- d) $r = -0,4$
- e) $r = 0$
Match each of the following scatter plots with the value of the Pearson correlation coefficient ($r$) that corresponds to it with reasoning: Values of $r$: $-0,92$;…
Match each of the following scatter plots with the value of the Pearson correlation coefficient ($r$) that corresponds to it with reasoning:
Values of $r$: $-0,92$; $0,05$; $0,65$; $1$.
In a study on the price of daily menus ($X$) and the distance to the city center ($Y$) in miles, the following measures have been obtained for a sample of 50…
In a study on the price of daily menus ($X$) and the distance to the city center ($Y$) in miles, the following measures have been obtained for a sample of 50 restaurants:
-
Mean of the prices: $\$\bar{x} = 12,5$
-
Mean of the distances: $\bar{y} = 3,2$ miles
-
Standard deviation of the price: $\$sx = 2,1$
-
Standard deviation of the distance: $s_y = 1,4$ miles
-
Covariance: $s_{xy} = -2,35$
Calculate the Pearson correlation coefficient. If a restaurant decides to increase the price of all its menus by $\$2$ due to inflation, how would this change affect the value of the correlation coefficient? Justify your answer based on the properties of this parameter.
The coefficient of determination
A streaming music application analyzes the relationship between the age of its users ($X$) and the number of different artists they listen to per month ($Y$). The…
A streaming music application analyzes the relationship between the age of its users ($X$) and the number of different artists they listen to per month ($Y$). The following sums are known for a sample of $n = 10$ users:
$$\sum x_i = 240 \quad \sum y_i = 150 \quad \sum x_i^2 = 6200 \quad \sum y_i^2 = 2850 \quad \sum x_i y_i = 3100$$-
Calculate the Pearson correlation coefficient.
-
Determine the coefficient of determination $R^2$ and interpret its meaning: what percentage of the variation in the number of artists listened to is explained by the user's age?
Regression lines
Now the exact version of the "line by eye."
Reading a regression line. The slope is the predicted change in $y$ for each increase of 1 in $x$. Here, each extra practice hour goes with about $0.6$ more shots made. The $y$-intercept is the prediction at $x = 0$. Here it is $4$, but the data only cover 2 to 9 hours, so the intercept is outside what we observed. If the intercept makes no sense in context (a parcel weighing $0$ pounds, say), treat it as just part of the line.
The other line. If you want to predict $X$ from $Y$, use the regression line of $X$ on $Y$. It is a different line:
$$x - \bar{x} = \frac{s_{xy}}{s_y^2}\,(y - \bar{y})$$An organic farmer observes the relationship between the amount of natural fertilizer used ($X$, in pounds) and the potato yield ($Y$, in pounds). The data obtained is…
An organic farmer observes the relationship between the amount of natural fertilizer used ($X$, in pounds) and the potato yield ($Y$, in pounds). The data obtained is summarized in the following table:
| $X$ | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| $Y$ | 12 | 18 | 25 | 28 | 32 |
-
Calculate the regression line of $Y$ on $X$.
-
What yield would be expected if $3,5$ pounds of fertilizer were used?
-
Is the previous prediction reliable? Justify your answer by calculating the correlation coefficient.
A courier company studies the relationship between the weight of parcels ($X$, in pounds) and the shipping cost ($Y$, in $\$…
A courier company studies the relationship between the weight of parcels ($X$, in pounds) and the shipping cost ($Y$, in $\$$). After calculating the parameters, they find that the regression line of $Y$ on $X$ is $y = 1,5x + 4,2$ and the correlation coefficient is $r = 0,98$.
-
State whether the relationship between weight and cost is direct or inverse.
-
Explain what the value $1,5$ means in the context of the problem (slope of the line).
-
If a parcel weighs $0$ pounds (an empty parcel or a very light envelope), what cost does the line predict? Does this value make physical sense?
-
Calculate the coefficient of determination and comment on the quality of the linear fit.
A video game company wants to predict the monthly expenditure on microtransactions ($Y$, in dollars) of its players based on their weekly hours of play ($X$). The…
A video game company wants to predict the monthly expenditure on microtransactions ($Y$, in dollars) of its players based on their weekly hours of play ($X$). The statistics department has obtained the following parameters:
$\bar{x} = 15$; $\bar{y} = 22$; $s_x^2 = 25$; $s_y^2 = 144$; $\sigma_{xy} = 48$
- a) Find the equation of the regression line of $Y$ on $X$.
- b) A player claims to spend $\$50$ a month. Use the regression line of $X$ on $Y$ to estimate how many weekly hours they play.
- c) Which of the two estimations (predicting the expenditure from the hours or predicting the hours from the expenditure) seems more logical to you in this context? Do they have the same mathematical reliability?
Slopes, $r$, and the two lines
Both regression lines are built from the same covariance, so they are tied together.
If $|r| = 1$ the two lines coincide. If $r = 0$ they are perpendicular (one horizontal, one vertical).
The two regression lines of a bivariate variable are: Regression line of $Y$ on $X$: $y = 0,85x + 12,4$ Regression line of $X$ on $Y$: $x = 0,72y + 5,1$ Given that the…
The two regression lines of a bivariate variable are:
-
Regression line of $Y$ on $X$: $y = 0,85x + 12,4$
-
Regression line of $X$ on $Y$: $x = 0,72y + 5,1$
Given that the variance of the variable $X$ is $s_x^2 = 16$, calculate:
-
The Pearson correlation coefficient $r$.
-
The covariance $s_{xy}$ of the distribution.
-
The coordinates of the center of gravity $(\bar{x}, \bar{y})$.
A Math retake exam has been taken. It is observed that the relationship between the grades of the first exam ($X$) and those of the second ($Y$) follows a linear trend.…
A Math retake exam has been taken. It is observed that the relationship between the grades of the first exam ($X$) and those of the second ($Y$) follows a linear trend. It is known that:
-
$\bar{x} = 4$; $\bar{y} = 6$
-
The two regression lines intersect forming a very small angle, and it has been calculated that the product of their slopes is $0,81$.
-
Both slopes are positive.
- a) Find the Pearson correlation coefficient and state what percentage of the grade of the second exam is explained by the grade of the first.
- b) If the standard deviation of $X$ is half that of $Y$, find the equation of the regression line of $Y$ on $X$.
- c) If a student got a $2$ in the first exam, what grade is estimated for them in the second?
A data analyst for a streaming* platform is studying the relationship between the time a user spends watching trailers ($X$, in minutes) and the time they spend watching…
A data analyst for a streaming platform is studying the relationship between the time a user spends watching trailers ($X$, in minutes) and the time they spend watching full content ($Y$, in minutes). After analyzing thousands of profiles, they have determined that the equations of the two regression lines are:
-
Regression line of $Y$ on $X$: $y = 1,2x + 45$
-
Regression line of $X$ on $Y$: $x = 0,3y - 12$
From this information, solve:
- a) Calculate the arithmetic means of both variables, $\bar{x}$ and $\bar{y}$.
- b) Determine the Pearson correlation coefficient, $r$, and interpret the degree of relationship between the two variables.
- c) If a user has spent 10 minutes watching trailers, what is the expected content viewing time? Is this prediction reliable? Reason the answer based on the coefficient of determination.
Putting it all together
Real problems give you different pieces of information, and your job is to recover what is missing. All the tools fit together:
| You know | You can find |
|---|---|
| Raw data or sums | $\bar{x}, \bar{y}$, variances, $s_{xy}$, then $r$ and the lines |
| $r$, $s_x$, $s_y$ | $s_{xy} = r\, s_x s_y$ |
| $s_{xy}$ and a variance | A slope: $m_{yx} = s_{xy}/s_x^2$ |
| Both regression lines | $r^2 = m_{yx}\, m_{xy}$ and the centroid (solve the system) |
| One line and $r$ | The ratio $s_y/s_x = m_{yx}/r$ |
Back to the start. For Jayden's team, $r \approx 0.88$: a strong positive linear relationship, and the line $y = 0.6x + 4$ accounts for about $77\%$ of the variation in shots made. So the coach is right that practice goes with better shooting. But with only five players, and with predictions only safe inside the 2-to-9-hour range, "30 hours means a perfect score" is extrapolation, and the correlation alone does not prove that practice is the cause.
In a study on the performance of electric scooter batteries, the ambient temperature ($X$, in $^\circ C$) and the actual range achieved ($Y$, in miles) are analyzed. The…
In a study on the performance of electric scooter batteries, the ambient temperature ($X$, in $^\circ C$) and the actual range achieved ($Y$, in miles) are analyzed. The following data are known:
-
The variance of the temperature is $s_x^2 = 16$.
-
The regression line of the range on the temperature is $y = -0,85x + 42$.
-
The coefficient of determination is $R^2 = 0,7225$.
Calculate:
- a) The covariance between the temperature and the range.
- b) The standard deviation of the range, $s_y$.
- c) What would happen to the correlation coefficient if we decided to measure the temperature in degrees Fahrenheit using the transformation $F = 1,8X + 32$? Justify your answer based on the properties of correlation.
The relationship between the investment in R&D ($X$, in millions of $) and the net profit ($Y$, in millions of $) of 10 technology companies is investigated. The…
The relationship between the investment in R&D ($X$, in millions of $) and the net profit ($Y$, in millions of $) of 10 technology companies is investigated. The following sums have been obtained:
$\sum x_i = 100$; $\sum y_i = 160$; $\sum x_i^2 = 1100$; $\sum y_i^2 = 2800$; $\sum x_i y_i = 1720$
- a) Calculate the center of gravity of the distribution.
- b) Find the Pearson correlation coefficient.
- c) Determine the equation of the regression line of $Y$ on $X$.
- d) If a company decides not to invest anything in R&D ($x = 0$), what profit is it estimated to have? Comment on the validity of this estimation outside the data range.
Given the regression lines $y = -2x + 10$ and $x = -0,4y + 4$, reason whether the following statements are true or false, proving it by calculating the corresponding…
Given the regression lines $y = -2x + 10$ and $x = -0,4y + 4$, reason whether the following statements are true or false, proving it by calculating the corresponding parameters:
- a) The correlation between the variables is positive because both slopes have the same sign.
- b) The center of gravity of the distribution is the point $(3, 4)$.
- c) The variables have a perfect functional dependence.
- d) The variance of $Y$ is greater than the variance of $X$.