We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 10 Days of Statistics
  4. Day 7: Spearman's Rank Correlation Coefficient
  5. Tutorial

Day 7: Spearman's Rank Correlation Coefficient

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Spearman's Rank Correlation Coefficient

We have two random variables, and :



If and denote the respective ranks of each data point, then the Spearman's rank correlation coefficient, , is the Pearson correlation coefficient of and .

Example



:


So,
Similarly,

equals the Pearson correlation coefficient of and , meaning that .

Special Case: and Don't Contain Duplicates

Here, is the difference between the respective values of and .

Proof

Let's define be the rank of and be the rank of . Both and are permutations of set , because data sets and contain no duplicates in this special case.

Mean of and :



Standard Deviation of and :

So,


Calculating :

We know that:
So,


Covariance of and :



Spearman's Rank Correlation Coefficient:
We know that the Spearman's rank correlation coefficient of and is equal to the Pearson correlation coefficient of and . So,



tutorial details


Tutorial By

AvimanyuSingh

Need Help?


View discussions
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy