Polynomial Regression Calculator: Cubic, Quartic and Higher-Degree Curve Fit with R²
Fit a least-squares polynomial of degree 1 to 6 (cubic, quartic, quintic) to your x, y data. Get the equation, R², adjusted R², residuals, predictions and a degree comparison.
How it works
ŷ = a₀ + a₁x + a₂x² + … + aₙxⁿ · coefficients minimize SSE = Σ(y − ŷ)², i.e. a = (XᵀX)⁻¹Xᵀy · R² = 1 − SSE ÷ SST, SST = Σ(y − ȳ)² · adjusted R² = 1 − (1 − R²)(N − 1) ÷ (N − n − 1) · standard error = √(SSE ÷ (N − n − 1))
Polynomial regression fits a curve y = a₀ + a₁x + … + aₙxⁿ through scattered data by least squares: it chooses the coefficients that make the sum of squared vertical gaps between the points and the curve as small as possible. Although the curve bends, the model is still linear in its coefficients, so it is solved like a multiple linear regression in which x, x², x³, … act as separate predictors. To keep the arithmetic accurate for large x values or high degrees, the calculator centers and rescales x before solving with a QR decomposition, then converts the coefficients back to powers of x. R² is the share of the variation in y that the curve explains. Adding a degree can never lower R², so the calculator also gives adjusted R² and the standard error, which penalize extra coefficients, and a table comparing every degree on your data so you can see where a higher degree stops paying off. You need at least degree + 1 different x values; with exactly that many the curve passes through every point. Unlike the site’s linear and three-point quadratic tools, this one fits cubic, quartic, quintic and sextic models to any number of points. Polynomials behave badly outside the data range, so be careful with predictions there.
Worked example
For the default 10 points (x = 1 to 10, y = 2.7, 8.8, 14.0, 15.2, 14.1, 15.9, 16.3, 21.2, 27.2, 40.2), the cubic fit is y = 0.196134x³ − 2.93432x² + 14.6801x − 9.54. The squared errors add up to SSE = 3.75401 against a total variation SST = 950.864, so R² = 1 − 3.75401 ÷ 950.864 = 0.996052: the cubic explains 99.6% of the variation in y. Adjusted R² is 1 − 0.003948 × 9 ÷ 6 = 0.994078, the standard error is √(3.75401 ÷ 6) = 0.790992, and the curve predicts y = 15.0694 at x = 5.5. The degree comparison shows why a cubic is the right choice here: a straight line reaches only R² = 0.82 and a quadratic 0.87, while a quartic barely moves R² (0.99615) and its adjusted R² drops to 0.99307.
Sources: Omni Calculator: Polynomial regression (model, least squares, matrix method) · Mathleaks / Pearson Algebra 2: cubic and quartic regression example · MetricGate: Polynomial regression worked example (mtcars mpg on hp) · Texas Instruments: R² for cubic and quartic regression
Frequently asked questions
How many data points do I need for cubic or quartic regression?
At least degree + 1 points with different x values: 4 for a cubic, 5 for a quartic, 7 for a sextic. With exactly that many the curve passes through every point and R² is 1, so use clearly more points than coefficients if you want a meaningful fit.
How do I choose the polynomial degree?
Start low and raise the degree only while adjusted R² and the standard error keep improving noticeably. Look at the residuals too: if they still show a pattern, a higher degree may help; if they look random, stop. The degree comparison table does this check for you.
What is a good R² for polynomial regression?
It depends on the field. Physical measurements often reach 0.99, while social or biological data may give 0.5. A high R² does not prove the model is right, and with high degrees R² can be high just because the curve chases noise.
Is polynomial regression linear or nonlinear regression?
It is linear regression: the curve is nonlinear in x, but the model is linear in its coefficients a₀, a₁, …, so ordinary least squares solves it exactly, with no starting guesses or iterations.
Why are my coefficients tiny or huge?
High powers of large x values (for example years like 2026⁵) are enormous, so their coefficients become very small. That is normal. To get readable coefficients, shift x first, for example use years since 2000.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.