{
  "id": "spearman-rank-correlation",
  "title": "Spearman's Rank Correlation",
  "lang": "en",
  "source_lang": "en",
  "summary": "Spearman's rank correlation measures the direction and strength of monotonic association by correlating the ranks of paired observations.",
  "category": "mathematics",
  "subcategory": "probability-statistics",
  "type": "concept",
  "aliases": [
    "Spearman's rho",
    "Spearman rank-order correlation",
    "Spearman's rank correlation coefficient"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/spearman-rank-correlation/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/spearman-rank-correlation/",
      "json": "https://aiwiki.page/zh/spearman-rank-correlation.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Spearman's rank correlation is a measure of association between two variables based on their relative ordering rather than their original numerical values. For a sample of paired observations, it is the Pearson correlation coefficient of the two sets of ranks. Usually denoted by \\(r_s\\) for a sample and \\(\\rho_s\\) for a population, it ranges from \\(-1\\) to \\(1\\), provided that neither ranked variable is constant. Positive values indicate that larger values of one variable tend to accompany larger values of the other; negative values indicate an association in the opposite direction.\n\nThe coefficient is particularly useful for ordered categories, skewed measurements, and relationships that are monotonic but not linear. It does not require normally distributed measurements, and strictly increasing transformations of either variable leave it unchanged. These properties make it a widely used tool in statistics, the behavioral sciences, environmental research, and data analysis. Its interpretation nevertheless depends on the treatment of tied values, the sampling design, and the distinction between monotonic association and more general forms of dependence."
    },
    {
      "heading": "Origins and the rank-based approach",
      "text": "The coefficient is named after Charles Spearman, whose 1904 paper “The Proof and Measurement of Association between Two Things” helped establish rank correlation as a practical statistical method. Spearman worked in psychology, where investigators often had judgments, test results, or ordered assessments rather than measurements on a common quantitative scale. Ranking supplied a way to compare such observations without assuming that the numerical distances between successive positions represented equal differences in the underlying attribute.\n\nThe essential operation is to replace each observation by its position within its own variable. For \\(n\\) paired observations \\((x_i,y_i)\\), the smallest \\(x\\)-value receives rank 1, the next receives rank 2, and so forth; the \\(y\\)-values are ranked separately. Each observation retains its original partner throughout this procedure. Sorting both columns independently and then pairing the sorted values would destroy the observed association and, in the absence of ties, manufacture a correlation of \\(1\\).\n\nRanks preserve order but discard spacing. Values \\(2,3,100\\) become ranks \\(1,2,3\\), just as values \\(2,50,100\\) do. Consequently, Spearman's coefficient answers a different question from a measure that uses the original numerical distances. It describes how consistently observations occupy corresponding relative positions, not how many units one measurement changes when another increases. The information discarded by ranking may be irrelevant when only ordering is meaningful, but it can be scientifically important when measurement differences have a direct interpretation.\n\nThis approach belongs to nonparametric statistics, although “nonparametric” does not mean assumption-free. The coefficient can be calculated for many kinds of data without specifying a parametric distribution, but probability statements about it still require assumptions about how observations were obtained. Independently sampled pairs, repeated measurements from the same subject, and measurements arranged in a time series can yield the same numerical coefficient while requiring different methods of inference.\n\nRanking also distinguishes this coefficient from the algebraic concept of matrix rank. Here, a rank is an observation's ordered position, not the dimension of a matrix's column space. The relevant measurement requirement is that each variable have a meaningful ordering. Arbitrarily coding unordered categories as numbers does not create an order suitable for Spearman correlation."
    },
    {
      "heading": "Sample definition and the rank-difference formula",
      "text": "Let \\(R_i\\) and \\(S_i\\) be the ranks of \\(x_i\\) and \\(y_i\\), respectively. The general sample definition is\n\n\\[r_s= \\frac{\\sum_{i=1}^{n}(R_i-\\bar R)(S_i-\\bar S)} {\\sqrt{\\sum_{i=1}^{n}(R_i-\\bar R)^2 \\sum_{i=1}^{n}(S_i-\\bar S)^2}},\\]\n\nwhere \\(\\bar R\\) and \\(\\bar S\\) are the respective rank means. This is ordinary Pearson correlation applied to the ranked observations. The formula expresses the covariance of the ranks relative to their variability. Any common choice of divisor, such as \\(n\\) or \\(n-1\\), cancels between the numerator and denominator.\n\nWhen there are no tied values, both rank lists are permutations of \\(1,\\ldots,n\\). Their means equal \\((n+1)/2\\), and each centered sum of squares is\n\n\\[Q=\\sum_{i=1}^{n}\\left(i-\\frac{n+1}{2}\\right)^2 =\\frac{n(n^2-1)}{12}.\\]\n\nWriting \\(d_i=R_i-S_i\\), expansion gives\n\n\\[\\sum_{i=1}^{n}d_i^2 =2Q-2\\sum_{i=1}^{n}(R_i-\\bar R)(S_i-\\bar S).\\]\n\nSubstitution into the correlation formula yields the familiar shortcut\n\n\\[r_s=1-\\frac{6\\sum_{i=1}^{n}d_i^2}{n(n^2-1)}.\\]\n\nThe shortcut is therefore a consequence of the special variance of untied ranks, not an independent definition that can be used unchanged in every dataset.\n\nFor example, consider five observations whose ranks are\n\n\\[R=(1,2,3,4,5),\\qquad S=(1,3,2,5,4).\\]\n\nThe rank differences are \\(0,-1,1,-1,1\\), so their squared sum is 4. Hence\n\n\\[r_s=1-\\frac{6(4)}{5(25-1)}=0.8.\\]\n\nThe two orderings agree substantially, but two adjacent pairs have exchanged positions. More generally, the squared differences give greater weight to large rank displacements than to small ones.\n\nThe coefficient equals \\(1\\) when the two nonconstant rank vectors have perfect positive linear correspondence and equals \\(-1\\) when they have perfect negative linear correspondence. With no ties, these cases mean identical and exactly reversed rankings, respectively. Its bounds follow from the Cauchy–Schwarz inequality applied to the centered rank vectors. If either variable is constant, its rank vector has zero variance, the denominator vanishes, and the coefficient is undefined rather than zero."
    },
    {
      "heading": "Tied observations and average ranks",
      "text": "Ties arise whenever two or more observations have the same recorded value. They are common in questionnaires, count data, rounded measurements, and variables with only a few categories. The usual convention assigns every observation in a tied group the average of the positions that the group occupies. For instance, values that would occupy positions 2 and 3 both receive rank \\(2.5\\). These are called average ranks or midranks.\n\nAverage ranks preserve the total rank sum \\(n(n+1)/2\\), so both rank means remain \\((n+1)/2\\). They reduce the centered sum of squares, however. If the tie-group sizes for the first variable are \\(t_1,t_2,\\ldots\\), then\n\n\\[A=\\sum_i(R_i-\\bar R)^2 =\\frac{n(n^2-1)-\\sum_j(t_j^3-t_j)}{12}.\\]\n\nFor the second variable, with tie-group sizes \\(u_1,u_2,\\ldots\\),\n\n\\[B=\\sum_i(S_i-\\bar S)^2 =\\frac{n(n^2-1)-\\sum_k(u_k^3-u_k)}{12}.\\]\n\nIf \\(D=\\sum_i(R_i-S_i)^2\\), the exact rank-difference expression becomes\n\n\\[r_s=\\frac{A+B-D}{2\\sqrt{AB}},\\]\n\nprovided \\(A\\) and \\(B\\) are positive. In practice, calculating Pearson correlation directly from the midranks is usually simpler than implementing this correction separately.\n\nConsider\n\n\\[x=(1,2,2,4),\\qquad y=(1,2,3,3).\\]\n\nTheir midranks are\n\n\\[R=(1,2.5,2.5,4),\\qquad S=(1,2,3.5,3.5).\\]\n\nHere \\(A=B=4.5\\), while \\(D=1.5\\), giving\n\n\\[r_s=\\frac{4.5+4.5-1.5}{2\\sqrt{4.5\\cdot4.5}} =\\frac56.\\]\n\nUsing the uncorrected shortcut instead would give \\(0.85\\), which is not the Pearson correlation of these rank vectors.\n\nTies affect interpretation as well as arithmetic. If one variable distinguishes observations that the other combines into tied groups, perfect rank correlation may be unattainable for those fixed marginal values, even if their broad ordering agrees. Different tie conventions—such as minimum ranks, maximum ranks, dense ranks, or arbitrary sequential ranks—can produce different results. The standard Spearman coefficient uses average ranks; arbitrary tie-breaking introduces distinctions unsupported by the data.\n\nThe issue becomes especially visible with binary variables. Average ranks are then affine transformations of the original zero–one codes, so Spearman correlation equals their Pearson correlation. Ranking does not create additional resolution in a coarse scale, nor does it remove limitations caused by highly uneven category frequencies."
    },
    {
      "heading": "Population definition and copulas",
      "text": "For continuous random variables \\(X\\) and \\(Y\\), let \\(F_X\\) and \\(F_Y\\) denote their cumulative distribution functions. Population Spearman correlation is\n\n\\[\\rho_s=\\operatorname{Corr}\\bigl(F_X(X),F_Y(Y)\\bigr).\\]\n\nThe transformed variables represent population-relative positions. Under continuous marginal distributions, each is uniformly distributed on \\([0,1]\\), with mean \\(1/2\\) and variance \\(1/12\\). It follows that\n\n\\[\\rho_s =12\\,\\mathbb E[F_X(X)F_Y(Y)]-3.\\]\n\nThus the population coefficient correlates percentile positions rather than measurements in their original units.\n\nThis formulation connects Spearman correlation to a copula, which separates a joint distribution's dependence structure from its marginal distributions. If \\(C(u,v)\\) is the copula of a continuous pair, then\n\n\\[\\rho_s =12\\int_0^1\\int_0^1 \\bigl[C(u,v)-uv\\bigr]\\,du\\,dv.\\]\n\nUnder statistical independence, \\(C(u,v)=uv\\), so the coefficient is zero. Positive and negative deviations from independence contribute with opposite signs to the integral. They can cancel, explaining why a zero coefficient does not establish independence.\n\nThe population definition also makes transformation invariance precise. If \\(g\\) is strictly increasing, \\(g(X)\\) retains the ordering and percentile position of \\(X\\), so\n\n\\[\\rho_s(g(X),Y)=\\rho_s(X,Y).\\]\n\nA strictly decreasing transformation reverses the sign when applied to just one variable. These statements do not hold without qualification for non-strict transformations, because collapsing distinct values creates ties. A strictly increasing logarithmic transformation of positive measurements leaves their Spearman correlation unchanged, whereas rounding them into broad categories need not do so.\n\nDiscrete distributions require additional care because \\(F_X(X)\\) is not generally uniform. The population counterpart of average ranking uses the mid-distribution function\n\n\\[F_X^{\\mathrm{mid}}(x) =P(X<x)+\\frac12P(X=x).\\]\n\nA natural definition matching sample midranks is\n\n\\[\\rho_s= \\operatorname{Corr} \\left(F_X^{\\mathrm{mid}}(X),F_Y^{\\mathrm{mid}}(Y)\\right).\\]\n\nFor continuous variables, this reduces to the previous definition. For discrete variables, its denominator must use the actual variances of the mid-distribution transforms; the continuous formula \\(12\\mathbb E[UV]-3\\) cannot simply be retained. Copula representations also lose their uniqueness away from the ranges of discrete marginal distribution functions, so continuous-margin identities should not be transferred uncritically to heavily tied data."
    },
    {
      "heading": "Monotonic association and its limits",
      "text": "Spearman correlation measures association in ordering and is therefore particularly responsive to a monotonic relationship. If \\(Y=g(X)\\) almost surely for a strictly increasing function \\(g\\), and the variables have continuous distributions, then \\(\\rho_s=1\\). Strictly decreasing functional relationships give \\(\\rho_s=-1\\). Neither relationship needs to be linear. For example, \\(Y=X^3\\) preserves the ordering of every real-valued observation, although its numerical slope varies with \\(X\\).\n\nThis property distinguishes monotonicity from linearity, but it does not make Spearman correlation a general detector of nonlinear dependence. Suppose \\(X\\) is uniformly distributed on \\([-1,1]\\) and \\(Y=X^2\\). The value of \\(Y\\) is completely determined by \\(X\\), yet population Spearman correlation is zero. Symmetry pairs every negative value of \\(X\\) with a positive value having the same \\(Y\\), and their contributions cancel. U-shaped, circular, and other nonmonotonic patterns can therefore have small or zero coefficients despite strong dependence.\n\nMagnitude describes the consistency of rank ordering, not a rate of change. A coefficient of \\(0.8\\) does not mean that one variable rises by 80 percent when the other rises, that 80 percent of observations are correctly ordered, or that the original measurements share 64 percent of their variance. Although \\(r_s^2\\) is the coefficient of determination from a simple linear regression of one rank vector on the other with an intercept, that interpretation concerns ranks, not the original measurement scale. Universal cutoffs for “weak,” “moderate,” and “strong” association ignore differences in measurement reliability, category resolution, and scientific context.\n\nRanking reduces sensitivity to the magnitude of extreme measurements: moving the largest value still farther from the rest leaves its rank unchanged. It does not make the coefficient immune to unusual observations. An added or altered observation can change many ranks, and a point pairing a very low rank with a very high rank may substantially affect a small sample. Robustness to numerical magnitude is distinct from immunity to contamination or sampling errors.\n\nFinally, rank association is not causation. Confounding, selection processes, common trends, and aggregation can all create or conceal a rank correlation. A positive relationship within each subgroup need not have the same sign after groups are pooled. Restricting analysis to a narrow range of values can also alter the coefficient. These issues concern the underlying study design and population, not defects that ranking alone can repair."
    },
    {
      "heading": "Hypothesis testing and null distributions",
      "text": "Spearman correlation commonly serves as a test statistic in hypothesis testing. Two null hypotheses must be distinguished: independence of the variables and a population rank correlation of zero. Independence implies zero Spearman correlation for nonconstant variables, but the reverse is false. Consequently, a test calibrated by freely permuting observations is fundamentally an independence test under an exchangeable sampling structure, even when its result is described informally as a test of “no correlation.”\n\nUnder independence for independently sampled pairs, the pairing of the observed \\(x\\)-values with the observed \\(y\\)-values is arbitrary conditional on the marginal samples. A permutation test fixes one rank vector and reorders the other. With no ties, all \\(n!\\) permutations can be enumerated in principle. For an absolute-value two-sided test, the exact p-value is the proportion of permutations satisfying\n\n\\[|r_s^{\\pi}|\\geq |r_s^{\\mathrm{obs}}|.\\]\n\nOther definitions of a two-sided tail can differ in discrete distributions, so the convention is part of the testing procedure.\n\nFor nonconstant fixed rank vectors, uniform random permutation gives\n\n\\[\\mathbb E_{\\pi}[r_s]=0,\\qquad \\operatorname{Var}_{\\pi}(r_s)=\\frac{1}{n-1}.\\]\n\nThese identities also hold for midrank vectors with ties, although ties change the shape and attainable values of the permutation distribution. Exact enumeration becomes expensive as \\(n\\) increases, making random permutation sampling useful. If \\(B\\) random permutations produce \\(b\\) statistics at least as extreme as the observed value, a common Monte Carlo calculation is \\((b+1)/(B+1)\\), which includes the observed arrangement and avoids reporting a zero tail probability from a finite simulation.\n\nA widely used approximation transforms the coefficient as\n\n\\[t=r_s\\sqrt{\\frac{n-2}{1-r_s^2}}\\]\n\nand compares it with Student's t distribution with \\(n-2\\) degrees of freedom. Unlike the corresponding Pearson result under bivariate normal sampling, this is not an exact finite-sample distributional result for Spearman correlation. Its accuracy depends on sample size and data structure. Under independent continuous variables, \\(\\sqrt{n-1}\\,r_s\\) is asymptotically standard normal.\n\nPermutation validity depends on exchangeability. Repeated measurements, family clusters, matched designs, and serial dependence generally rule out unrestricted shuffling. Appropriate restricted permutations or model-based methods must reflect the design. Moreover, dependence with \\(\\rho_s=0\\) can have a different asymptotic variance from independence, so an independence-based calibration need not provide a valid general test of the broader null hypothesis \\(\\rho_s=0\\)."
    },
    {
      "heading": "Estimation, confidence intervals, and study design",
      "text": "As an estimate of population rank association, the sample coefficient has sampling uncertainty even when its numerical calculation is exact. Under standard independent sampling conditions, it is a consistent estimator of the corresponding population quantity. It is not generally unbiased in finite samples: the expected value of \\(r_s\\) need not equal \\(\\rho_s\\). Small samples also permit only a limited set of possible coefficients, particularly when ranks are untied or variables have few categories.\n\nA confidence interval requires more than the observed coefficient. Its width depends on sample size, the joint distribution, ties, and the dependence among sampling units. The Fisher transformation,\n\n\\[z=\\operatorname{atanh}(r_s) =\\frac12\\log\\left(\\frac{1+r_s}{1-r_s}\\right),\\]\n\nis sometimes used in approximate procedures. However, the familiar Pearson standard error \\(1/\\sqrt{n-3}\\) is not a universally valid standard error for transformed Spearman correlation. Rank-specific approximations or distributional assumptions are needed to justify a particular interval.\n\nBootstrap sampling provides another approach. For independently sampled observations, whole pairs \\((x_i,y_i)\\) are resampled together, ranks are recalculated in every resample, and the resulting coefficients approximate the estimator's sampling distribution. Resampling the two variables separately would remove their observed association and simulate a different problem. Bootstrap samples may contain many repeated observations, and very small or highly discrete datasets can produce resamples in which one variable is constant. Boundary estimates near \\(-1\\) or \\(1\\) can also make simple interval procedures unreliable.\n\nThe definition of a sampling unit is especially important. Ten measurements from each of 20 individuals do not ordinarily supply the same inferential information as 200 independent individuals. Cluster-based resampling treats individuals, rather than their individual measurements, as independent units. Serially correlated data require methods appropriate to their dependence, such as block-based resampling under suitable conditions. An ordinary row-level analysis may estimate a descriptive association while substantially understating its uncertainty.\n\nStudy planning also requires more information than a desired rank correlation. Statistical power depends on the alternative dependence structure, category frequencies, measurement error, and the testing procedure. Two joint distributions can share the same population Spearman coefficient but yield different finite-sample power. When many correlations are investigated, multiple testing changes the interpretation of unadjusted significance results. Procedures controlling familywise error or the false discovery rate address multiplicity; they do not correct bias from selective reporting, missingness, or an inappropriate sampling model."
    },
    {
      "heading": "Relationships to other association measures",
      "text": "Pearson correlation and Spearman correlation differ in what information they retain. Pearson correlation uses numerical deviations from means and measures linear association in the original variables. Spearman correlation applies that same calculation after ranking. When a relationship is linear and well described by a suitable quantitative model, ranking discards spacing information that may improve estimation or prediction. Conversely, for monotonic nonlinear relationships or measurements whose spacing is arbitrary, ranks can provide the more relevant description.\n\nKendall's rank correlation uses comparisons between pairs of observations. With continuous variables, its population coefficient is the probability of concordance minus the probability of discordance. Concordance occurs when two observations have the same ordering on both variables; discordance occurs when their orderings differ. Tie-adjusted versions, including Kendall's tau-b, are used for discrete data. Spearman's rho instead correlates the full rank positions, so its numerical scale is not interchangeable with Kendall's tau.\n\nTheir relationship is especially clear for a bivariate normal distribution with Pearson correlation parameter \\(\\rho\\). In this model,\n\n\\[\\rho_s=\\frac{6}{\\pi}\\arcsin\\left(\\frac{\\rho}{2}\\right), \\qquad \\tau=\\frac{2}{\\pi}\\arcsin(\\rho).\\]\n\nFor example, \\(\\rho=0.5\\) corresponds to \\(\\rho_s\\approx0.483\\) and \\(\\tau=1/3\\). These identities illustrate why the same verbal magnitude categories should not be transferred automatically between coefficients. They are model-specific relationships, not general conversion formulas for arbitrary data.\n\nA partial Spearman coefficient is commonly obtained by ranking the variables, regressing each ranked variable on ranked control variables, and correlating the residuals. Equivalently, it can be calculated as a partial correlation from a rank-correlation matrix when the required matrix operations are well defined. This adjusts for linear relationships among ranks. It does not generally test conditional independence, and it does not guarantee removal of confounding. Conditional relationships can remain nonlinear even after the original measurements are ranked.\n\nMeasures such as mutual information target broader dependence rather than a signed tendency toward increasing or decreasing order. Under their defining conditions, they can detect relationships that yield zero Spearman correlation, including symmetric U-shaped patterns. They answer a different question and introduce different estimation requirements. Similarly, agreement statistics for repeated measurements are not interchangeable with rank correlation: two instruments can rank every subject identically while differing systematically in calibration or scale."
    },
    {
      "heading": "Computation and applications",
      "text": "A standard computational procedure first identifies complete observation pairs, assigns average ranks independently to the two retained variables, and calculates Pearson correlation between the resulting rank vectors. For general unsorted numerical data, sorting dominates the computation, usually requiring \\(O(n\\log n)\\) time per variable. Once ranks are available, their means, centered sums of squares, and cross-product require \\(O(n)\\) operations. The procedure avoids the direct examination of all observation pairs.\n\nMissing-data rules determine which observations enter the ranking. If incomplete pairs are removed for a particular comparison, ranks should be calculated within the retained paired sample. Ranking a larger column first and then dropping unmatched observations generally produces a different result. Pairwise deletion across many variables can also create a table of correlations that is not positive semidefinite, because different entries use different subsets and potentially different rank assignments. Such a table is not necessarily the correlation matrix of a single common ranked dataset.\n\nWith complete data, a Spearman correlation matrix is simply the Pearson correlation matrix of the ranked columns and is positive semidefinite. This matters for principal component analysis, matrix factorization, and other methods that assume a valid correlation or covariance matrix. Even then, analysis concerns transformed variables. Components extracted from ranks describe variation in relative positions rather than variation in the original measurement units.\n\nApplications include comparing ordered assessments in education, examining monotonic associations among environmental measurements, and assessing whether two quantitative assays order samples similarly. In gene-expression analysis, rank correlation can describe coordinated ordering of expression levels across samples without requiring a linear relationship on the recorded scale. In machine learning, it can assess whether prediction scores rank cases in an order consistent with observed outcomes. These uses retain the distinction between ranking performance and accurate numerical prediction.\n\nSoftware implementations can agree on the coefficient while disagreeing on a reported significance level because they use different exact, asymptotic, tie-adjusted, or permutation procedures. They may also differ in missing-value handling and warnings for constant inputs. Reproducible reporting therefore identifies the number of analyzed pairs, the treatment of ties and missing values, the inferential method, and whether the calculation concerns independent observations or a structured sampling design. A reported coefficient alone does not specify those analytical choices."
    }
  ],
  "links": [
    "correlation",
    "statistics",
    "time-series",
    "matrix-rank",
    "covariance",
    "cauchy-schwarz-inequality",
    "variance",
    "random-variable",
    "cumulative-distribution-function",
    "statistical-independence",
    "logarithm",
    "monotonic-function",
    "coefficient-of-determination",
    "causation",
    "confounding",
    "test-statistic",
    "statistical-hypothesis-testing",
    "permutation-test",
    "p-value",
    "students-t-distribution",
    "degrees-of-freedom",
    "consistent-estimator",
    "expected-value",
    "confidence-interval",
    "bootstrap-sampling",
    "statistical-power",
    "multiple-testing",
    "false-discovery-rate",
    "kendall-rank-correlation",
    "multivariate-normal-distribution",
    "conditional-independence",
    "mutual-information",
    "principal-component-analysis",
    "covariance-matrix",
    "education",
    "gene-expression",
    "machine-learning"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}