Polynomial Regression Calculator

Fit a quadratic, cubic or quartic curve to x, y data by least squares: coefficients, equation, R², adjusted R², F-test p-value and a prediction.

Use a point for decimals (1.5), no thousands separators, and separate numbers with spaces or a comma and a space.
Pair each y with the x in the same position. Up to 1000 points.

Results

Best-fit equation
y = −899.935 + 5.85716x − 0.00942488x²
Constant term (b₀)
-899.93
Coefficient of x (b₁)
5.8572
Coefficient of x² (b₂)
-0.00942488
R² (share of the variation in y explained)
0.4338
Adjusted R²
0.3583
F statistic (2 and 15 degrees of freedom)
5.747
p-value (does the curve beat a flat line?)
0.014
Residual standard error
2.6705
Predicted y at x = 310
10.054
Number of points
18

How it’s calculated

Polynomial regression fits a curve ŷ = b₀ + b₁x + b₂x² (+ b₃x³ + b₄x⁴) that minimises the sum of squared vertical distances to the points, exactly like linear regression but with extra powers of x. It suits data that rise and then fall (or the reverse). R² is the share of the variation in y that the curve explains; adjusted R² penalises the extra coefficients, and the F-test asks whether the curve explains more than a flat line would by chance.

ŷ = b₀ + b₁x + b₂x² + … + b_d x^d choose b to minimise SSE = Σ (y − ŷ)² R² = 1 − SSE / SST, SST = Σ (y − ȳ)² adjusted R² = 1 − (1 − R²)(n − 1)/(n − d − 1) F = (R²/d) / ((1 − R²)/(n − d − 1)), p from the F distribution with d and n − d − 1 df

To stay accurate, the calculator first rescales x to the range −1 to 1 and solves the least-squares problem with a QR decomposition rather than the textbook normal equations, which lose precision for large x or high degrees. The coefficients are then converted back to your original x.

Example (Handbook of Biological Statistics, LibreTexts): carapace length (mm) and clutch size of 18 gopher tortoises. The best-fit quadratic is ŷ = −899.9 + 5.857x − 0.009425x² with R² = 0.4338 (0.43 with 15 degrees of freedom, P = 0.014), while a straight line explains only 1.5%. At x = 310 mm the curve predicts about 10.05 eggs. These are the default values.

Higher degrees always raise R², so do not choose a degree just because R² goes up; watch adjusted R² and the shape of the curve, and avoid predicting outside the range of your data.

Frequently asked questions

Which degree should I use?

The lowest one that captures the shape: quadratic for one bend, cubic for an S shape. Higher degrees chase noise. A good fit should also make sense for what you are measuring.

What does R² mean here?

The fraction of the variation in y explained by the curve, from 0 to 1. It always increases with the degree, which is why adjusted R² is shown as well.

Why can the predictions be absurd outside my data?

Polynomials shoot off to plus or minus infinity beyond the data. In the tortoise example the quadratic predicts negative clutch sizes for very small or very large tortoises.

How many points do I need?

At least one more than the degree, with that many different x values. With exactly degree + 1 points the curve passes through all of them and R² is 1, which tells you nothing; use many more points than coefficients.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator