• Descriptive
    • Moments
    • Concentration
    • Central Tendency
    • Variability
    • Stem-and-Leaf Plot
    • Histogram & Frequency Table
    • Data Quality Forensics
    • Conditional EDA
    • Quantiles
    • Kernel Density Estimation
    • Normal QQ Plot
    • Bootstrap Plot

    • Multivariate Descriptive Statistics
  • Distributions
    • Binomial Probabilities
    • Geometric Probabilities
    • Negative Binomial Probabilities
    • Hypergeometric Probabilities
    • Multinomial Probabilities
    • Dirichlet
    • Poisson Probabilities

    • Exponential
    • Gamma
    • Erlang
    • Weibull
    • Rayleigh
    • Maxwell-Boltzmann
    • Lognormal
    • Pareto
    • Inverse Gamma
    • Inverse Chi-Square

    • Beta
    • Power
    • Beta Prime (Inv. Beta)
    • Triangular

    • Normal (area)
    • Logistic
    • Laplace
    • Cauchy (standard)
    • Cauchy (location-scale)
    • Gumbel
    • Fréchet
    • Generalized Extreme Value

    • Normal RNG
    • ML Fitting
    • Tukey Lambda PPCC
    • Box-Cox Normality Plot
    • Noncentral t
    • Noncentral F
    • Sample Correlation r

    • Empirical Tests
  • Hypotheses
    • Theoretical Aspects of Hypothesis Testing
    • Bayesian Inference
    • Minimum Sample Size

    • Empirical Tests
    • Multivariate (pair-wise) Testing
  • Models
    • Manual Model Building
    • Guided Model Building
  • Time Series
    • Time Series Plot
    • Decomposition
    • Exponential Smoothing

    • Blocked Bootstrap Plot
    • Mean Plot
    • (P)ACF
    • VRM
    • Standard Deviation-Mean Plot
    • Spectral Analysis
    • ARIMA

    • Cross Correlation Function
    • Granger Causality
  1. Descriptive Statistics & Exploratory Data Analysis
  2. 72  Rank Correlation
  • Preface
  • Getting Started
    • 1  Introduction
    • 2  Why Do We Need Innovative Technology?
    • 3  Basic Definitions
    • 4  The Big Picture: Why We Analyze Data
  • Introduction to Probability
    • 5  Definitions of Probability
    • 6  Jeffreys’ axiom system
    • 7  Bayes’ Theorem
    • 8  Sensitivity and Specificity
    • 9  Naive Bayes Classifier
    • 10  Law of Large Numbers

    • 11  Problems
  • Probability Distributions
    • 12  Bernoulli Distribution
    • 13  Binomial Distribution
    • 14  Geometric Distribution
    • 15  Negative Binomial Distribution
    • 16  Hypergeometric Distribution
    • 17  Multinomial Distribution
    • 18  Poisson Distribution

    • 19  Uniform Distribution (Rectangular Distribution)
    • 20  Normal Distribution (Gaussian Distribution)
    • 21  Gaussian Naive Bayes Classifier
    • 22  Chi Distribution
    • 23  Chi-squared Distribution (1 parameter)
    • 24  Chi-squared Distribution (2 parameters)
    • 25  Student t-Distribution
    • 26  Fisher F-Distribution
    • 27  Exponential Distribution
    • 28  Lognormal Distribution
    • 29  Gamma Distribution
    • 30  Beta Distribution
    • 31  Weibull Distribution
    • 32  Pareto Distribution
    • 33  Inverse Gamma Distribution
    • 34  Rayleigh Distribution
    • 35  Erlang Distribution
    • 36  Logistic Distribution
    • 37  Laplace Distribution
    • 38  Gumbel Distribution
    • 39  Cauchy Distribution
    • 40  Triangular Distribution
    • 41  Power Distribution
    • 42  Beta Prime Distribution
    • 43  Sample Correlation Distribution
    • 44  Dirichlet Distribution
    • 45  Generalized Extreme Value (GEV) Distribution
    • 46  Frechet Distribution
    • 47  Noncentral t Distribution
    • 48  Noncentral F Distribution
    • 49  Inverse Chi-Squared Distribution
    • 50  Maxwell-Boltzmann Distribution
    • 51  Distribution Relationship Map

    • 52  Problems
  • Descriptive Statistics & Exploratory Data Analysis
    • 53  Types of Data
    • 54  Datasheets

    • 55  Frequency Plot (Bar Plot)
    • 56  Frequency Table
    • 57  Contingency Table
    • 58  Binomial Classification Metrics
    • 59  Confusion Matrix
    • 60  ROC Analysis

    • 61  Stem-and-Leaf Plot
    • 62  Histogram
    • 63  Data Quality Forensics
    • 64  Quantiles
    • 65  Central Tendency
    • 66  Variability
    • 67  Skewness & Kurtosis
    • 68  Concentration
    • 69  Notched Boxplot
    • 70  Scatterplot
    • 71  Pearson Correlation
    • 72  Rank Correlation
    • 73  Partial Pearson Correlation
    • 74  Simple Linear Regression
    • 75  Moments
    • 76  Quantile-Quantile Plot (QQ Plot)
    • 77  Normal Probability Plot
    • 78  Probability Plot Correlation Coefficient Plot (PPCC Plot)
    • 79  Box-Cox Normality Plot
    • 80  Kernel Density Estimation
    • 81  Bivariate Kernel Density Plot
    • 82  Conditional EDA: Panel Diagnostics
    • 83  Bootstrap Plot (Central Tendency)
    • 84  Survey Scores Rank Order Comparison
    • 85  Cronbach Alpha

    • 86  Equi-distant Time Series
    • 87  Time Series Plot (Run Sequence Plot)
    • 88  Mean Plot
    • 89  Blocked Bootstrap Plot (Central Tendency)
    • 90  Standard Deviation-Mean Plot
    • 91  Variance Reduction Matrix
    • 92  (Partial) Autocorrelation Function
    • 93  Periodogram & Cumulative Periodogram

    • 94  Problems
  • Hypothesis Testing
    • 95  Normal Distributions revisited
    • 96  The Population
    • 97  The Sample
    • 98  The One-Sided Hypothesis Test
    • 99  The Two-Sided Hypothesis Test
    • 100  When to use a one-sided or two-sided test?
    • 101  What if \(\sigma\) is unknown?
    • 102  The Central Limit Theorem (revisited)
    • 103  Statistical Test of the Population Mean with known Variance
    • 104  Statistical Test of the Population Mean with unknown Variance
    • 105  Statistical Test of the Variance
    • 106  Statistical Test of the Population Proportion
    • 107  Statistical Test of the Standard Deviation \(\sigma\)
    • 108  Statistical Test of the difference between Means -- Independent/Unpaired Samples
    • 109  Statistical Test of the difference between Means -- Dependent/Paired Samples
    • 110  Statistical Test of the difference between Variances -- Independent/Unpaired Samples

    • 111  Hypothesis Testing for Research Purposes
    • 112  Decision Thresholds, Alpha, and Confidence Levels
    • 113  Bayesian Inference for Decision-Making
    • 114  One Sample t-Test
    • 115  Skewness & Kurtosis Tests
    • 116  Paired Two Sample t-Test
    • 117  Wilcoxon Signed-Rank Test
    • 118  Unpaired Two Sample t-Test
    • 119  Unpaired Two Sample Welch Test
    • 120  Two One-Sided Tests (TOST) for Equivalence
    • 121  Mann-Whitney U test (Wilcoxon Rank-Sum Test)
    • 122  Bayesian Two Sample Test
    • 123  Median Test based on Notched Boxplots
    • 124  Chi-Squared Tests for Count Data
    • 125  Kolmogorov-Smirnov Test
    • 126  One Way Analysis of Variance (1-way ANOVA)
    • 127  Kruskal-Wallis Test
    • 128  Two Way Analysis of Variance (2-way ANOVA)
    • 129  Repeated Measures ANOVA
    • 130  Friedman Test
    • 131  Testing Correlations
    • 132  A Note on Causality

    • 133  Problems
  • Regression Models
    • 134  Simple Linear Regression Model (SLRM)
    • 135  Multiple Linear Regression Model (MLRM)
    • 136  Logistic Regression
    • 137  Generalized Linear Models
    • 138  Multinomial and Ordinal Logistic Regression
    • 139  Cox Proportional Hazards Regression
    • 140  Conditional Inference Trees
    • 141  Leaf Diagnostics for Conditional Inference Trees
    • 142  Conditional Random Forests
    • 143  Hypothesis Testing with Linear Regression Models (from a Practical Point of View)

    • 144  Problems
  • Introduction to Time Series Analysis
    • 145  Case: the Market of Health and Personal Care Products
    • 146  Decomposition of Time Series
    • 147  Ad hoc Forecasting of Time Series
  • Box-Jenkins Analysis
    • 148  Introduction to Box-Jenkins Analysis
    • 149  Theoretical Concepts
    • 150  Stationarity
    • 151  Identifying ARMA parameters
    • 152  Estimating ARMA Parameters and Residual Diagnostics
    • 153  Forecasting with ARIMA models
    • 154  Intervention Analysis
    • 155  Cross-Correlation Function
    • 156  Transfer Function Noise Models
    • 157  General-to-Specific Modeling
  • Model Building Strategies
    • 158  Introduction to Model Building Strategies
    • 159  Manual Model Building
    • 160  Model Validation
    • 161  Regularization Methods
    • 162  Hyperparameter Optimization Strategies
    • 163  Guided Model Building in Practice
    • 164  Diagnostics, Revision, and Guided Forecasting
    • 165  Leakage, Target Encoding, and Robust Regression
  • References
  • Appendices
    • Appendices
    • A  Method Selection Guide
    • B  Presentations and Teaching Materials
    • C  R Language Concepts for Statistical Computing
    • D  Matrix Algebra
    • E  Standard Normal Table (Gaussian Table)
    • F  Critical values of Student’s \(t\) distribution with \(\nu\) degrees of freedom
    • G  Upper-tail critical values of the \(\chi^2\)-distribution with \(\nu\) degrees of freedom
    • H  Lower-tail critical values of the \(\chi^2\)-distribution with \(\nu\) degrees of freedom

