Back to homeMathematics · Algebra 2 · Change subject
Start for free
Algebra 2 · Mathematics
Statistics · Statistics

Covariance and Correlation

Before you start, make sure you know: Representation on the plane (Math 8 (Pre-Algebra))

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.

Three scatter plots: points rising (positive correlation), points falling (negative correlation), and points with no pattern (no correlation) Positive Negative No 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).

Practice★☆☆Not started
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):

  1. a) The number of hours a 12th grade student spends playing video games and their grade in the Economics exam.
  2. b) The side length of a square and its perimeter.
  3. c) The gallons of gas put into a car and the total amount to pay at the gas station.
  4. d) The height of a teenager and their body weight.
Solve
Practice★☆☆Not started
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:

  1. a) The number of absences from class and the final grade for the course.
  2. b) A person's shoe size and their average grade in Math.
  3. c) The outside temperature in summer and the energy consumption of air conditioning units.
  4. d) The age in years of a mobile phone and its resale price on the second-hand market.
Solve
Practice★☆☆Not started
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$).

0 2 4 6 8 10 12 10 20 30 40 Training hours (X) Points scored (Y)

Based on the shape of the scatter plot, answer:

  1. a) Is it a direct or inverse relationship?
  2. b) How would you describe the strength of the correlation: strong or weak?
  3. c) What sign do you expect the covariance $\sigma_{xy}$ to have for this data?
Solve

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.

Two rising scatter plots: a narrow band of points close to a line (strong correlation) and a wide scatter of points (weak correlation) Strong: narrow band Weak: wide scatter

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.

Practice★☆☆Not started
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.

Graph A x y Graph B x y
  1. a) In which of the two graphs are the points closer to a possible regression line?
  2. b) Which of the two will have a correlation coefficient $r$ closer to $1$?
  3. c) If in graph A the value of $r$ is $1$, what reasonable value (between $0$ and $1$) could you assign to graph B?
Solve
Practice★☆☆Not started
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.

Solve

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.

Scatter plot split into four quadrants by lines through the means: upper-right and lower-left quadrants have positive products, the other two negative (x̄, ȳ) +− +−

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$.

Practice★☆☆Not started
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.

Solve
Practice★☆☆Not started
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
  1. a) As time increases, does the temperature tend to increase or decrease?
  2. b) Justify, according to your previous answer, whether the covariance will be positive, negative, or zero.
Solve
Practice★★☆Not started
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:

  1. Represent the scatter plot associated with this two-dimensional distribution.

  2. Calculate the center of gravity of the distribution.

  3. Determine the covariance $s_{xy}$ and interpret the sign obtained in the context of the problem.

Sₓᵧ > 0 5 10 15 20 25 Training hours (X) 60 70 80 90 100 Accuracy index (Y) x̄ ȳ G(x̄, ȳ)
Solve

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
Practice★★☆Not started
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
  1. Find the marginal distributions of $X$ and $Y$.

  2. Calculate the marginal mean of children ($\bar{x}$) and the marginal mean of bedrooms ($\bar{y}$).

  3. Is there a dependence between the two variables? Reason your answer by observing the frequencies in the table.

Solve
Practice★★★Not started
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:

  1. a) Calculate the covariance of the distribution.
  2. b) Calculate the Pearson correlation coefficient.
  3. c) Is there a strong relationship between the heights of the members of the couple in this sample?
Solve

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$.

Practice★★★Not started
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:

  1. a) Reason what happens to the new covariance $\sigma'_{xy}$.
  2. b) If the original correlation coefficient was $r = 0,75$, what will the new coefficient $r'$ be after the changes? Justify your answer analytically.
  3. c) Will the reliability of the predictions change after these modifications to the data?
Solve

Pearson's correlation coefficient

To remove the units, divide the covariance by both standard deviations.

Number line from -1 to 1 for the correlation coefficient: -1 is a perfect negative line, 0 is no linear relationship, 1 is a perfect positive line −101 −0.50.5 perfectnegative line no linearrelationship perfectpositive line

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.

Practice★☆☆Not started
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:

  1. a) $r = 0,85$
  2. b) $r = -1,2$
  3. c) $r = 2,5$
  4. d) $r = -0,4$
  5. e) $r = 0$
Solve
Practice★★☆Not started
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$.

A B C D
Solve
Practice★★☆Not started
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.

Solve

The coefficient of determination

A bar representing all the variation in Y, with 64 percent explained by the line and 36 percent left unexplained, for r equal to 0.8 all the variation in Y (r = 0.8) explained: 64% unexplained: 36% r² = 0.64
Practice★★☆Not started
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$$
  1. Calculate the Pearson correlation coefficient.

  2. 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?

Solve

Regression lines

Now the exact version of the "line by eye."

Scatter plot of hours of practice versus free throws made with the regression line of y on x and the regression line of x on y crossing at the centroid (x̄, ȳ) = (5, 7) y on xx on y hours of practice per week shots made (of 10)

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})$$
Practice★★☆Not started
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
  1. Calculate the regression line of $Y$ on $X$.

  2. What yield would be expected if $3,5$ pounds of fertilizer were used?

  3. Is the previous prediction reliable? Justify your answer by calculating the correlation coefficient.

Solve
Practice★★☆Not started
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$.

  1. State whether the relationship between weight and cost is direct or inverse.

  2. Explain what the value $1,5$ means in the context of the problem (slope of the line).

  3. 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?

  4. Calculate the coefficient of determination and comment on the quality of the linear fit.

2 4 6 8 Weight X (lb) 5 10 15 20 Cost Y ($) Δx = 2 lb Δy = $3 m = 1.5 y = $4.20 (Fixed cost, x=0) y = 1.5x + 4.2 r = 0.98 R² = 0.96
Solve
Practice★★★Not started
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$

  1. a) Find the equation of the regression line of $Y$ on $X$.
  2. 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.
  3. 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?
Solve

Slopes, $r$, and the two lines

Both regression lines are built from the same covariance, so they are tied together.

The two regression lines cross at the centroid; the smaller the angle between them, the stronger the correlation (x̄, ȳ) y on xx on y smaller angle between the lines: stronger correlation

If $|r| = 1$ the two lines coincide. If $r = 0$ they are perpendicular (one horizontal, one vertical).

Practice★★☆Not started
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:

  1. The Pearson correlation coefficient $r$.

  2. The covariance $s_{xy}$ of the distribution.

  3. The coordinates of the center of gravity $(\bar{x}, \bar{y})$.

10 20 30 40 50 60 10 20 30 40 50 60 X Y x̄ ȳ (x̄, ȳ) y = 0.85x + 12.4 x = 0.72y + 5.1 s²ₓ = 16
Solve
Practice★★★Not started
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.

  1. 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.
  2. b) If the standard deviation of $X$ is half that of $Y$, find the equation of the regression line of $Y$ on $X$.
  3. c) If a student got a $2$ in the first exam, what grade is estimated for them in the second?
Exam 1 Grade (X) Exam 2 Grade (Y) 2 4 6 8 10 2 4 6 8 10 Y on X X on Y (4, 6) Center of gravity x=2 y=2.4
Solve
Practice★★★Not started
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:

  1. a) Calculate the arithmetic means of both variables, $\bar{x}$ and $\bar{y}$.
  1. b) Determine the Pearson correlation coefficient, $r$, and interpret the degree of relationship between the two variables.
  1. 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.
0 2 4 6 8 12 10 30 40 50 60 70 80 57 Time on trailers (X) [min] Time on content (Y) [min] y = 1.2x + 45 (Y on X) x = 0.3y - 12 (X on Y) (x̄, ȳ) x̄ ≈ 2.34 ȳ ≈ 47.81 Prediction (x=10)
Solve

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.

Practice★★★Not started
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:

  1. a) The covariance between the temperature and the range.
  2. b) The standard deviation of the range, $s_y$.
  3. 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.
Solve
Practice★★★Not started
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$

  1. a) Calculate the center of gravity of the distribution.
  2. b) Find the Pearson correlation coefficient.
  3. c) Determine the equation of the regression line of $Y$ on $X$.
  4. 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.
Solve
Practice★★★Not started
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:

  1. a) The correlation between the variables is positive because both slopes have the same sign.
  2. b) The center of gravity of the distribution is the point $(3, 4)$.
  3. c) The variables have a perfect functional dependence.
  4. d) The variance of $Y$ is greater than the variance of $X$.
X Y 2 4 6 8 10 0 2 4 6 8 10 12 y = −2x + 10 x = −0.4y + 4 (3, 4) CG (0, 10)
Solve

Summary

See all the exercises in this section