SpearmanRho
✖
SpearmanRho
gives Spearman's rank correlation matrix for the multivariate symbolic distribution dist.
gives the 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],
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 real‐valued 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
and j
marginals of dist, respectively, and disti,j is the
marginal of dist.
- SpearmanRho[dist] gives a matrix
where the
entry is given by SpearmanRho[dist,i,j].
Examples
open allclose allBasic Examples (4)Summary of the most common use cases

https://wolfram.com/xid/0bnhhrimqr19m-gugb6d

https://wolfram.com/xid/0bnhhrimqr19m-fulot0


https://wolfram.com/xid/0bnhhrimqr19m-9un6t

https://wolfram.com/xid/0bnhhrimqr19m-hz9gv1


https://wolfram.com/xid/0bnhhrimqr19m-bv14aj

https://wolfram.com/xid/0bnhhrimqr19m-ce2wv

https://wolfram.com/xid/0bnhhrimqr19m-i51zwj

Compute Spearman's for a bivariate distribution:

https://wolfram.com/xid/0bnhhrimqr19m-f7dh9d

https://wolfram.com/xid/0bnhhrimqr19m-mzz2lg


https://wolfram.com/xid/0bnhhrimqr19m-nwpxl1

Scope (7)Survey of the scope of standard use cases
Data (4)
Exact input yields exact output:

https://wolfram.com/xid/0bnhhrimqr19m-kcmch9

Approximate input yields approximate output:

https://wolfram.com/xid/0bnhhrimqr19m-bxeync


https://wolfram.com/xid/0bnhhrimqr19m-04fgr


https://wolfram.com/xid/0bnhhrimqr19m-kt50m4

SparseArray data can be used:

https://wolfram.com/xid/0bnhhrimqr19m-h2htud

Distributions and Processes (3)
Spearman's for a continuous multivariate distribution:

https://wolfram.com/xid/0bnhhrimqr19m-fnv00k


https://wolfram.com/xid/0bnhhrimqr19m-tekwa

Spearman's for derived distributions:

https://wolfram.com/xid/0bnhhrimqr19m-c3a9y


https://wolfram.com/xid/0bnhhrimqr19m-cy97of

https://wolfram.com/xid/0bnhhrimqr19m-etkwz


https://wolfram.com/xid/0bnhhrimqr19m-hxjash

https://wolfram.com/xid/0bnhhrimqr19m-gm1a47


https://wolfram.com/xid/0bnhhrimqr19m-edj4ah

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

https://wolfram.com/xid/0bnhhrimqr19m-hv1ygl

Applications (4)Sample problems that can be solved with this function
Spearman's is typically used to detect linear dependence between two vectors:

https://wolfram.com/xid/0bnhhrimqr19m-l7u46j
The absolute magnitude of tends to 1 given strong linear dependence:

https://wolfram.com/xid/0bnhhrimqr19m-patcg

The value tends to 0 for linearly independent vectors:

https://wolfram.com/xid/0bnhhrimqr19m-dx1jig

Spearman's can be used to measure linear association:

https://wolfram.com/xid/0bnhhrimqr19m-bcl86

https://wolfram.com/xid/0bnhhrimqr19m-g1rlnp

Spearman's can only detect monotonic relationships:

https://wolfram.com/xid/0bnhhrimqr19m-7nvfr

https://wolfram.com/xid/0bnhhrimqr19m-nazb6e

https://wolfram.com/xid/0bnhhrimqr19m-j9qi3

https://wolfram.com/xid/0bnhhrimqr19m-gtfa0z

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

https://wolfram.com/xid/0bnhhrimqr19m-jor85u

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:

https://wolfram.com/xid/0bnhhrimqr19m-drd2ab


https://wolfram.com/xid/0bnhhrimqr19m-gp8q9i

https://wolfram.com/xid/0bnhhrimqr19m-fshejd
A scatter plot matrix of the various metrics:

https://wolfram.com/xid/0bnhhrimqr19m-m0cf8q

Spearman's corresponding to the scatter plot matrix:

https://wolfram.com/xid/0bnhhrimqr19m-cp0h5h

SpearmanRankTest suggests that vehicles with higher horsepower are more costly:

https://wolfram.com/xid/0bnhhrimqr19m-bgy446

Higher fuel economy meant lower prices in 1993:

https://wolfram.com/xid/0bnhhrimqr19m-bh8d2b

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:

https://wolfram.com/xid/0bnhhrimqr19m-fvojjd

https://wolfram.com/xid/0bnhhrimqr19m-cp90d4


https://wolfram.com/xid/0bnhhrimqr19m-mp4oro

Spearman's is Correlation applied to ranks:

https://wolfram.com/xid/0bnhhrimqr19m-gyy786

https://wolfram.com/xid/0bnhhrimqr19m-i1g8cy

With no ties, ranks can be computed using ordering:

https://wolfram.com/xid/0bnhhrimqr19m-pyvmky

https://wolfram.com/xid/0bnhhrimqr19m-bljs6q

Spearman's matrix is symmetric:

https://wolfram.com/xid/0bnhhrimqr19m-31bc2

https://wolfram.com/xid/0bnhhrimqr19m-mmzf9d

The diagonal elements of Spearman's matrix are
:

https://wolfram.com/xid/0bnhhrimqr19m-o1vsb7

https://wolfram.com/xid/0bnhhrimqr19m-h7qlge

Spearman's is related to KendallTau:

https://wolfram.com/xid/0bnhhrimqr19m-hbkym
KendallTau tends to be about of
given weak linear association:

https://wolfram.com/xid/0bnhhrimqr19m-mts4te

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

https://wolfram.com/xid/0bnhhrimqr19m-xln2s

https://wolfram.com/xid/0bnhhrimqr19m-dde2tx


https://wolfram.com/xid/0bnhhrimqr19m-gm71p


https://wolfram.com/xid/0bnhhrimqr19m-kylhyv

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

https://wolfram.com/xid/0bnhhrimqr19m-f40mz2


https://wolfram.com/xid/0bnhhrimqr19m-m22vt

Spearman's is less sensitive to outliers than Correlation:

https://wolfram.com/xid/0bnhhrimqr19m-in32zp

https://wolfram.com/xid/0bnhhrimqr19m-bfgq4m


https://wolfram.com/xid/0bnhhrimqr19m-hn8j42


https://wolfram.com/xid/0bnhhrimqr19m-jgtad1


https://wolfram.com/xid/0bnhhrimqr19m-bbfovu


https://wolfram.com/xid/0bnhhrimqr19m-ipvl9m

Use SpearmanRankTest to test for independence:

https://wolfram.com/xid/0bnhhrimqr19m-l4v2w

https://wolfram.com/xid/0bnhhrimqr19m-eetjj

Alternatively, use IndependenceTest to automatically select an appropriate test:

https://wolfram.com/xid/0bnhhrimqr19m-kv172

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

https://wolfram.com/xid/0bnhhrimqr19m-tkukp

https://wolfram.com/xid/0bnhhrimqr19m-be53he

Spearman's for a continuous bivariate distribution:

https://wolfram.com/xid/0bnhhrimqr19m-bfewud

https://wolfram.com/xid/0bnhhrimqr19m-ewdode


https://wolfram.com/xid/0bnhhrimqr19m-ba93xz


https://wolfram.com/xid/0bnhhrimqr19m-hqcqde

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
]}
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
]}