Cubic Regression Calculator

Enter the x and y values of your points to fit a cubic.

Numbers separated by commas.

The same number of numbers as the x values.

Try

Result

You entered4 points\text{4 points}

y=13x3−x2+83x\displaystyle y = \frac{1}{3}x^{3} - x^{2} + \frac{8}{3}x

R²

R2=1\displaystyle R^2 = 1
Show the work
  1. Least-squares cubic fit

    Choose a, b, c and d to make the sum of the squared vertical gaps between the points and the curve as small as possible. Setting each partial derivative to zero gives four linear equations, the normal equations.

    Using y=ax3+bx2+cx+dy = ax^3 + bx^2 + cx + d

    ∑x3y=a∑x6+b∑x5+c∑x4+d∑x3∑x2y=a∑x5+b∑x4+c∑x3+d∑x2∑xy=a∑x4+b∑x3+c∑x2+d∑x∑y=a∑x3+b∑x2+c∑x+dn\begin{aligned} \textstyle\sum x^3y &= a\sum x^6 + b\sum x^5 + c\sum x^4 + d\sum x^3 \\ \textstyle\sum x^2y &= a\sum x^5 + b\sum x^4 + c\sum x^3 + d\sum x^2 \\ \textstyle\sum xy &= a\sum x^4 + b\sum x^3 + c\sum x^2 + d\sum x \\ \textstyle\sum y &= a\sum x^3 + b\sum x^2 + c\sum x + dn \end{aligned}
  2. Sums for the normal equations

    With n = 4 points, in exact fractions.

    ∑x1=10, ∑x2=30, ∑x3=100, ∑x4=354, ∑x5=1300, ∑x6=4890, ∑x0y=30, ∑x1y=98, ∑x2y=346, ∑x3y=1274\textstyle\sum x^{1} = 10,\ \textstyle\sum x^{2} = 30,\ \textstyle\sum x^{3} = 100,\ \textstyle\sum x^{4} = 354,\ \textstyle\sum x^{5} = 1300,\ \textstyle\sum x^{6} = 4890,\ \textstyle\sum x^{0}y = 30,\ \textstyle\sum x^{1}y = 98,\ \textstyle\sum x^{2}y = 346,\ \textstyle\sum x^{3}y = 1274
  3. Solving the normal equations

    Elimination in exact fractions gives the four coefficients.

    a=13, b=−1, c=83, d=0a = \frac{1}{3},\ b = -1,\ c = \frac{8}{3},\ d = 0
  4. Coefficient of determination

    R² is the share of the spread in y that the cubic explains; 1 means every point is on the curve.

    R2=1−SSresSStot=1−0115=1\begin{aligned} R^2 &= 1 - \dfrac{SS_{res}}{SS_{tot}} \\ &= 1 - \frac{0}{115} \\ &= 1 \end{aligned}
  5. Result

    The best cubic fit.

    y=13x3−x2+83xy = \frac{1}{3}x^{3} - x^{2} + \frac{8}{3}x

Worked examples