Table of contents

  • 72.1 Definition of Spearman Rank Order Correlation
  • 72.2 Uncorrected Spearman Rank Order Correlation
  • 72.3 Corrected Spearman Rank Order Correlation
  • 72.4 t-Test Statistic
  • 72.5 z-Test Statistic
  • 72.6 Definition of Kendall’s \(\tau\) Rank Order Correlation (Kendall 1938)
  • 72.7 R Module
    • 72.7.1 Public website
    • 72.7.2 RFC
  • 72.8 Purpose
  • 72.9 Pros & Cons
    • 72.9.1 Pros
    • 72.9.2 Cons
  • 72.10 Example 1
  • 72.11 Example 2
  1. Descriptive Statistics & Exploratory Data Analysis
  2. 72  Rank Correlation

72  Rank Correlation

72.1 Definition of Spearman Rank Order Correlation

The basic idea of Rank Correlations is that we compute the linear association between the rank orders of two variables, rather than the original data values. To define the Spearman Rank Order Correlation (Spearman 1904) we use a computational example based on sample data that are displayed in Table 72.1.

Table 72.1: Student Scores for two exams \(x\) and \(y\)
Student Score \(x\) Rank \(x\) Score \(y\) Rank \(y\) \(d_i\) \(d_i^2\)
A 30 11.0 70 10.5 +0.5 0.25
B 30 11.0 70 10.5 +0.5 0.25
C 25 5.5 68 7.5 -2.0 4.00
D 27 7.5 63 5.0 +2.5 6.25
E 23 3.0 52 2.5 +0.5 0.25
F 21 1.0 50 1.0 +0.0 0.00
G 27 7.5 68 7.5 +0.0 0.00
H 23 3.0 59 4.0 -1.0 1.00
I 23 3.0 52 2.5 +0.5 0.25
J 30 11.0 70 10.5 +0.5 0.25
K 28 9.0 70 10.5 -1.5 2.25
L 25 5.5 64 6.0 -0.5 0.25
15.00

