Correlation Coefficients

This lesson covers: 

  1. What correlation is
  2. Spearman's rank correlation for assessing relationships between two variables
  3. Pearson’s linear correlation for assessing relationships between two variables

What is correlation?

Correlation refers to the relationship between two variables.


The correlation can be:

  1. Positive - This is when both variables increase or decrease together, where a value near +1 indicates a strong positive correlation.
  2. Negative - This is when one variable increases as the other decreases, where a value near -1 suggests a strong negative correlation.
  3. Non-existent - This is when there is no correlation, indicated by a correlation coefficient close to 0.


A correlation coefficient of 1 indicates a perfect, positive linear correlation, where all points lie on a straight line.

There are two statistical tests you need to know that can determine correlation:

  1. Spearman's rank correlation - Determines if there is a correlation between two variables when one or both of them are not normally distributed.
  2. Pearson's linear correlation - Determines if there is a linear correlation between two variables that are normally distributed.

Spearman's rank correlation for assessing relationships between two variables

Spearman’s rank correlation coefficient is used to measure the strength and direction of association between two continuous variables that are not normally distributed.


The process for calculating Spearman's rank correlation is:

  1. Convert the raw data values of each variable into ranks from the smallest value to the largest value.
  2. If two values are the same for one variable, give them an average rank (e.g. if the two smallest values are 6 mm, they would both have the rank 1.5, and the next smallest value would have the rank 3).
  3. Determine the difference in ranks (d) for each pair of values.
  4. Square these rank differences (d2).
  5. Sum up all the squared rank differences.
  6. Calculate Spearman's rho (ρ).


Use the formula (this will be provided in an exam):

ρ=1n3n6d2


Where:

  • ρ= Spearman’s rank correlation coefficient
  • d2= sum of the squared differences of the ranks
  • n= number of pairs of data


You will most likely be given critical value tables that use the sample size, n, for this test, rather than needing to calculate degrees of freedom.


Then, compare ρ to a critical value at 5% significance level to determine the significance of the correlation:

  • ρ value near +1 indicates a strong positive correlation.
  • ρ value near -1 suggests a strong negative correlation.
  • ρ value around 0 implies there is no correlation.


It can be helpful to carry out the calculations for steps 1 to 4 in a table, for example:

SampleStem length (mm)Leaf width (mm)Rank: stem lengthRank: leaf widthRank difference (d)d2
17954106.53.512.25
273809900
320311100
423662.58-5.530.25
5675486.51.52.25
6644273416
739515411
8295345-11
9593662416
1023882.510-7.556.25

Worked example - Correlation of study time and test scores using Spearman's rank

The table below shows the study time and test scores of 10 students. The critical value at the 5% level for n = 10 is 0.600.

SampleStudy time (hours)Test score (%)
15.578
23.265
38.182
42.459
56.780
67.388
71.855
84.673
99.094
1010.590

Using Spearman's rank correlation coefficient, assess whether there is a significant correlation between study time and test scores.


Step 1: Equation

ρ=1n(n21)6d2


Step 2: Rank the data to calculate d2

rank the data for both variables from smallest to largest, using the average rank when two values are identical, and then calculate the rank difference (d) and d2

SampleStudy time (hours)Test score (%)Rank: study timeRank: test scoreRank difference (d)d2
15.5785500
23.2653300
38.1828711
42.4592200
56.7806600
67.38878-11
71.8551100
84.6734400
99.094910-11
1010.59010911

Step 3: Substitution and correct evaluation

ρ=1n(n21)6d2

sum of the squared differences of ranks (d2)=4

n=10

ρ=110(1021)6×4

ρ=199024

ρ=10.0242

ρ=0.976


Step 4: Determine significance and interpret result

the significance of the correlation coefficient is determined by comparing it to a critical value at a chosen significance level


the critical value at the 5% level for n = 10 is 0.648, so the correlation coefficient of 0.976 is much larger than the critical value


this means the correlation is significant at the 5% level, indicating a very strong positive correlation between study time and test scores that is unlikely to be due to chance

Pearson’s linear correlation for assessing relationships between two variables

Pearson's correlation coefficient (r) measures the strength and direction of the linear relationship between two continuous variables that are normally distributed.


The process for calculating Pearson’s linear correlation is:

  1. Calculate the mean of all the x values (xˉ).
  2. Calculate the mean of all the y values (yˉ).
  3. Calculate the standard deviation for x (sx) and y (sy):


sx=n1Σ(xxˉ)2

sy=n1Σ(yyˉ)2


  1. For each pair of data points, multiply the x and y values to calculate xy.
  2. Sum all the xy products to find the total (∑xy).
  3. Substitute the calculated values into a formula.


The formula to use is as follows (this will be provided in an exam):

r=(n1)sxsyxynxˉyˉ


Where:

  • r = correlation coefficient, representing the strength and direction of the linear relationship.
  • x, y = the variables being compared.
  • xˉ, yˉ = means of the variables.
  • sx, sy = standard deviations of the variables.
  • n = number of pairs of data.


  1. Calculate the degrees of freedom, which in Pearson’s linear correlation are n - 2.
  2. Compare r to a critical value at 5% significance level to determine the significance of the correlation.

Worked example - Calculating Pearson's correlation coefficient

Is there a correlation between the number of daisies and dandelions recorded in ten quadrats?

QuadratNumber of daisies (x)Number of dandelions (y)
11530
21225
31835
41020
52040
61122
71734
81428
91938
101326

Step 1: Equation

r=(n1)sxsyxynxˉyˉ


Step 2: Calculation of the means

xˉ=nx=10149=14.9

yˉ=ny=10298=29.8


Step 3: Construct table to calculate differences, squares, and product of x and y

Table showing calculations for Pearson's correlation coefficient including x, y, differences, squares, and product of x and y.

Step 4: Calculation of the standard deviations

sx=n1(xxˉ)2=9108.93.479

sy=n1(yyˉ)2=9413.66.779


Step 5: Substitution and correct evaluation

r=(n1)sxsyxynxˉyˉ

r=(101)×3.479×6.7794652(10×14.9×29.8)

r=9×3.479×6.77946524440.2

r=212.257211.8

r0.998 (to 3 s.f.)


Step 6: Determine significance and interpret result

the degrees of freedom (df) for Pearson's r are n2, which in this case is 102=8


the critical value for r with 8 degrees of freedom at a 5% significance level is approximately 0.632, according to the Pearson's r critical values table


as the r value of 0.998 is greater than 0.632, the result is statistically significant. There does seem to be a positive correlation between the number of daisies and dandelions in the quadrats