Comparison of Pearson vs Spearman Correlation Coefficients

Sereno 04 Sep, 2024
6 min read

Introduction

Pearson and Spearman correlation coefficients are two widely used statistical measures when measuring the relationship between variables. The Pearson correlation coefficient assesses the linear relationship between variables, while the Spearman correlation coefficient evaluates the monotonic relationship.

In this article, we will delve into a comprehensive comparison of these correlation coefficients for correlation analysis. We will explore their calculation methods, interpretability, strengths, and limitations. Understanding the differences between Pearson and Spearman correlation coefficients is crucial for selecting the appropriate measure based on the nature of the data and the research objectives.

Also, we are covering the difference between Pearson and Spearman correlation. We will explore Pearson vs Spearman, highlighting their unique applications, and discuss when to use Pearson correlation vs Spearman in data analysis.

Let’s explore the difference between Pearson vs Spearman Correlation Coefficients!

What is Correlation?

Correlation is a bivariate statistical measure that tells us about the association between the two variables. It describes how one variable behaves if there is some change in the other variable.

If the two variables are increasing or decreasing in parallel then they have a positive correlation between them and if one of the variables is increasing and another one is decreasing then they have a negative correlation with each other. If the change of one variable has no effect on another variable then they have a zero correlation between them.

Importance of Correlation coefficients

Correlation coefficients are like universal translators in the world of machine learning and data science. They help us understand the language between variables – how much, and in what direction, they change together.

Here’s why they’re crucial:

  • Finding patterns: Uncovering hidden relationships between features, like what factors influence house prices.
  • Picking the best features: Choosing the most relevant data for machine learning models, making them more efficient.
  • Understanding models: Seeing how models interpret data and identifying potential issues.

What is Spearman Correlation used for?

Spearman’s correlation, another name for Spearman’s rank correlation coefficient, is a statistical tool that dives into how two variables are connecte. Instead of assuming a straight line relationship, it assesses how much one variable tends to go up or down as the other changes along with it. This change, called a monotonic relationship, can be either a steady increase together or a consistent decrease together. Even if the data doesn’t form a perfect line, Spearman’s correlation can reveal this underlying trend.

Pearson vs Spearman Correlation

AspectPearson Correlation CoefficientSpearman Correlation Coefficient
PurposeMeasures linear relationshipsMeasures monotonic relationships
AssumptionsVariables are normally distributed, linear relationshipVariables have monotonic relationship, no assumptions on distribution
Calculation MethodBased on covariance and standard deviationsBased on ranked data and rank order
Range of Values-1 to 1-1 to 1
InterpretationStrength and direction of linear relationshipStrength and direction of monotonic relationship
Sensitivity to OutliersSensitive to outliersLess sensitive to outliers
Data TypesAppropriate for interval and ratio dataAppropriate for ordinal variables and non-normally distributed data
Sample SizeThe Pearson correlation coefficient isn’t the most efficient choice for small sample sizes.This method works well with smaller samples and doesn’t require normality assumptions.
UsageAssessing linear associations, parametric testsAssessing monotonic associations, non-parametric tests

What is Pearson Correlation Coefficient?

The Pearson correlation coefficient also known as linear correlation is a statistical measure that quantifies the strength and direction of a linear relationship between two continuous variables. It ranges from -1 to 1, with values close to -1 indicating a strong negative linear relationship, values close to 1 indicating a strong positive linear relationship, and 0 indicating no linear relationship.

What is Spearman Correlation Coefficient?

The Spearman correlation coefficient is a statistical measure that assesses the strength and direction of a monotonic relationship between two variables. It ranks the data rather than relying on their actual values, making it suitable for non-normally distributed or ordinal data. It ranges from -1 to 1, where values close to -1 or 1 indicate a strong monotonic relationship, and 0 indicates no monotonic relationship. Spearman correlation is valuable for detecting and quantifying associations when linear relationships are not assumed or when dealing with ranked or ordinal scale.

Example of Spearman’s Rank Correlation

Spearman’s Rank Correlation:

Let’s say we want to determine the relationship between the study time (in hours) and the exam scores (out of 100) of a group of students. We have the following data for five students:

StudentStudy Time (hours)Exam Score
A1075
B860
C1285
D655
E970

First, we rank the study time and exam scores separately:

StudentStudy Time (hours)Rank (Study Time)Exam ScoreRank (Exam Score)
A103753
B84605
C121851
D65556
E92704

Now, we calculate the differences between the ranks for each pair of data points:

  • P=Rank of Study Time−Rank of Exam Score, Di​=Rank of Study Timei​−Rank of Exam Scorei
StudentDi
A0
B-1
C0
D-1
E-2

Next, we square each (Di)​ value:

Student2Di2​
A0
B1
C0
D1
E4

The sum of ��2Di2​ is 0+1+0+1+4=60+1+0+1+4=6.