Note that a “mean rank” is assigned if two or more data values are equal (e.g. students C and L both have a score of 25 for exam \(x\) which corresponds to a mean rank of 5.5 = (5+6)/2). Because ties are present in this example, the no-ties z-test based on \(D=\sum d_i^2\) (see Section 72.5) is not valid for inference here.

72.2 Uncorrected Spearman Rank Order Correlation

The “uncorrected” Spearman Rank Order Correlation is defined as

\[ r_s = 1 - \frac{6 \sum_{i=1}^{n} d_i^2}{n(n-1)(n+1)} = 1 - \frac{6D}{n(n-1)(n+1)} \]

where \(d_i\) is the difference in rank order for each observation \(i = 1, 2, 3, …, n\).

When this definition is applied to our sample data we obtain

\[ r_s = 1 - \frac{6 \times 15}{12 \times 11 \times 13} = 1 - \frac{90}{1716} = 0.947552 \]

72.3 Corrected Spearman Rank Order Correlation

The problem with this definition is that it does not take into account the ties in the rank orders. To compute the “corrected” Spearman Rank Order Correlation we use the following definition

\[ r_s = \frac{\sum x^2 + \sum y^2 - \sum d^2}{2 \sqrt{\sum x^2 \times \sum y^2}} \]

with the following components (applied to the sample data)

