A cubic polynomial can bend twice, so it can follow an S-shaped trend or a curve that levels off and then rises again – growth that slows and speeds up, dose–response curves, the output of a sensor across its range or a cost curve with economies and then diseconomies of scale. Cubic regression chooses the four coefficients a₀ to a₃ that minimise the sum of squared vertical distances between the curve and your points.
Setting a₃ = 0 turns the model into quadratic regression, and setting a₂ = a₃ = 0 gives a straight line, so the cubic is a natural next step when a lower-degree fit leaves a pattern in the residuals. The coefficient table tells you whether the x³ term is statistically supported; adjusted R² tells you whether the extra flexibility is worth the extra parameter.
A cubic needs at least four distinct x values. With exactly four points it passes through all of them and you learn nothing about the fit, so aim for considerably more points than coefficients.
How to use the Cubic Regression Calculator
- x values
- y values — Same number of values as x
- Predict y at x = — Optional – leave empty to skip the prediction
- Precision (significant figures)
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
The tool forms the normal equations from the columns 1, x, x² and x³ (with x centred and scaled to avoid round-off), solves them by Gauss–Jordan elimination, converts the coefficients back to powers of x and computes residuals, R², the residual standard error and the coefficient standard errors with n − 4 degrees of freedom.
Worked example
Eight readings x = 1…8 with y = 2.1, 6.8, 8.9, 9.2, 9.8, 12.4, 18.9, 30.1 rise, level off and climb again. The least-squares cubic is y = 0.2758x³ − 3.174x² + 12.45x − 7.479 with R² = 0.99981 and residual standard error 0.156. All four coefficients have p-values below 0.0001, so the cubic term is clearly needed. The inflection point is at x = 3.174 ÷ (3 × 0.2758) ≈ 3.84. At x = 9 the curve predicts 48.49 (95% prediction interval 47.34 to 49.64), an extrapolation one step beyond the data.
Choosing the degree
| Degree | Name | Turning points | Minimum points |
|---|---|---|---|
| 1 | Linear | 0 | 2 |
| 2 | Quadratic | 1 | 3 |
| 3 | Cubic | 2 | 4 |
| 4 | Quartic | 3 | 5 |
| 5 | Quintic | 4 | 6 |
Formula
Minimise Σ(y − a₀ − a₁x − a₂x² − a₃x³)² · β = (XᵀX)⁻¹Xᵀy with columns 1, x, x², x³
Worked example
Inputs — x values: 1, 2, 3, 4, 5, 6, 7, 8; y values: 2.1, 6.8, 8.9, 9.2, 9.8, 12.4, 18.9, 30.1; Predict y at x =: 9; Precision (significant figures): 4.
Results — Regression equation = y = 0.2758x³ − 3.174x² + 12.45x − 7.479; Coefficient a₃ (x³) = 0.275758; Coefficient a₂ (x²) = -3.173918; Coefficient a₁ (x) = 12.447944; Coefficient a₀ (constant term) = -7.478571; Coefficient of determination (R²) = 0.99981.
Key terms
- Cubic polynomial
- A polynomial of degree three, a₃x³ + a₂x² + a₁x + a₀.
- Inflection point
- Where the curve changes from bending up to bending down, at x = −a₂ ÷ (3a₃).
- Normal equations
- The linear system (XᵀX)β = Xᵀy whose solution is the least-squares estimate.
- Degrees of freedom
- n minus the number of coefficients, here n − 4.
Frequently asked questions
How many points are needed for cubic regression?
At least four distinct x values. Four points give an exact fit; use eight or more to judge how well a cubic describes the data.
How do I calculate a cubic regression?
Build the matrix X with columns 1, x, x², x³, then solve (XᵀX)β = Xᵀy. The calculator does this for you and shows every coefficient.
Is a higher R² always better?
No – R² never falls when you add terms. Compare adjusted R², which can drop when a term does not help.
What shape can a cubic follow?
Up to two turning points and one inflection point, e.g. rise–plateau–rise or an S-curve.
How can I tell if the cubic term is needed?
Look at the p-value of a₃. If it is large (say above 0.05) a quadratic is probably enough.
Can I extrapolate with a cubic?
Rarely safely – the x³ term dominates outside the data and sends predictions off sharply.
Why are my coefficients huge with years as x?
Powers of large numbers like 2024 are enormous, so the coefficients become tiny or huge. Subtract a base year (use 0, 1, 2…) for readable coefficients; predictions are unchanged.