{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $(x_1, y_1), \\dots, (x_n, y_n)$ be $n \\ge 2$ pairs of real numbers, with $x_1, \\dots, x_n$ distinct and $y_1, \\dots, y_n$ distinct.\nLet $r_i$ be the rank of $x_i$ among $x_1, \\dots, x_n$ and $s_i$ the rank of $y_i$ among $y_1, \\dots, y_n$, with rank $1$ for the smallest.\n*Spearman's rank correlation coefficient* is the sample [[correlation coefficient|04CTY6XYWN]] of the pairs $(r_i, s_i)$.\nWith $d_i = r_i - s_i$ it equals\n$$\\rho_s = 1 - \\frac{6 \\sum_{i=1}^{n} d_i^2}{n(n^2 - 1)}.$$\n\n## Remarks\n\nThe closed formula holds because the ranks of each variable are the numbers $1, \\dots, n$, whose mean and variance are known.\nFor random variables $X$ and $Y$ with continuous [[distribution functions|0MXMS3AE13]] $F$ and $G$, the population version is the correlation of $F(X)$ and $G(Y)$, which equals $12 \\, E[F(X) G(Y)] - 3$.\n\nExample: $x = (1, 2, 3)$ and $y = (1, 3, 2)$.\nThe ranks are $r = (1, 2, 3)$ and $s = (1, 3, 2)$, so $d = (0, -1, 1)$ and $\\rho_s = 1 - 6 \\cdot 2 / (3 \\cdot 8) = 1/2$.\nFor $y = (1, 4, 9)$ instead, $d = 0$ and $\\rho_s = 1$.\n\nNon-example: for data with ties, such as $y = (1, 1, 2)$, the ranks are not defined by the clause above.\nThe usual fix gives tied values the average of their ranks and takes the Pearson correlation; the formula with $\\sum d_i^2$ is then no longer exact.\n\nThe [[Kendall rank correlation coefficient|DYFY16SFHZ]] is another rank correlation, based on pairs of observations.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "defines": "DJFYTQJ3SH",
    "kind": "definition",
    "msc": [
      "62H20",
      "62G10"
    ],
    "name": "Spearman's rank correlation coefficient",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient"
      }
    ],
    "tag": "M092V97ZET",
    "uses": [
      "04CTY6XYWN",
      "0MXMS3AE13"
    ]
  },
  "kind": "definition",
  "link": "https://tamnd.github.io/math2/node/M092V97ZET/",
  "links": [
    {
      "field": "defines",
      "target": "DJFYTQJ3SH"
    },
    {
      "field": "uses",
      "target": "04CTY6XYWN"
    },
    {
      "field": "uses",
      "target": "0MXMS3AE13"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/M092V97ZET.md",
  "msc": [
    "62H20",
    "62G10"
  ],
  "name": "Spearman's rank correlation coefficient",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/M09/M092V97ZET.md",
  "status": null,
  "tag": "M092V97ZET",
  "uri": "m2://M092V97ZET",
  "url": "https://tamnd.github.io/math2/wiki/spearmans-rank-correlation-coefficient-definition/",
  "writing": {
    "tag": "M092V97ZET",
    "kind": "definition",
    "level": "W0",
    "next": [
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