\[ \begin{cases}\sum T_x = \sum \frac{t^3 - t}{12} = \underset{\text{{\tiny 3 ties of rank 3}}}{\frac{3^3 - 3}{12}} + \underset{\text{{\tiny 2 ties of rank 5.5}}}{\frac{2^3 - 2}{12}} + \underset{\text{{\tiny 2 ties of rank 7.5}}}{\frac{2^3 - 2}{12}} + \underset{\text{{\tiny 3 ties of rank 11}}}{\frac{3^3 - 3}{12}} = 5 \\\sum T_y = \sum \frac{t^3 - t}{12} = \underset{\text{{\tiny 2 ties of rank 2.5}}}{\frac{2^3 - 2}{12}} + \underset{\text{{\tiny 2 ties of rank 7.5}}}{\frac{2^3 - 2}{12}} + \underset{\text{{\tiny 4 ties of rank 10.5}}}{\frac{4^3 - 4}{12}} = 6 \\\sum x^2 = \frac{n^3 - n}{12} - \sum T_x = \frac{12^3 - 12}{12} - 5 = 143 - 5 = 138 \\\sum y^2 = \frac{n^3 - n}{12} - \sum T_y = \frac{12^3 - 12}{12} - 6 = 143 - 6 = 137\end{cases} \]

This implies that the “corrected” result is

\[ r_s = \frac{138 + 137 - 15}{2 \sqrt{138 \times 137}} = 0.945461 \]

72.4 t-Test Statistic

\[ t = r_s \sqrt{\frac{n-2}{1-r_s^2}} \]

When applied to the sample data we obtain

\[ t = 0.945461 \sqrt{\frac{12-2}{1-0.893897}} = 9.178631 \]

which, based on the t-Distribution, leads to

\[ \text{P}(t \geq 9.178631) = 0.000002 \]

72.5 z-Test Statistic

This z-test based on \(D=\sum d_i^2\) assumes there are no ties in either ranking.

\[ z = \frac{D - \text{E}(D)}{\sqrt{\text{V}(D)}} = \frac{\sum_{i=1}^{n}d_i^2 - \frac{n(n-1)(n+1)}{6}}{\sqrt{\frac{n^2(n-1)(n+1)^2}{36}}} \]

If this no-ties formula is applied to the tied sample data above, we obtain the following value (illustrative only; for tied data use a tie-corrected or software-computed Spearman test for inference):

\[ z = \frac{15 - 286}{\sqrt{7436}} = -3.142676 \]

If one nonetheless plugs this illustrative value into the standard Normal Distribution, it leads to

\[ \text{P}(z \geq -3.142676) = 0.999163 \wedge \text{P}(z < -3.142676) = 0.000837 \]

These probabilities are not valid Spearman inference results for this tied sample.

72.6 Definition of Kendall’s \(\tau\) Rank Order Correlation (Kendall 1938)

