Correlation

When two sets of data are strongly linked together we say they have a High Correlation.

The word Correlation is made of Co- (meaning "together"), and Relation

A correlation is assumed to be linear (following a line).

correlation examples

Correlation can have a value:

The value shows how good the correlation is (not how steep the line is), and if it is positive or negative.

Example: Ice Cream Sales

The local ice cream shop keeps track of how much ice cream they sell versus the temperature on that day. Here are their figures for the last 12 days:

Ice Cream Sales vs Temperature
Temperature °C Ice Cream Sales
14.2° $215
16.4° $325
11.9° $185
15.2° $332
18.5° $406
22.1° $522
19.4° $412
25.1° $614
23.4° $544
18.1° $421
22.6° $445
17.2° $408

And here is the same data as a Scatter Plot:

scatter plot ice cream 1

We can easily see that warmer weather and higher sales go together. The relationship is good but not perfect.

In fact the correlation is 0.9575 ... see at the end how I calculated it.

Also try the Correlation Calculator.

Correlation Is Not Good at Curves

The correlation calculation only works properly for straight line relationships.

Our Ice Cream Example: there has been a heat wave!

It gets so hot that people aren't going near the shop, and sales start dropping.

Here is the latest graph:

scatter ice cream plot 2

The correlation value is now 0: "No Correlation" ... !

The calculated correlation value is 0 (I worked it out), which means "no correlation".

But we can see the data follows a nice curve that reaches a peak around 25° C.

But the correlation calculation is not "smart" enough to see this.

Moral of the story: make a Scatter Plot, and look at it!
You may see a relationship that the calculation does not.

"Correlation Is Not Causation"

A common saying is "Correlation Is Not Causation".

What it really means is that a correlation does not prove one thing causes the other:

There can be many reasons the data has a good correlation.

Example: Sunglasses vs Ice Cream

Our Ice Cream shop finds how many sunglasses were sold by a big store for each day and compares them to their ice cream sales:

scatter ice cream plot 3

The correlation between Sunglasses and Ice Cream sales is high

Does this mean that sunglasses make people want ice cream?

Example: Poor suburbs are more likely to have high pollution.

Why?

  • Do poor people make pollution?
  • Are polluted suburbs the only place poor people can afford?
  • Is it a common link, such as factories with low paying jobs and lots of pollution?

Example: A Real Case!

study sick

A few years ago a survey of employees found a strong positive correlation between "Studying an external course" and Sick Days.

Does this mean:

  • Studying makes them sick?
  • Sick people study a lot?
  • Or did they lie about being sick so they can study more?

Without further research we can't be sure why.

How To Calculate

How did I calculate the value 0.9575 at the top?

I used "Pearson's Correlation". There is software that can calculate it, such as the CORREL() function in Excel or LibreOffice Calc ...

... but here is how to calculate it yourself:

Let us call the two sets of data "x" and "y" (in our case Temperature is x and Ice Cream Sales is y):

Here is how I calculated the first Ice Cream example (values rounded to 1 or 0 decimal places):

correlation calculations

As a formula it is:

correlation formula

Where:

You probably won't have to calculate it like that, but at least you know it is not "magic", but simply a routine set of calculations.

Note for Programmers

You can calculate it in one pass through the data. Just sum up x, y, x2, y2 and xy (no need for a or b calculations above) then use the formula:

correlation formula onepass

Other Methods

There are other ways to calculate a correlation coefficient, such as "Spearman's rank correlation coefficient".

 

3072, 3776, 8757, 8758, 8759, 8760, 3080, 3081, 3810, 3811