Pearson’s Correlation Coefficient

One number from minus one to one.

One number for a scatter plot

Pearson’s product-moment correlation coefficient, r, measures how closely the points of a scatter plot follow one straight line. It is always between −1 and 1.

If every point lies on one rising line, r = 1. If every point lies on one falling line, r = −1. Those are the two extremes, and nothing goes past them.

Direction from the sign

r is built from the deviations from the two means, x − x̄ and y − ȳ. A point above both means, or below both, has two deviations of the same sign, and their product is positive. A point above one mean and below the other gives a negative product.

Add the products over every point, and the total is Sxy = Σ(x − x̄)(y − ȳ). When most points rise together, the positive products win and Sxy is positive. When they fall, Sxy is negative. When neither wins, Sxy is near 0.

Then r = Sxy/√(Sxx × Syy), where Sxx = Σ(x − x̄)² and Syy = Σ(y − ȳ)². Dividing by √(Sxx × Syy) is what keeps r between −1 and 1.

Five points worked

Take the five points (1, 2), (3, 5), (5, 4), (7, 8) and (9, 7): hours studied across, score up the side. The means are x̄ = 25/5 = 5 and ȳ = 26/5 = 5.2.

The x deviations are −4, −2, 0, 2 and 4. The y deviations are −3.2, −0.2, −1.2, 2.8 and 1.8. Their products are 12.8, 0.4, 0, 5.6 and 7.2, so Sxy = 26.

The squared x deviations add up to Sxx = 16 + 4 + 0 + 4 + 16 = 40, and the squared y deviations to Syy = 10.24 + 0.04 + 1.44 + 7.84 + 3.24 = 22.8.

So r = 26/√(40 × 22.8) = 26/√912 = 26/30.20 = 0.861: a strong positive correlation. The points rise from left to right, but they do not sit on one line, so r is less than 1.

hours studiedscore

The five points (1, 2), (3, 5), (5, 4), (7, 8) and (9, 7). They rise from left to right with some scatter, and r = 0.861.

The same sums from totals

With many points, the three sums are quicker from five totals: Sxx = Σx² − (Σx)²/n, Syy = Σy² − (Σy)²/n and Sxy = Σxy − (Σx)(Σy)/n.

For the five points, Σx = 25, Σy = 26, Σx² = 165, Σy² = 158 and Σxy = 156. Then Sxx = 165 − 625/5 = 40, Syy = 158 − 676/5 = 22.8 and Sxy = 156 − 650/5 = 26, the same as before.

Strength from the size

The sign of r gives the direction and its size gives the strength. An r of 0.9 or −0.9 is strong: the points lie close to a line. An r of 0.5 is moderate, and an r of 0.1 is weak, hardly different from a shapeless cloud.

r is unit-free. If the hours were recorded in minutes instead, every x deviation would be 60 times as large, Sxy and √(Sxx) would both be multiplied by 60, and r would still be 0.861.

r = 0.96gradient 1gradientscatter

r = 0.96 measures how tightly the points hug a line, not how steep it is: add scatter and r falls whatever the gradient

Set the scatter to 0 and flatten the line

Twenty points scattered about a line. One handle sets the gradient of the line and the other the scatter about it. Set the scatter to 0 and r is exactly 1, however flat the line; add scatter and r falls, whatever the gradient.

r = 0 exactly

A shapeless cloud, (1, 7), (3, 2), (5, 9), (7, 4) and (9, 6), has x̄ = 5 and ȳ = 5.6. Its products of deviations are −5.6, 7.2, 0, −3.2 and 1.6, which add up to 0, so r = 0.

The arch (1, 1), (3, 6), (5, 8), (7, 6) and (9, 1) is anything but shapeless. But with x̄ = 5 and ȳ = 4.4, its products are 13.6, −3.2, 0, 3.2 and −13.6, which also add up to 0, so r = 0 here too.

The rising half cancels the falling half exactly. r measures how well one straight line fits. An r near 0 means no straight-line relationship; it does not mean no relationship. Look at the scatter plot before trusting r.

water givencrop