Spearman's Rank Correlation coefficient (ρ)

So, the Spearman’s Rank Correlation coefficient (ρ) between study time and exam scores is 0.7, indicating a strong positive correlation.

Practical application of correlation using R?

Determining the association between Girth and Height of Black Cherry Trees (Using the existing dataset “trees” which is already present in r and can be accessed by typing the name of the dataset, list of all the data set can be seen by using the command data() )

Below is the code to compute the correlation:

Loading the Dataset

> data <- trees
> head(data, 3)
  Girth Height Volume
1   8.3     70   10.3
2   8.6     65   10.3
3   8.8     63   10.2

Creating a Scatter Plot Using ggplot2 Library

> library(ggplot2)
> ggplot(data, aes(x = Girth, y = Height)) + geom_point() + 
+   geom_smooth(method = "lm", se =TRUE, color = 'red')

Test for Assumptions of Correlation

Here two assumptions are checked which need to be fulfilled before performing the correlation (Shapiro test, which is test to check the input variable is following the normal distribution or not, is used to check whether the variables i.e. Girth and Height are normally distributed or not)

> shapiro.test(data$Girth)

	Shapiro-Wilk normality test

data:  data$Girth
W = 0.94117, p-value = 0.08893

> shapiro.test(data$Height)

	Shapiro-Wilk normality test

data:  data$Height
W = 0.96545, p-value = 0.4034

p–value is greater than 0.05, so we can assume the normality

Correlation

> cor(data$Girth,data$Height, method = "pearson")
[1] 0.5192801
> cor(data$Girth,data$Height, method = "spearman")
[1] 0.4408387

Testing the Significance of the Correlation

For Pearson

> Pear <- cor.test(data$Girth, data$Height, method = 'pearson')
> Pear

	Pearson's product-moment correlation

data:  data$Girth and data$Height
t = 3.2722, df = 29, p-value = 0.002758
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.2021327 0.7378538
sample estimates:
      cor 
0.5192801

For Spearman

> Spear <- cor.test(data$Girth, data$Height, method = 'spearman')
> Spear

	Spearman's rank correlation rho

data:  data$Girth and data$Height
S = 2773.4, p-value = 0.01306
alternative hypothesis: true rho is not equal to 0
sample estimates:
      rho 
0.4408387

Since the p-value is less than 0.05 (For Pearson it is 0.002758 and for Spearman, it is 0.01306, we can conclude that the Girth and Height of the trees are significantly correlated for both the coefficients with the value of 0.5192801 (Pearson) and 0.4408387 (Spearman).

Pearson vs Spearman Correlation – Final Verdict

As we can see both the correlation coefficients give the positive correlation value for Girth and Height of the trees but the value given by them is slightly different because Pearson correlation coefficients measure the linear relationship between the variables while Spearman correlation coefficients measure only monotonic relationships, relationship in which the variables tend to move in the same/opposite direction but not necessarily at a constant rate whereas the rate is constant in a linear relationship.

At the end of this article , I want to say that hope you like the article of pearson and spearman correlation. You get a clear information of pearson vs spearman correlation and its difference .I hope you found this explanation helpful and now have a clearer understanding of the difference between Pearson and Spearman correlation. If you have any further questions, feel free to ask!

Frequently Asked Questions

Q1. What is the purpose of Pearson and Spearman correlation?

A. The Pearson and Spearman correlation measures the strength and direction of the relationship between variables. Pearson correlation assesses linear relationships, while Spearman correlation evaluates monotonic relationships.

Q2. When should I use Spearman correlation?

A. Spearman correlation is useful when the relationship between variables is not strictly linear but can be described by a monotonic function. It is commonly used when dealing with ordinal or non-normally distributed data.

Q3. Are Spearman correlations more powerful than Pearson correlations?

It is inaccurate to say that Spearman correlations are inherently more powerful than Pearson correlations. The choice between the two depends on the specific characteristics and assumptions of the data and the research question being addressed.

Q4. Is Spearman always higher than Pearson?

A. Spearman correlation is not always higher than Pearson correlation. The magnitude and direction of the correlation can differ between the two measures, especially when the relationship between variables is nonlinear or influenced by outliers. The choice between the two should be based on the data and the research objectives.

Q5. How Spearman different from Kendall?

A. Kendall’s tau and Spearman’s rank are similar correlation coefficients for non-normal data. Here’s the key difference:
Kendall’s tau: More robust to outliers, better for small samples (uses concordant/discordant pairs).
Spearman’s rank: Might give slightly higher values, but more sensitive to outliers (uses rank differences).

Sereno 04 Sep, 2024

Frequently Asked Questions

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

Responses From Readers

Clear

Abhijit Dey
Abhijit Dey 25 Jun, 2023

Thanks a lot. This is really useful.