{
  "id": "quadratic-regression",
  "version": "7c35a68c8f9c",
  "status": "published",
  "name": "Quadratic Regression Calculator",
  "question": "What is the quadratic regression?",
  "summary": "Fits the least-squares parabola y = ax² + bx + c to paired x and y values and reports a, b, c, R², the vertex, and a prediction at a new x.",
  "category": "statistics",
  "subcategory": "descriptive",
  "url": "https://www.acalculator.org/statistics/quadratic-regression-calculator",
  "markdown": "https://www.acalculator.org/statistics/quadratic-regression-calculator.md",
  "kind": "function",
  "method": "Solve the normal equations [n Σx Σx²; Σx Σx² Σx³; Σx² Σx³ Σx⁴] [c b a]ᵀ = [Σy Σxy Σx²y]ᵀ; R² = 1 − Σ(y − ŷ)² ÷ Σ(y − ȳ)².",
  "assumptions": [
    "The first x value goes with the first y value, and so on, so both lists must be the same length.",
    "The curve minimises the sum of squared vertical distances from the points (ordinary least squares).",
    "A parabola needs at least 3 different x values."
  ],
  "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 y values, one for each x value, in the same order.",
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "at": {
        "title": "New x value",
        "description": "An x value at which to read y from the fitted curve. Leave it empty to skip.",
        "type": "number"
      }
    }
  },
  "outputs": {
    "equation": {
      "label": "Quadratic regression equation",
      "description": "The least-squares parabola, each coefficient to 6 significant digits.",
      "format": "text"
    },
    "a": {
      "label": "a (x² coefficient)",
      "description": "The coefficient of x². A positive a opens the curve upward.",
      "format": "number"
    },
    "b": {
      "label": "b (x coefficient)",
      "description": "The coefficient of x.",
      "format": "number"
    },
    "c": {
      "label": "c (constant)",
      "description": "The value of y on the curve where x = 0.",
      "format": "number"
    },
    "r2": {
      "label": "R²",
      "description": "The share of the variation in y that the curve explains, 1 − SSE ÷ SST. It is not shown when every y is the same.",
      "format": "number"
    },
    "vertexX": {
      "label": "Vertex x",
      "description": "The x of the turning point, −b ÷ 2a. It is not shown when a is 0.",
      "format": "number"
    },
    "vertexY": {
      "label": "Vertex y",
      "description": "The y of the turning point, c − b² ÷ 4a.",
      "format": "number"
    },
    "predicted": {
      "label": "Predicted y",
      "description": "The value of y on the curve at the new x value.",
      "format": "number"
    },
    "n": {
      "label": "Number of points (n)",
      "description": "How many (x, y) pairs there are.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "x": "-2, -1, 0, 1, 2",
      "y": "5, 2, 1, 2, 5.5",
      "at": 3
    },
    "outputs": {
      "equation": "y = 1.07143x² + 0.1x + 0.957143",
      "a": 1.0714285714285714,
      "b": 0.1,
      "c": 0.9571428571428572,
      "r2": 0.9982363315696648,
      "vertexX": -0.04666666666666667,
      "vertexY": 0.9548095238095238,
      "predicted": 10.9,
      "n": 5
    },
    "text": "The quadratic regression equation through 5 points is y = 1.07143x² + 0.1x + 0.957143."
  },
  "examples": [
    {
      "given": {
        "x": [
          -2,
          -1,
          0,
          1,
          2
        ],
        "y": [
          5,
          2,
          1,
          2,
          5.5
        ],
        "at": 3
      },
      "expect": {
        "equation": "y = 1.07143x² + 0.1x + 0.957143",
        "a": 1.0714285714285714,
        "b": 0.1,
        "c": 0.9571428571428572,
        "r2": 0.9982363315696648,
        "vertexX": -0.04666666666666667,
        "vertexY": 0.9548095238095238,
        "predicted": 10.9
      },
      "source": "hand calculation in content.mdx: Σx = 0, Σx² = 10, Σx³ = 0, Σx⁴ = 34, Σy = 15.5, Σxy = 1, Σx²y = 46; a = 15/14, b = 1/10, c = 67/70; NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression (a quadratic β₀ + β₁x + β₁₁x² is linear in its parameters; the estimates minimise the sum of squared deviations), https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm (retrieved 2026-10-05); Python 3: fractions.Fraction and Cramer's rule"
    },
    {
      "given": {
        "x": [
          1,
          2,
          3
        ],
        "y": [
          1,
          4,
          9
        ]
      },
      "expect": {
        "equation": "y = x²",
        "a": 1,
        "b": 0,
        "c": 0,
        "r2": 1,
        "vertexX": 0,
        "vertexY": 0
      },
      "source": "hand calculation in content.mdx: the parabola through three points is unique, and 1, 4, 9 are 1², 2², 3²; NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression (a quadratic β₀ + β₁x + β₁₁x² is linear in its parameters; the estimates minimise the sum of squared deviations), https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm (retrieved 2026-10-05)"
    },
    {
      "given": {
        "x": [
          0,
          1,
          2,
          3,
          4
        ],
        "y": [
          1,
          1.8,
          3.3,
          4.5,
          6.3
        ]
      },
      "expect": {
        "a": 0.12142857142857143,
        "b": 0.8442857142857143,
        "c": 0.9628571428571429,
        "r2": 0.997070903244293
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression (a quadratic β₀ + β₁x + β₁₁x² is linear in its parameters; the estimates minimise the sum of squared deviations), https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm (retrieved 2026-10-05); Python 3: the normal equations in fractions.Fraction, solved by Cramer's rule (a = 17/140, b = 591/700, c = 337/350, R² = 31317/31409)"
    }
  ],
  "sources": [
    "NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression: a quadratic β₀ + β₁x + β₁₁x² is linear in its parameters, and least squares minimises the sum of squared deviations. https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm (retrieved 2026-10-05)",
    "OpenStax, Introductory Statistics 2e, §12.3 The Regression Equation: residuals y − ŷ and the sum of squared errors SSE that least squares minimises. https://openstax.org/books/introductory-statistics-2e/pages/12-3-the-regression-equation (retrieved 2026-10-05)"
  ],
  "related": [
    "linear-regression",
    "exponential-regression",
    "correlation-coefficient"
  ],
  "changelog": []
}