The arch (1, 1), (3, 6), (5, 8), (7, 6) and (9, 1). The crop depends closely on the water given, yet r = 0, because no straight line fits it.

The usual mistakes

Reading the direction backwards. Points that rise from left to right give a positive r, and points that fall give a negative one.

Reading r as the gradient. A nearly flat line with every point on it has r = 1; r measures how tightly the points follow a line, not how steep the line is.

Putting raw sums into the formula. 156/√(165 × 158) = 0.966 is not r; the sums must first be measured about the means.

Taking r = 0 to mean the two measurements are unrelated. The arch has r = 0 and a clear pattern.

Solar panels on a school roof

In the application below, ten days of sunshine and electricity are given only as five totals. Sxx, Syy and Sxy come from the totals, and r from those three.

Worked example: Solar Panels on a School Roof, with Pearson's r Found from the Summary Sums

Question A school records, on 10 days, the hours of sunshine x and the electricity y kWh generated by the solar panels on its roof. The results give ∑ x = 60, ∑ y = 150, ∑ x2 = 400, ∑ y2 = 2340 and ∑ xy = 951. (a) Find Sxx, Syy and Sxy. (b) Calculate Pearson's product-moment correlation coefficient, and describe the correlation.

  1. 1.Measure the squares about the mean by subtracting (∑ x)2n: Sxx = ∑ x2 − (∑ x)2n = 400 − 60210 = 400 − 360 = 40.

    -101rSxx = 400 − 60 × 60/10= 400 − 360 = 40
    -101rSxx = 400 − 60 × 60/10= 400 − 360 = 40
    Sxx = ∑ x2 − (∑ x)2n = 400 − 360 = 40. The scale shows where r must fall, between −1 and 1.
  2. 2.In the same way, Syy = 2340 − 150210 = 2340 − 2250 = 90 and Sxy = ∑ xy − ∑ x ∑ yn = 951 − 60 × 15010 = 951 − 900 = 51.

    -101rSyy = 2340 − 150 × 150/10 = 90Sxy = 951 − 60 × 150/10 = 51
    -101rSyy = 2340 − 150 × 150/10 = 90Sxy = 951 − 60 × 150/10 = 51
    Syy = 2340 − 2250 = 90 and Sxy = 951 − 900 = 51.
  3. 3.(a) Sxx = 40, Syy = 90 and Sxy = 51.

    -101rSxx = 40Syy = 90Sxy = 51
    -101rSxx = 40Syy = 90Sxy = 51
    (a) Sxx = 40, Syy = 90 and Sxy = 51.
  4. 4.Divide Sxy by the square root of the product of the other two: r = Sxy√Sxx Syy = 51√40 × 90 = 51√3600 = 5160 = 0.850.

    -101r = 0.850rr = 51/√(40 × 90) = 51/√3600= 51/60 = 0.850
    -101r = 0.850rr = 51/√(40 × 90) = 51/√3600= 51/60 = 0.850
    r = 51√40 × 90 = 5160 = 0.850, placed on the scale.
  5. 5.(b) r = 0.850 is positive and close to 1, so there is strong positive linear correlation: on sunnier days the panels generate more electricity. Check: r lies between −1 and 1, as every correlation coefficient must.

    -101r = 0.850rr = 0.850, close to 1strong positive correlation
    -101r = 0.850rr = 0.850, close to 1strong positive correlation
    (b) r = 0.850 lies close to 1: strong positive linear correlation between sunshine and electricity.

Answer: (a) Sxx = 40, Syy = 90, Sxy = 51; (b) r = 0.850, strong positive linear correlation

Common mistakes

  • Putting the raw sums into the formula, 951√400 × 2340 = 0.983. The sums must first be measured about the means, which is what subtracting (∑ x)2n and ∑ x ∑ yn does.
  • Confusing (∑ x)2 with ∑ x2. (∑ x)2 = 602 = 3600 is the square of the total, while ∑ x2 = 400 is the total of the squares.

More correlation and regression problems, worked step by step →

Practice Pearson’s Correlation Coefficient in the app