Skip to content

← Grade 12 Mathematics

Correlation and Regression

Unit 10 · Statistics and Probability

Hide the stories, facts, photos, activities and interactives, for revising before an exam
What this builds on from class
In this unit 5 sections
  1. 10.1 Correlation and its nature
  2. 10.2 Karl Pearson’s correlation coefficient
  3. 10.3 Rank correlation
  4. 10.4 Regression equation, regression lines of y on x and x on y
  5. Exercise

Climb from Kathmandu towards Nagarkot and the air gets cooler; go down to Chitwan and it gets hot. Higher means colder, and Nepal’s weather stations show it almost exactly: Jumla, at 2,363 m, has an average year of 13.1 °C, Biratnagar, at 72 m, 24.9 °C. Rain is another matter. Pokhara, at 827 m, gets 3,866 mm in an average year; Jumla, three times higher, 804 mm; Biratnagar, almost at sea level, 1,757 mm.

So here is this unit’s question: height decides the temperature; does it also decide the rain? “Decides” needs a number: how closely two quantities go together, their correlation, and the line that predicts one from the other, a regression line. The answer comes at the end of 10.4.
Heights, temperatures and rain: WMO Climatological Standard Normals 1991–2020, Nepal’s Department of Hydrology and Meteorology.

10.1 Correlation and its nature

What you need: the mean and the standard deviation of one set of numbers, σ=Σ(x−x‾)2n \sigma = \sqrt{\frac{\Sigma (x - \overline{x})^2}{n}} , dividing by n: Grade 11, Unit 15. This unit takes two numbers measured on each thing (a station’s height and its temperature, a student’s marks in two subjects), a bivariate set of pairs (x, y).

Seeing it: the scatter diagram

Plot each pair as a point, x across and y up: a scatter diagram. Its shape tells the nature of the correlation.

  • Positive correlation: the points rise to the right; larger x goes with larger y (a child’s age and height, a field’s fertilizer and its yield, up to a point).
  • Negative correlation: they fall to the right; larger x goes with smaller y (height and temperature, a phone’s price and how many are sold).
  • No correlation: no tilt at all; knowing x tells nothing about y.

It is perfect when every point lies on one straight line, and linear when the points gather round a straight line, as in this unit; points round a curve show a curvilinear relation, which this unit’s r does not measure. Correlation can be strong or weak: how tightly the points hug their line.

On a scatter diagram the points fall from top left to bottom right, close to a line. The correlation is:

Pick an answer to see why.

10.2 Karl Pearson’s correlation coefficient

Building r

Put a cross at the means (x, y). A point above and to the right of it, or below and to the left, has (x − x)(y − y) > 0: it votes for “together”. A point in the other two corners has a negative product and votes against. Adding the votes, Σ(x−x‾)(y−y‾) \Sigma (x - \overline{x})(y - \overline{y}) , gives a large positive total for a rising cloud, a large negative one for a falling cloud, and about 0 when the votes cancel. Divided by n it is the covariance, cov⁡(x,y)=1nΣ(x−x‾)(y−y‾) \operatorname{cov}(x, y) = \frac{1}{n}\Sigma (x - \overline{x})(y - \overline{y}) .

The covariance changes with the units (heights in meters give a total 100 times that in hundreds of meters), so divide by both standard deviations. That is Karl Pearson’s coefficient of correlation:
r=cov⁡(x,y)σxσy=Σ(x−x‾)(y−y‾)Σ(x−x‾)2 Σ(y−y‾)2 r = \frac{\operatorname{cov}(x, y)}{\sigma_x \sigma_y} = \frac{\Sigma (x - \overline{x})(y - \overline{y})}{\sqrt{\Sigma (x - \overline{x})^2 \, \Sigma (y - \overline{y})^2}}
(the ns cancel). When the means are not whole numbers, the sums of the data themselves are easier:
r=nΣxy−Σx ΣynΣx2−(Σx)2 nΣy2−(Σy)2 r = \frac{n\Sigma xy - \Sigma x \, \Sigma y}{\sqrt{n\Sigma x^2 - (\Sigma x)^2}\,\sqrt{n\Sigma y^2 - (\Sigma y)^2}}

  1. Σ(x−x‾)(y−y‾)=Σxy−y‾Σx−x‾Σy+nx‾ y‾=Σxy−Σx Σyn \Sigma (x - \overline{x})(y - \overline{y}) = \Sigma xy - \overline{y}\Sigma x - \overline{x}\Sigma y + n\overline{x}\,\overline{y} = \Sigma xy - \frac{\Sigma x \, \Sigma y}{n} (multiply out; Σx=nx‾ \Sigma x = n\overline{x} );
  2. in the same way Σ(x−x‾)2=Σx2−(Σx)2n \Sigma (x - \overline{x})^2 = \Sigma x^2 - \frac{(\Sigma x)^2}{n} , as in Grade 11’s short-cut for σ \sigma ;
  3. put these in the first form and multiply top and bottom by n.

