Understanding the polynomial regression calculator — concept and principle
This calculator fits a polynomial curve of degree 2 to 6 to your (x, y) data by least squares. It returns the fitted equation, the coefficients, R², adjusted R², the standard error, the residual sum of squares and a prediction at a chosen x. Use it for curved trends in experiments, calibration curves, growth data and engineering measurements.
How it is calculated
Model: ŷ = a₀ + a₁x + a₂x² + … + a_d·x^d.
- The coefficients minimise SSE = Σ(y − ŷ)² by solving the normal equations (XᵀX)a = Xᵀy, where X has columns 1, x, x², …, x^d.
- To stay accurate at higher degrees, x is centred and scaled before solving and converted back afterwards.
- R² = 1 − SSE ÷ SST, with SST = Σ(y − ȳ)².
- Adjusted R² = 1 − (1 − R²)(n − 1) ÷ (n − d − 1).
- Standard error = √(SSE ÷ (n − d − 1)).
You need at least d + 1 different x values.
The principle
Although the curve is not a straight line, the model is linear in its coefficients, so ordinary least squares applies just as in linear regression. Least squares picks the curve that makes the total squared vertical distance from the points as small as possible. Each extra degree adds one more coefficient and one more bend, which always reduces SSE. That is why plain R² always rises with degree, and why adjusted R² and the standard error, which charge for each extra coefficient, are better for choosing a degree.
Worked example
Default data: x = 0 to 9, y = 1.0, 2.8, 3.1, 2.5, 2.0, 2.4, 3.9, 6.0, 7.6, 7.9; degree 4; predict at x = 4.5.
- Fit by least squares: y = −0.0181964x⁴ + 0.341696x³ − 1.92181x² + 3.65915x + 0.932517.
- SSE = 0.0982226 with n − d − 1 = 10 − 4 − 1 = 5 residual degrees of freedom.
- R² = 0.998117; adjusted R² = 0.996611.
- Standard error = √(0.0982226 ÷ 5) ≈ 0.140159.
- Prediction at x = 4.5: ŷ ≈ 2.15742.
How to read the result
R² near 1 means the curve follows the points closely, but with few points and a high degree that can simply be overfitting. Compare adjusted R² and the standard error across degrees and choose the lowest degree that fits well. The standard error is the typical vertical miss in y units. Predictions are reliable only inside the range of your x data.
Common mistakes
- Choosing the highest degree because it gives the largest R².
- Extrapolating beyond the data; polynomials can swing wildly outside the range.
- Using exactly d + 1 points, which makes the curve pass through every point and leaves no information about noise.
- Reading the coefficients as independent effects; they are strongly correlated.
Frequently asked questions
What degree should I choose?
The lowest degree that captures the shape, judged by adjusted R², the standard error and a look at the residuals.
Is polynomial regression a type of linear regression?
Yes. It is linear in the coefficients, so the same least-squares method applies.
Why does the page centre and scale x?
Powers of large x values become huge and nearly dependent, which makes the equations unstable. Rescaling avoids that.
Sources: NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression