SpearmanRho[v1,v2]
gives Spearman's rank correlation coefficient
for the vectors v1 and v2.
SpearmanRho[m]
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 ![]()
Spearman rank correlation for the multivariate symbolic distribution dist.
SpearmanRho
SpearmanRho[v1,v2]
gives Spearman's rank correlation coefficient
for the vectors v1 and v2.
SpearmanRho[m]
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 ![]()
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 all close allBasic Examples (4)
v1 = {3, -4, 1, 4, 22, 17, -2, 2, 13, -11};
v2 = {-20, -24, 0, 4, 24, 36, -12, -12, 56, -14};SpearmanRho[v1, v2]m = RandomVariate[BinormalDistribution[.6], 10^5];SpearmanRho[m]//MatrixFormm1 = RandomReal[1, {10^3, 4}];m2 = RandomReal[1, {10^3, 3}];SpearmanRho[m1, m2]//MatrixFormCompute Spearman's
for a bivariate distribution:
𝒟 = BinormalDistribution[.5];SpearmanRho[𝒟]//MatrixFormSpearmanRho[RandomVariate[𝒟, 10^5]]//MatrixFormScope (7)
Data (4)
Exact input yields exact output:
SpearmanRho[{3 / 2, 3, 5, 10}, {2, 5 / 4, 15, 8}]Approximate input yields approximate output:
SpearmanRho[{1.5, 3, 5, 10}, {2, 1.25, 15, 8}]SpearmanRho[N[{1, 2, 5, 6}, 20], N[{19, 34, 6, 8}, 20]]SpearmanRho[RandomReal[1, 10 ^ 5], RandomReal[1, 10 ^ 5]]SparseArray data can be used:
SpearmanRho[SparseArray[{{2, 2} -> 1, {5, 3} -> 2, {10, 1} -> 3}]]//MatrixFormDistributions and Processes (3)
Spearman's
for a continuous multivariate distribution:
SpearmanRho[BinormalDistribution[ρ]]//MatrixFormSpearmanRho[BinormalDistribution[ρ], 2, 1]Spearman's
for derived distributions:
SpearmanRho[ProductDistribution[ExponentialDistribution[1], NormalDistribution[3, 5]]]//MatrixForm𝒟 = CopulaDistribution[{"Frank", 2}, {UniformDistribution[{0, 1}], UniformDistribution[{0, 1}]}];SpearmanRho[𝒟]//MatrixForm𝒟 = HistogramDistribution[RandomVariate[BinormalDistribution[.75], 10 ^ 2]];SpearmanRho[𝒟]//MatrixFormSpearmanRho[BinormalDistribution[.75]]//MatrixFormSpearman's
for a random process at times s and t:
SpearmanRho[WienerProcess[][{0.3, 0.7}]]//MatrixFormApplications (4)
Spearman's
is typically used to detect linear dependence between two vectors:
{v11, v21} = Transpose[RandomVariate[BinormalDistribution[.99], 1000]];
{v12, v22} = Transpose[RandomVariate[BinormalDistribution[0], 1000]];The absolute magnitude of
tends to 1 given strong linear dependence:
SpearmanRho[v11, v21]The value tends to 0 for linearly independent vectors:
SpearmanRho[v12, v22]Spearman's
can be used to measure linear association:
data = BlockRandom[SeedRandom[1];Table[RandomVariate[BinormalDistribution[i], 3000], {i, {-.99, -.75, -.25, -.5, 0., .25, .5, .75, .99}}]];Grid[Partition[Table[ListPlot[i, PlotStyle -> Directive[PointSize[Tiny]],
FrameTicks -> None, Frame -> True, Axes -> None, PlotLabel -> Row[{"ρ : ", SpearmanRho[i][[1, 2]]}]], {i, data}],
3]]Spearman's
can only detect monotonic relationships:
uni = RandomReal[{-3, 3}, 3000];f[x_] := {{x, -Sqrt[Abs[x]] + RandomReal[.5]}, {x, .25x^2 + RandomReal[.5]}, {x, -Sinc[x] + RandomReal[.5]}, {Cos[x], Sin[x] + RandomReal[.5]}}data = f /@ uni;Table[ListPlot[data[[All, i]], Frame -> True, Axes -> None, PlotLabel -> Row[{"ρ : ", SpearmanRho[data[[All, i]]][[1, 2]]}], PlotStyle -> Directive[PointSize[Tiny]], FrameTicks -> None], {i, 4}]HoeffdingD can be used to detect a variety of dependence structures:
Table[HoeffdingD[data[[All, i]]][[1, 2]], {i, 4}]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:
ExampleData[{"Statistics", "USCars1993"}, "LongDescription"]carData = N@ExampleData[{"Statistics", "USCars1993"}][[All, {5, 7, 13, 18}]];labs = ExampleData[{"Statistics", "USCars1993"}, "ColumnHeadings"][[{5, 7, 13, 18}]];A scatter plot matrix of the various metrics:
GraphicsGrid[Table[If[i == j, Style[labs[[i]], Bold, FontSize -> 14], ListPlot[Transpose[{carData[[All, j]], carData[[All, i]]}], Frame -> True, AspectRatio -> 1, FrameTicks -> None, ImageSize -> {80, 80}, PlotRange -> All]], {i, 4}, {j, 4}]]Spearman's
corresponding to the scatter plot matrix:
SpearmanRho[N@carData]//MatrixFormSpearmanRankTest suggests that vehicles with higher horsepower are more costly:
SpearmanRankTest[carData[[All, 1]], carData[[All, 3]], "TestDataTable"]Higher fuel economy meant lower prices in 1993:
SpearmanRankTest[carData[[All, 1]], carData[[All, 2]], "TestDataTable"]Properties & Relations (10)
Spearman's
ranges from -1 to 1 for high negative and high positive association, respectively:
d1 = RandomVariate[NormalDistribution[], 100];
d2 = -d1;SpearmanRho[d1, d1]SpearmanRho[d1, d2]Spearman's
is Correlation applied to ranks:
data = Transpose@RandomVariate[BinormalDistribution[.8], 100];SpearmanRho[data[[1]], data[[2]]]With no ties, ranks can be computed using ordering:
rnks = Ordering[Ordering[#]]& /@ data;Correlation[rnks[[1]], rnks[[2]]]//NSpearman's
matrix is symmetric:
spr = SpearmanRho[RandomVariate[BinormalDistribution[1 / 3], 10 ^ 3]];SymmetricMatrixQ[spr]The diagonal elements of Spearman's
matrix are
:
data = RandomInteger[{-3, 3}, {100, 15}];Diagonal[SpearmanRho[data]]Spearman's
is related to KendallTau:
data = BlockRandom[SeedRandom[1];Table[RandomVariate[BinormalDistribution[i], 3000], {i, {-.99, -.75, -.25, -.5, 0., .25, .5, .75, .99}}]];KendallTau tends to be about
of
given weak linear association:
Grid[Partition[Table[ListPlot[i, PlotStyle -> Directive[PointSize[Tiny]],
FrameTicks -> None, Frame -> True, Axes -> None,
PlotLabel -> Row[{"τ / ρ : ", (KendallTau[i][[1, 2]]/SpearmanRho[i][[1, 2]])}]], {i, data}],
3]]Spearman's
will attain
or
if the variables are perfectly monotonically related:
x = RandomReal[{-1, 1}, 1000];
y = ArcTanh[x];
z = -ArcTanh[x];ListPlot[{Transpose[{x, y}], Transpose[{x, z}]}]SpearmanRho[x, y]SpearmanRho[x, z]This is in contrast to Correlation, which strictly measures linear association:
Correlation[x, y]Correlation[x, z]Spearman's
is less sensitive to outliers than Correlation:
data = {{10.5, 0.8}, {10.8, 0.6}}~Join~RandomVariate[BinormalDistribution[-.9], 100];ListPlot[data, PlotRange -> All]Correlation[data][[1, 2]]SpearmanRho[data][[1, 2]]Correlation[data[[3 ;; -1]]][[1, 2]]SpearmanRho[data[[3 ;; -1]]][[1, 2]]Use SpearmanRankTest to test for independence:
data = RandomVariate[BinormalDistribution[.5], 1000];ListPlot[data, PlotStyle -> Directive[PointSize[Small]], PlotLabel -> SpearmanRankTest[Sequence@@Transpose[data], "TestDataTable"]]Alternatively, use IndependenceTest to automatically select an appropriate test:
IndependenceTest[Sequence@@Transpose[data], "TestDataTable"]Use CorrelationTest to test a particular value of Spearman's
:
data = RandomVariate[BinormalDistribution[-.5], 1000];ListPlot[data, PlotStyle -> Directive[PointSize[Small]], PlotLabel -> CorrelationTest[data, -.5, "TestDataTable"]]Spearman's
for a continuous bivariate distribution:
𝒟 = CopulaDistribution[{"AMH", 2 / 3}, {UniformDistribution[{0, 1}], UniformDistribution[{0, 1}]}];rho = SpearmanRho[𝒟, 1, 2]12Expectation[CDF[MarginalDistribution[𝒟, 1], x] * CDF[MarginalDistribution[𝒟, 2], y], {x, y}𝒟] - 3rho - %//FullSimplifyRelated Guides
History
Text
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.
APA
Wolfram Language. (2012). SpearmanRho. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SpearmanRho.html
BibTeX
@misc{reference.wolfram_2026_spearmanrho, author="Wolfram Research", title="{SpearmanRho}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/SpearmanRho.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_spearmanrho, organization={Wolfram Research}, title={SpearmanRho}, year={2012}, url={https://reference.wolfram.com/language/ref/SpearmanRho.html}, note=[Accessed: 13-June-2026]}