Interpretation and properties

What r says (properties stated without proof, as the curriculum asks):

  1. −1 ≤ r ≤ 1. r = 1: perfect positive, every point on a rising line; r = −1: perfect negative; r = 0: no linear correlation.
  2. The sign gives the direction, the size the strength. A rough guide many books use: |r| ≥ 0.75 high, 0.5 ≤ |r| < 0.75 moderate, below 0.5 low (the cut-offs vary from book to book).
  3. r has no units, and is the same both ways: rxy=ryx r_{xy} = r_{yx} .
  4. r does not change with a change of origin or scale. If u=x−ah u = \frac{x - a}{h} and v=y−bk v = \frac{y - b}{k} with h, k > 0, then ruv=rxy r_{uv} = r_{xy} (if h and k have opposite signs, only the sign of r flips). Example 1 used this twice: heights in hundreds of meters, then deviations from the means.
  5. r2 r^2 , the coefficient of determination, is the share of the spread in y that the straight line accounts for: r = −0.996 gives r2=0.99 r^2 = 0.99 , so height accounts for about 99% of the difference in temperature between these stations.

Some older books also judge r by its probable error, P.E.=0.6745 1−r2n \text{P.E.} = 0.6745 \, \frac{1 - r^2}{\sqrt{n}} : if |r| is more than 6 P.E. the correlation is taken as significant (not chance), and if it is less than P.E. as not significant. It is meant for many pairs, not five, and CDC’s 2078 curriculum and model paper don’t ask it.

For some pairs, rxy=0.8 r_{xy} = 0.8 . The variables are changed to u=x−5010 u = \frac{x - 50}{10} and v=y−42 v = \frac{y - 4}{2} . Then ruv r_{uv} is:

Pick an answer to see why.

10.3 Rank correlation

Sometimes only an order can be given (two judges ranking dancers, a class ranked in two subjects), or one far-out value would swamp r. Then rank each variable, 1 for the smallest (or the largest, the same way for both), and use Spearman’s rank correlation coefficient:
ρ=1−6Σd2n(n2−1) \rho = 1 - \frac{6\Sigma d^2}{n(n^2 - 1)}
where d is the difference of a pair’s two ranks and n the number of pairs. It is Pearson’s r worked out on the ranks, so again −1≤ρ≤1 -1 \le \rho \le 1 : ρ=1 \rho = 1 when the two orders agree exactly (every d = 0), −1 when one is the other reversed. (Tied values share the mean of their ranks; this unit keeps to data without ties.)

Eight students are ranked in two subjects, and Σd2=0 \Sigma d^2 = 0 . Then:

Pick an answer to see why.

10.4 Regression equation, regression lines of y on x and x on y

The line of best fit

Correlation says how closely the points follow a line; regression finds the line, to estimate one variable from the other. For y = a + bx, each point misses the line by y − (a + bx) up or down. The line of regression of y on x is the one that makes the sum of the squares of these misses, Σ(y−a−bx)2 \Sigma (y - a - bx)^2 , least (the least squares line). Setting its derivatives with respect to a and b to zero gives the normal equations:
Σy=na+bΣx,Σxy=aΣx+bΣx2 \Sigma y = na + b\Sigma x, \qquad \Sigma xy = a\Sigma x + b\Sigma x^2
The first, divided by n, says y = a + bx: the line passes through the means. Taking it from the line and solving the pair for b gives the line in its usual form:
y−y‾=byx(x−x‾),byx=Σ(x−x‾)(y−y‾)Σ(x−x‾)2=nΣxy−ΣxΣynΣx2−(Σx)2=rσyσx y - \overline{y} = b_{yx}(x - \overline{x}), \qquad b_{yx} = \frac{\Sigma (x - \overline{x})(y - \overline{y})}{\Sigma (x - \overline{x})^2} = \frac{n\Sigma xy - \Sigma x\Sigma y}{n\Sigma x^2 - (\Sigma x)^2} = r\frac{\sigma_y}{\sigma_x}
byx b_{yx} , the regression coefficient of y on x, is the line’s slope: how much y changes, on average, for each unit of x. Grade 12 Computing’s Data, evidence and decisions finds the same line for all 15 stations in Python.

Two lines, not one

To estimate x from y, the misses that matter are across, x − (a′ + b′y), and making their squares least gives a different line, the line of regression of x on y:
x−x‾=bxy(y−y‾),bxy=Σ(x−x‾)(y−y‾)Σ(y−y‾)2=rσxσy x - \overline{x} = b_{xy}(y - \overline{y}), \qquad b_{xy} = \frac{\Sigma (x - \overline{x})(y - \overline{y})}{\Sigma (y - \overline{y})^2} = r\frac{\sigma_x}{\sigma_y}
The two lines (properties without proof):

  1. Both pass through (x, y): solving the two equations together gives the means.
  2. byx bxy=r2 b_{yx} \, b_{xy} = r^2 , so r=±byx bxy r = \pm\sqrt{b_{yx} \, b_{xy}} , with the sign the two coefficients share (they always have the same sign as r). Since r2≤1 r^2 \le 1 , the two coefficients can’t both be more than 1 in size.
  3. When r = ±1 the two lines are one line; when r = 0 they are y = y and x = x, at right angles. The closer |r| is to 1, the closer the lines.

Try it

Two regression lines, one station at a time

Nepal’s 15 WMO stations. The blue line is y on x, the red dashed one x on y, and they cross at the means; byx b_{yx} is shown per 100 m, bxy b_{xy} in meters per °C (or per mm). Drag a station, or switch to rain, and watch the lines open and close.

050010001500200025001014182226Height (m)Temperature (°C)
Height and:
Correlation, r
−0.995
byx
−0.487
bxy
−203.6

Every station has the same value: with no spread there is no correlation and no line to draw.

The stations lie close to a line, so the two regression lines almost close into one: |r| is near 1, and either line predicts well.

The two lines still cross at the means, but they have opened out: a moderate correlation, and each line now predicts something different.

The lines have opened out towards a cross, the blue one nearly flat and the red one steep: |r| is small, and height tells you little about the other number.

The regression line of y on x is y − 20 = 1.5(x − 8). The estimate of y when x = 10 is:

Pick an answer to see why.

Back to the rain

Height decides the temperature almost completely, and the rain hardly at all. For all 15 stations, a computer gives:

Height against Pearson’s r Spearman’s ρ \rho y on x
Temperature −0.995 −0.996 (r of the ranks: two stations tie) y = 25.45 − 0.487x (°C, x in 100 m)
Rain −0.22 −0.31 (Example 2) y = 1845 − 20.8x (mm)

For temperature, r2=0.99 r^2 = 0.99 : height accounts for 99% of the differences, and every one of the 15 stations lies within a degree of the line. A school at 1,500 m can expect an average year near 25.45−0.487×15≈18.1 25.45 - 0.487 \times 15 \approx 18.1 °C. For rain, r2=0.05 r^2 = 0.05 : height accounts for about 5%. The rest is where a place stands: Pokhara sits at the foot of the Annapurnas, where the monsoon air is forced up and drops its rain, while places sheltered behind high ridges get far less (the rain shadow). Pokhara alone pulls r about; the ranks, where its 3,866 mm counts only as “the wettest”, give −0.31. In the widget, switch to rain and drag Pokhara down to 1,800 mm: r becomes about −0.41.

Exercise

Choose the correct option

Karl Pearson’s correlation coefficient r always lies:

Pick an answer to see why.

Spearman’s rank correlation coefficient for n pairs is:

Pick an answer to see why.

r = 0 for a set of pairs means:

Pick an answer to see why.

byx=0.8 b_{yx} = 0.8 and bxy=0.45 b_{xy} = 0.45 . The correlation coefficient is:

Pick an answer to see why.

The two regression lines are x + 2y = 5 and 2x + 3y = 8. The means (x, y) are:

Pick an answer to see why.

When r = −1, the two regression lines:

Pick an answer to see why.

Heights are measured in meters and temperatures in °C, and r = −0.99. The heights are rewritten in kilometers. Then r becomes:

Pick an answer to see why.

Six pairs are ranked and Σd2=14 \Sigma d^2 = 14 . Spearman’s ρ \rho is:

Pick an answer to see why.

For ten pairs, Σ(x−x‾)2=40 \Sigma (x - \overline{x})^2 = 40 , Σ(y−y‾)2=90 \Sigma (y - \overline{y})^2 = 90 and Σ(x−x‾)(y−y‾)=48 \Sigma (x - \overline{x})(y - \overline{y}) = 48 . Then r is:

Pick an answer to see why.

Which pair cannot be the two regression coefficients byx b_{yx} , bxy b_{xy} of one set of data?

Pick an answer to see why.

The two regression lines are 3x + 2y = 26 and 6x + y = 31. The correlation coefficient is:

Pick an answer to see why.

Short questions

1.

Seven students’ hours of study in a week (x) and their marks out of 20 in a test (y):

x 1 2 3 4 5 6 7
y 9 8 10 12 11 13 14
  • a.Find Karl Pearson’s correlation coefficient. (3 marks)
  • b.Interpret it, and say whether it shows that study raises marks. (2 marks)
Answer
2.
x 4 6 8 10 12
y 20 17 13 12 8
  • a.Find the regression line of y on x, and estimate y when x = 7. (3 marks)
  • b.Find the regression line of x on y. (2 marks)
Answer
3.

Eight students’ marks in Mathematics and English:

Student A B C D E F G H
Mathematics 78 65 92 55 70 84 48 60
English 70 72 81 50 58 76 45 63

Find the rank correlation coefficient and interpret it. (5 marks)

Hint
Answer
4.
  • a.From byx=rσyσx b_{yx} = r\frac{\sigma_y}{\sigma_x} and bxy=rσxσy b_{xy} = r\frac{\sigma_x}{\sigma_y} , show that r2=byx bxy r^2 = b_{yx} \, b_{xy} , and that byx b_{yx} , bxy b_{xy} and r have the same sign. (2 marks)
  • b.The two regression lines of some data are 8x − 10y + 66 = 0 and 40x − 18y = 214. Find x, y and r. (3 marks)
Hint
Answer

Long question

5.

Five more of DHM’s stations, height x in hundreds of meters (to the nearest 100 m) and the average year’s temperature y in °C:

Station Simara Nepalgunj Dhankuta Kathmandu Taplejung
x 1 2 12 13 17
y 24.4 24.6 19.9 19.3 16.8
  • a.Draw a scatter diagram and say what kind of correlation it shows. (1 mark)
  • b.Find Karl Pearson’s correlation coefficient. (3 marks)
  • c.Find the regression line of y on x, and estimate the average temperature at 1,000 m. (2 marks)
  • d.Find the regression line of x on y, and estimate the height where the average year is 20 °C. Why is this not found from the line in c? (2 marks)
Answer

Project work

Where these facts come from
  • Heights, average annual temperatures and annual rain of Nepal’s 15 WMO stations (the opening, Examples 1–3, Question 5, the widget, Back to the rain): WMO Climatological Standard Normals 1991–2020, Nepal, sent by Nepal’s Department of Hydrology and Meteorology and published by NOAA’s National Centers for Environmental Information (public domain), as used in Grade 12 Computing, Unit 5; heights rounded to the nearest 100 m for hand working are ours. The Pokhara and Jumla explanation of the rain: Going Further 6–8, Why is Pokhara so wet and Mustang so dry?.
  • Galton’s sweet peas (about 1875), reversion and regression, his index of correlation (1888), and Pearson’s debt to Natural Inheritance: MacTutor, “Francis Galton”; Pearson’s Mathematical Contributions to the Theory of Evolution (1893–1912), with the correlation coefficient: MacTutor, “Karl Pearson”; Spearman’s paper of 1904, and the short formula holding only without ties: Wikipedia, “Spearman’s rank correlation coefficient”, read November 2026.
  • The study hours, marks and the other practice data in the exercise are ours.
  • The unit’s items and project work: CDC, Secondary Education Curriculum 2078, Mathematics, Grades 11–12, 5.1 and Grade 12 sample projects 8 and 9; the marks and the model paper: CDC, Specification Grid 2078, Mathematics (Mat. 402), Grade 12, and its Model question 2080; IOE, BE/BArch Entrance Syllabus 2083, Mathematics 7.2.

Found a mistake? Please tell us.