\[ \tau = \frac{\text{\# concordant pairs - \# discordant pairs}}{\frac{n(n-1)}{2}} \]

where a pair of ranks is said to be “concordant” if \(x_i > x_j\) and \(y_i > y_j\) or if both \(x_i < x_j\) and \(y_i < y_j\).

As is the case with the Spearman Rank Order Correlation, Kendall’s \(\tau\) requires special treatment of ties. This treatment is not discussed in this book -- however, the R modules use the corrected formulas.

72.7 R Module

72.7.1 Public website

The Spearman Rank Order Correlation for bivariate data is available on the public website:

  • https://compute.wessa.net/rwasp_spearman.wasp

The Kendall’s \(\tau\) Rank Order Correlation for bivariate data is available on the public website:

  • https://compute.wessa.net/rwasp_kendall.wasp

The public website also features an R module which allows to compute Pearson Correlations, Spearman Rank Order Correlations, and Kendall’s \(\tau\) Rank Order Correlations for all possible pairs of variables in a multivariate dataset:

  • https://compute.wessa.net/rwasp_pairs.wasp

72.7.2 RFC

When using the default profile in RFC these R modules can be found under the “Descriptive / Multivariate Descriptive Statistics”.

The R code to compute Correlation Matrices is shown in Section 71.5.2. To compute the bivariate Spearman and Kendall \(\tau\) Rank Order Correlation on your local machine, the following script can be used in the R console:

y <- c(80,60,10,20,30)
x <- c(20,40,30,50,60)
ylab = 'y'
xlab = 'x'
plot(x,y,main='Scatterplot',xlab=xlab,ylab=ylab)
grid()

plot(rank(x),rank(y),main='Scatterplot of Ranks',xlab=xlab,ylab=ylab)
grid()

#Kendall's tau with base R
k <- cor.test(x,y,method='kendall')
#rho
k$estimate
#2-sided p-value
k$p.value
#Spearman's rho with base R
k <- cor.test(x,y,method='spearman')
#rho
k$estimate
#2-sided p-value
k$p.value
 tau 
-0.2 
[1] 0.8166667
 rho 
-0.3 
[1] 0.6833333

To compute the Spearman or Kendall \(\tau\) Rank Order Correlation, the R code uses the cor.test function which features a method parameter (method can have the values ‘pearson’, ‘spearman’, and ‘kendall’). Alternatively, there are several external libraries (such as the Kendall package) that can be used.

72.8 Purpose

Rank Order Correlations are used to identify associations between pairs of variables. Since the computations are based on ranks (rather than the original values) they require a hypothesis-testing mechanism (see Hypothesis Testing) which does not rely on distributional assumptions (i.e. Rank Order Correlations are non-parametric).

72.9 Pros & Cons

72.9.1 Pros

Rank Order Correlations have the following advantages:

  • There are no distributional assumptions when these correlations are used to test hypotheses. In other words, there is no requirement that the variables have a Normal Distribution.
  • These correlations are robust (not sensitive to outliers).
  • They are easily computed with many software packages.

72.9.2 Cons

Rank Order Correlations have the following disadvantages:

  • Some software packages may not correct for ties (software documentation does not always describe whether or not correction for ties is applied, and how this is done)
  • While most readers know that Rank Order Correlations exist, they often do not know why they are used and how they differ from Pearson Correlations.

72.10 Example 1

The following analysis shows the Spearman Rank Order Correlation for two types of intrinsic motivation scores. Since both variables have a discrete (non normal) distribution, this computation can be used for the purpose of hypothesis testing.

Interactive Shiny app (click to load).
Open in new tab

The correlation coefficient is 0.599 which is evidence for a positive association between both types of intrinsic motivation (i.e. students with high scores for IM.Know also tend to have high scores for IM.Accomplishment).

72.11 Example 2

The Kendall \(\tau\) correlation can be computed by selecting “Kendall” in the “Type of Correlations” drop down box. The output show that the correlation is 0.463 which is considerably smaller than the Spearman correlation from the previous example. This is (not always but) often the case: Kendall’s \(\tau\) tends to be more conservative than Spearman’s correlation.

Kendall, Maurice G. 1938. “A New Measure of Rank Correlation.” Biometrika 30 (1/2): 81–93. https://doi.org/10.2307/2332226.
Spearman, Charles. 1904. “The Proof and Measurement of Association Between Two Things.” The American Journal of Psychology 15 (1): 72–101. https://doi.org/10.2307/1412159.
71  Pearson Correlation
73  Partial Pearson Correlation

© 2026 Patrick Wessa. Provided as-is, without warranty.

Feedback: e-mail | Anonymous contributions: click to copy (Sats) | click to copy (XMR)

Cookie Preferences