{
  "id": "residual",
  "version": "b126525711cc",
  "status": "published",
  "name": "Residual Calculator",
  "question": "What are the residuals?",
  "summary": "Finds the residual y − ŷ of every point from the least-squares regression line, with the predicted values, the sum of squared residuals (SSE), and the residual standard deviation.",
  "category": "statistics",
  "subcategory": "descriptive",
  "url": "https://www.acalculator.org/statistics/residual-calculator",
  "markdown": "https://www.acalculator.org/statistics/residual-calculator.md",
  "kind": "schedule",
  "method": "b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²; a = ȳ − b x̄; ŷ = a + bx; residual = y − ŷ; SSE = Σ(y − ŷ)²; s = √(SSE ÷ (n − 2)).",
  "assumptions": [
    "The line is the least-squares regression line of y on x, fitted to all the points you enter.",
    "A positive residual means the point is above the line; a negative one, below it.",
    "The residuals of a least-squares line with an intercept always add up to 0."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "x": {
        "title": "x values",
        "description": "The x values, in order, separated by commas, spaces, semicolons, or new lines.",
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "y": {
        "title": "y values",
        "description": "The observed y values, one for each x value, in the same order.",
        "type": "array",
        "items": {
          "type": "number"
        }
      }
    }
  },
  "outputs": {
    "residuals": {
      "label": "Residuals (y − ŷ)",
      "description": "The residual of each point, in the order you entered them.",
      "format": "text"
    },
    "equation": {
      "label": "Regression line",
      "description": "The least-squares line, each coefficient to 6 significant digits.",
      "format": "text"
    },
    "slope": {
      "label": "Slope (b)",
      "description": "How much ŷ changes when x goes up by 1.",
      "format": "number"
    },
    "intercept": {
      "label": "Intercept (a)",
      "description": "The value of ŷ where x = 0.",
      "format": "number"
    },
    "sse": {
      "label": "Sum of squared residuals (SSE)",
      "description": "Each residual squared, then added up.",
      "format": "number"
    },
    "residualSd": {
      "label": "Residual standard deviation (s)",
      "description": "The square root of SSE ÷ (n − 2). It needs 3 or more points.",
      "format": "number"
    },
    "n": {
      "label": "Number of points (n)",
      "description": "How many (x, y) pairs there are.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "x": "1, 2, 3, 4, 5",
      "y": "2, 4, 5, 4, 5"
    },
    "outputs": {
      "residuals": "−0.8, 0.6, 1, −0.6, −0.2",
      "equation": "ŷ = 0.6x + 2.2",
      "slope": 0.6,
      "intercept": 2.2,
      "sse": 2.4,
      "residualSd": 0.8944271909999159,
      "n": 5
    },
    "text": "The residuals from ŷ = 0.6x + 2.2 are −0.8, 0.6, 1, −0.6, −0.2."
  },
  "examples": [
    {
      "given": {
        "x": [
          1,
          2,
          3,
          4,
          5
        ],
        "y": [
          2,
          4,
          5,
          4,
          5
        ]
      },
      "expect": {
        "residuals": "−0.8, 0.6, 1, −0.6, −0.2",
        "equation": "ŷ = 0.6x + 2.2",
        "slope": 0.6,
        "intercept": 2.2,
        "sse": 2.4,
        "residualSd": 0.894427190999916,
        "n": 5
      },
      "source": "hand calculation in content.mdx: ŷ = 2.2 + 0.6x gives 2.8, 3.4, 4, 4.6, 5.2; residuals −0.8, 0.6, 1, −0.6, −0.2; SSE = 2.4; s = √(2.4 ÷ 3); OpenStax, Introductory Statistics 2e, §12.3 The Regression Equation (the residual is y − ŷ, positive above the line; SSE is the sum of the squared residuals, which the least-squares line minimises), https://openstax.org/books/introductory-statistics-2e/pages/12-3-the-regression-equation (retrieved 2026-10-05); Python 3: statistics.linear_regression"
    },
    {
      "given": {
        "x": [
          0,
          1,
          2,
          3
        ],
        "y": [
          10,
          7,
          4,
          1
        ]
      },
      "expect": {
        "residuals": "0, 0, 0, 0",
        "equation": "ŷ = −3x + 10",
        "sse": 0,
        "residualSd": 0
      },
      "source": "hand calculation in content.mdx: every point is on ŷ = 10 − 3x; OpenStax, Introductory Statistics 2e, §12.3 The Regression Equation (the residual is y − ŷ, positive above the line; SSE is the sum of the squared residuals, which the least-squares line minimises), https://openstax.org/books/introductory-statistics-2e/pages/12-3-the-regression-equation (retrieved 2026-10-05)"
    },
    {
      "given": {
        "x": [
          0.1,
          0.2,
          0.3
        ],
        "y": [
          0.3,
          0.1,
          0.2
        ]
      },
      "expect": {
        "residuals": "0.05, −0.1, 0.05",
        "equation": "ŷ = −0.5x + 0.3",
        "sse": 0.015
      },
      "source": "hand calculation in content.mdx: x̄ = 0.2, ȳ = 0.2, Sxx = 0.02, Sxy = −0.01, b = −0.5, a = 0.3; OpenStax, Introductory Statistics 2e, §12.3 The Regression Equation (the residual is y − ŷ, positive above the line; SSE is the sum of the squared residuals, which the least-squares line minimises), https://openstax.org/books/introductory-statistics-2e/pages/12-3-the-regression-equation (retrieved 2026-10-05); Python 3: fractions.Fraction"
    }
  ],
  "sources": [
    "OpenStax, Introductory Statistics 2e, §12.3 The Regression Equation: the residual y − ŷ is positive for a point above the line and negative below it; SSE is the sum of the squared residuals, which the least-squares line minimises. https://openstax.org/books/introductory-statistics-2e/pages/12-3-the-regression-equation (retrieved 2026-10-05)"
  ],
  "related": [
    "linear-regression",
    "sum-of-squares",
    "quadratic-regression"
  ],
  "changelog": []
}
