Scatter plots and the correlation coefficient ·… | StemPy Lab
Course 17.3·Lesson 1 of 3
Scatter plots and the correlation coefficient
A scatter plot shows two measurements for each person or thing as one point. The correlation coefficient r measures how closely the points follow a straight line, from −1 to 1
Lesson 1 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
read a scatter plot and describe the direction, the strength and the shape of a pattern;
find the correlation coefficient r from data or from sums;
say what r does and does not tell you, and find a rank correlation.
Two measurements for each student
A teacher records, for five students, the hours x spent studying for a test and the mark y in the test. Each student gives a pair (x,y). Plot each pair as a point, with x across and y up. The picture is a scatter plot. The data in one variable, from the earlier lessons, gave one number per student. Now each student gives two, and we ask whether they move together.
Look for three things.
Direction. Do the points rise (positive association) or fall (negative association) as you go right?
Strength. Do the points lie close to a line, or are they scattered?
Shape. Is the pattern a straight line, or does it bend?
Four small scatter plots in a row, each with eight points. The first rises steadily from lower left to upper right and is labelled strong positive, r = 0.99. The second falls steadily from upper left to lower right and is labelled strong negative, r = -0.99. The third is a cloud with no direction and is labelled none, r = -0.03. The fourth follows a U-shaped curve, the parabola y = x squared with its lowest point in the middle, and is labelled not a line, r = 0.
The correlation coefficient
To put a number on the strength of a straight-line pattern, first find the means xˉ and yˉ and then three sums:
Sxx=∑(x−xˉ)2,Syy=∑(y−yˉ)2,Sxy=∑(x−xˉ)(y−yˉ).
The correlation coefficient, also called the product moment correlation coefficient and written r, is
r=SxxSyySxy=σxσycov(x,y).
Here cov(x,y)=nSxy is the covariance, and σx, σy are the standard deviations from the first course. When the data are given as totals, an equivalent form uses three combinations of the totals:
A=n∑xy−∑x∑y,B=n∑x2−(∑x)2,C=n∑y2−(∑y)2.
Then
r=BCA.
For the five students, with hours 1,2,3,4,5 and marks 50,56,58,66,70, we find xˉ=3 and yˉ=60. Then Sxx=10, Syy=256 and Sxy=50. So r=10×25650=0.988. The points lie very close to a rising line.
What r tells you
−1≤r≤1. A value near 1 means a strong rising line, near −1 a strong falling line, and near 0 no straight-line pattern. If r=±1, every point lies exactly on a line.
r has no unit. Changing the unit of x or of y does not change it. If every x is changed to ax+b with a>0, r is unchanged. If a<0, the sign of r flips.
r is the same whichever variable is called x.
r measures only straight-line association. The U-shaped points in the last panel of the picture have r=0, although y is exactly x2.
Common words for ∣r∣ are strong (above about 0.8), moderate and weak (below about 0.5), but books differ on the borders. A question will not rely on them without giving them.
Rank correlation
Sometimes the data are ranks, as when two judges place five dancers in order. Spearman's rank correlation coefficient is
rs=1−n(n2−1)6∑d2,
where d is the difference between the two ranks of the same item. It is the product moment r of the ranks, if no ranks tie. A-Level Further Maths uses it. For ranks 1,2,3,4,5 and 2,1,3,5,4 the differences are −1,1,0,−2,1, so ∑d2=7 and rs=1−12042=0.65.
Practise with new numbers
Try it in Python
The program finds Sxx, Syy and Sxy for the hours and the marks, then r, and checks it against numpy.
Common mistakes
Forgetting the square root in the denominator.
Reading r=0 as no relationship. It only means no straight-line relationship.
Reading a high r as proof of cause. Two things can move together because of a third.
Giving r a unit. It has none.
Using r for a curved pattern. Look at the scatter plot first.
Remember these
r=SxxSyySxy and −1≤r≤1.
r has no unit and measures only straight-line association.
Changing the units or the zero of x or y leaves ∣r∣ unchanged.
rs=1−n(n2−1)6∑d2 for ranks.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Describe in words the scatter plot of the hours of sunshine against the number of umbrellas sold in a town, if the umbrellas sell more on cloudy days.
For some data, Sxx=25, Syy=16 and Sxy=−15. Find r.
Every height in centimetres is changed to metres, and every mass in kilograms is changed to grams. What happens to r?
The five points with x=−2,−1,0,1,2 lie exactly on y=x2, so y=4,1,0,1,4. Find r and explain it.
Two judges rank four dancers as 1,2,3,4 and 2,1,4,3. Find the rank correlation.
References
OpenStax, Introductory Statistics, Chapter 12, sections on scatter plots and the correlation coefficient.
A-Level and IB texts name r the product moment correlation coefficient. AP Statistics also calls it the correlation. It is not in the NCERT Class XI or XII mathematics books.
Enroll free in Correlation and Regression
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.