WOLFRAM

SpearmanRho[v1,v2]

gives Spearman's rank correlation coefficient for the vectors v1 and v2.

gives Spearman's rank correlation coefficient for the matrix m.

SpearmanRho[m1,m2]

gives Spearman's rank correlation coefficient for the matrices m1 and m2.

SpearmanRho[dist]

gives Spearman's rank correlation matrix for the multivariate symbolic distribution dist.

SpearmanRho[dist,i,j]

gives the ^(th) Spearman rank correlation for the multivariate symbolic distribution dist.

Details

  • SpearmanRho[v1,v2] gives Spearman's rank correlation coefficient between v1 and v2.
  • Spearman's is a measure of association based on the rank differences between two lists which indicates how well a monotonic function describes their relationship.
  • Spearman's is given by , where is equal to Length[xlist], r_(i) is the rank difference between and , is the correction term for ties in v1, and is the correction term for ties in v2.
  • SpearmanRho[{v11,v12,},{v21,v22,}] is equivalent to Correlation[{r11,r12,},{r21,r22,}] where rij is the tie-corrected ranking corresponding to vij.
  • The arguments v1 and v2 can be any realvalued vectors of equal length.
  • For a matrix m with columns SpearmanRho[m] is a × matrix of the rank correlations between columns of m.
  • For an × matrix m1 and an × matrix m2 SpearmanRho[m1,m2] is a × matrix of the rank correlations between columns of m1 and columns of m2.
  • SpearmanRho[dist,i,j] is 12 Expectation[F[x]G[y],{x,y}disti,j]-3 where F[x] and G[y] are the CDFs of the i^(th) and j^(th) marginals of dist, respectively, and disti,j is the ^(th) marginal of dist.
  • SpearmanRho[dist] gives a matrix where the ^(th) entry is given by SpearmanRho[dist,i,j].

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Spearman's for two vectors:

Out[3]=3

Spearman's for a matrix:

Spearman's for two matrices:

Compute Spearman's for a bivariate distribution:

Compare to a simulated value:

Scope  (7)Survey of the scope of standard use cases

Data  (4)

Exact input yields exact output:

Out[4]=4

Approximate input yields approximate output:

Out[1]=1
Out[2]=2

Works with large arrays:

Out[1]=1

SparseArray data can be used:

Distributions and Processes  (3)

Spearman's for a continuous multivariate distribution:

Out[2]=2

Spearman's for derived distributions:

Data distribution:

Spearman's for a random process at times s and t:

Applications  (4)Sample problems that can be solved with this function

Spearman's is typically used to detect linear dependence between two vectors:

The absolute magnitude of tends to 1 given strong linear dependence:

Out[3]=3

The value tends to 0 for linearly independent vectors:

Out[4]=4

Spearman's can be used to measure linear association:

Out[2]=2

Spearman's can only detect monotonic relationships:

Out[4]=4

HoeffdingD can be used to detect a variety of dependence structures:

Out[5]=5

A collection of measurements were taken from a representative sample of new cars in 1993. Because some of the variables are measured at an ordinal scale, Spearman's is more appropriate than Correlation for measuring monotonic association:

Out[1]=1

A scatter plot matrix of the various metrics:

Out[4]=4

Spearman's corresponding to the scatter plot matrix:

SpearmanRankTest suggests that vehicles with higher horsepower are more costly:

Out[6]=6

Higher fuel economy meant lower prices in 1993:

Out[7]=7

Properties & Relations  (10)Properties of the function, and connections to other functions

Spearman's ranges from -1 to 1 for high negative and high positive association, respectively:

Out[3]=3
Out[4]=4

Spearman's is Correlation applied to ranks:

Out[2]=2

With no ties, ranks can be computed using ordering:

Out[4]=4

Spearman's matrix is symmetric:

Out[2]=2

The diagonal elements of Spearman's matrix are 1:

Out[2]=2

Spearman's is related to KendallTau:

KendallTau tends to be about of given weak linear association:

Out[2]=2

Spearman's will attain 1 or -1 if the variables are perfectly monotonically related:

Out[2]=2
Out[3]=3
Out[4]=4

This is in contrast to Correlation, which strictly measures linear association:

Out[5]=5
Out[6]=6

Spearman's is less sensitive to outliers than Correlation:

Out[2]=2

With outliers:

Out[3]=3
Out[4]=4

Without outliers:

Out[5]=5
Out[6]=6

Use SpearmanRankTest to test for independence:

Out[2]=2

Alternatively, use IndependenceTest to automatically select an appropriate test:

Out[3]=3

Use CorrelationTest to test a particular value of Spearman's :

Test against a value of :

Out[2]=2

Spearman's for a continuous bivariate distribution:

Out[2]=2
Out[3]=3
Out[4]=4
Wolfram Research (2012), SpearmanRho, Wolfram Language function, https://reference.wolfram.com/language/ref/SpearmanRho.html.
Wolfram Research (2012), SpearmanRho, Wolfram Language function, https://reference.wolfram.com/language/ref/SpearmanRho.html.

Text

Wolfram Research (2012), SpearmanRho, Wolfram Language function, https://reference.wolfram.com/language/ref/SpearmanRho.html.

Wolfram Research (2012), SpearmanRho, Wolfram Language function, https://reference.wolfram.com/language/ref/SpearmanRho.html.

CMS

Wolfram Language. 2012. "SpearmanRho." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SpearmanRho.html.

Wolfram Language. 2012. "SpearmanRho." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SpearmanRho.html.

APA

Wolfram Language. (2012). SpearmanRho. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SpearmanRho.html

Wolfram Language. (2012). SpearmanRho. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SpearmanRho.html

BibTeX

@misc{reference.wolfram_2025_spearmanrho, author="Wolfram Research", title="{SpearmanRho}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/SpearmanRho.html}", note=[Accessed: 30-March-2025 ]}

@misc{reference.wolfram_2025_spearmanrho, author="Wolfram Research", title="{SpearmanRho}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/SpearmanRho.html}", note=[Accessed: 30-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_spearmanrho, organization={Wolfram Research}, title={SpearmanRho}, year={2012}, url={https://reference.wolfram.com/language/ref/SpearmanRho.html}, note=[Accessed: 30-March-2025 ]}

@online{reference.wolfram_2025_spearmanrho, organization={Wolfram Research}, title={SpearmanRho}, year={2012}, url={https://reference.wolfram.com/language/ref/SpearmanRho.html}, note=[Accessed: 30-March-2025 ]}