{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $y_1, \\dots, y_n$ be observed values of a response, not all equal, and let $\\hat y_1, \\dots, \\hat y_n$ be the fitted values of a regression model.\nLet $\\bar y = \\frac{1}{n} \\sum_{i=1}^n y_i$ be the [[sample mean|03Y6AQ2S0J]].\nThe *total sum of squares* is $SS_{\\mathrm{tot}} = \\sum_{i=1}^n (y_i - \\bar y)^2$.\nThe *residual sum of squares* is $SS_{\\mathrm{res}} = \\sum_{i=1}^n (y_i - \\hat y_i)^2$.\nThe *coefficient of determination* is\n$$R^2 = 1 - \\frac{SS_{\\mathrm{res}}}{SS_{\\mathrm{tot}}}.$$\n\n## Remarks\n\nExample: take the points $(x_i, y_i) = (0,0), (1,1), (2,3)$ and fit $y = a + bx$ by [[ordinary least squares|YM708KHV2W]].\nThe fit is $b = 3/2$, $a = -1/6$, with fitted values $-1/6$, $4/3$, $17/6$.\nThen $SS_{\\mathrm{res}} = 1/36 + 4/36 + 1/36 = 1/6$ and $SS_{\\mathrm{tot}} = 16/9 + 1/9 + 25/9 = 14/3$, so $R^2 = 1 - 1/28 = 27/28$.\n\nWhen the fit is by ordinary least squares with an intercept, $SS_{\\mathrm{tot}} = SS_{\\mathrm{reg}} + SS_{\\mathrm{res}}$ with $SS_{\\mathrm{reg}} = \\sum_i (\\hat y_i - \\bar y)^2$.\nSo $R^2 = SS_{\\mathrm{reg}} / SS_{\\mathrm{tot}}$ lies in $[0, 1]$.\nIn that case $R^2$ is the square of the sample correlation between $y$ and $\\hat y$.\nFor a straight line fit it is the square of the sample correlation between $x$ and $y$.\n\nNon-example: if the fitted values do not come from least squares with an intercept, the formula can give a negative number.\nWith the same data and the constant prediction $\\hat y_i = 3$, one gets $SS_{\\mathrm{res}} = 13 \u003e SS_{\\mathrm{tot}}$, so $R^2 \u003c 0$.\n\nThe *adjusted* $R^2$ for a model with $p$ coefficients, including the intercept, is $1 - (1 - R^2)(n - 1)/(n - p)$.\nIt penalises extra regressors.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "defines": "B45RMKMVZ5",
    "kind": "definition",
    "msc": [
      "62J05"
    ],
    "name": "Coefficient of determination",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Coefficient_of_determination"
      }
    ],
    "tag": "XKGEV5RP3T",
    "uses": [
      "YM708KHV2W",
      "03Y6AQ2S0J"
    ]
  },
  "kind": "definition",
  "link": "https://tamnd.github.io/math2/node/XKGEV5RP3T/",
  "links": [
    {
      "field": "defines",
      "target": "B45RMKMVZ5"
    },
    {
      "field": "uses",
      "target": "YM708KHV2W"
    },
    {
      "field": "uses",
      "target": "03Y6AQ2S0J"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/XKGEV5RP3T.md",
  "msc": [
    "62J05"
  ],
  "name": "Coefficient of determination",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/XKG/XKGEV5RP3T.md",
  "status": null,
  "tag": "XKGEV5RP3T",
  "uri": "m2://XKGEV5RP3T",
  "url": "https://tamnd.github.io/math2/wiki/coefficient-of-determination-definition/",
  "writing": {
    "tag": "XKGEV5RP3T",
    "kind": "definition",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
