Cubic Regression Calculator Desmos: How to Use
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
Desmos does not have a dedicated “cubic regression” button, but you can perform cubic regression directly in the graphing calculator by typing a cubic expression in the form y_1 ~ ax_1^3 + bx_1^2 + cx_1 + d into a new expression line. Desmos will then compute the best-fit cubic polynomial for your data and display the coefficients a, b, c, and d along with the correlation coefficient R^2.
Formula
The cubic regression model is a polynomial of degree three:
y = a·x³ + b·x² + c·x + d
where:
yis the dependent variable (the value you want to predict).xis the independent variable (the input).ais the coefficient of the cubic term (determines the overall shape and end behavior).bis the coefficient of the quadratic term.cis the coefficient of the linear term.dis the constant term (the y-intercept).
Desmos uses the least-squares method to find the values of a, b, c, and d that minimize the sum of the squared differences between the observed y-values and the values predicted by the model.
Worked Example
Suppose you have the following data points: (1,2), (2,5), (3,10), (4,17). You want to fit a cubic model.
- Enter the x-values in one list:
x_1 = [1,2,3,4] - Enter the y-values in another list:
y_1 = [2,5,10,17] - Type the regression expression:
y_1 ~ a x_1^3 + b x_1^2 + c x_1 + d - Desmos outputs:
a = 0,b = 1,c = 0,d = 1(the model isy = x² + 1).
In this case, the data is actually quadratic, so the cubic coefficient is zero. For a true cubic dataset, such as (0,0), (1,1), (2,8), (3,27), the regression would give a = 1, b = 0, c = 0, d = 0 (exactly y = x³).
How to Use Desmos for Cubic Regression
Follow these steps in the Desmos graphing calculator (desmos.com/calculator):
- Click the + button and choose table.
- Enter your x-values in the first column and y-values in the second column. Desmos automatically names them
x_1andy_1. - Click on the next empty expression line (the one below the table).
- Type:
y_1 ~ a x_1^3 + b x_1^2 + c x_1 + d - Press Enter. Desmos will display the values of
a,b,c, anddin a small box near the expression, along withR^2.
You can also type the lists directly without a table, e.g., x_1 = [1,2,3,4] and y_1 = [2,5,10,17].
How to Choose Between Quadratic and Cubic Regression
Use a cubic model when the data shows two bends (an inflection point) or when a quadratic model leaves a clear pattern in the residuals. For example, a car’s fuel efficiency vs. speed often rises then falls, which a quadratic can capture; but if the data also levels off at high speed, a cubic might fit better.
Check the R^2 value: closer to 1 means a better fit. However, adding more terms (like going from quadratic to cubic) always increases R^2 on the training data, so use judgment. If the cubic coefficient a is very small relative to the other coefficients, the cubic term may not be meaningful.
Common Mistakes and How to Avoid Them
- Forgetting the tilde (~): The tilde tells Desmos to perform regression. If you use an equals sign, it will just plot the expression without fitting.
- Using the wrong variable names: If you type
y ~ ax^3 + bx^2 + cx + dwithout the subscript1, Desmos may not know which lists to use. Always reference your actual list names (usuallyx_1andy_1). - Not checking the residual plot: A good fit should have residuals randomly scattered around zero. If they form a curve, a higher-degree polynomial might be needed.
- Overfitting: A cubic can fit four points perfectly, but that doesn’t mean it will predict well. Use the model only within the range of your data.
Limitations of Cubic Regression
Cubic regression can exhibit wild behavior outside the data range. The end behavior of a cubic is determined by the sign of a: if a is positive, the curve goes up to the right and down to the left; if negative, the opposite. This can produce unrealistic predictions if you extrapolate too far.
Also, cubic regression requires at least four data points to determine the four coefficients. With exactly four points, the curve will pass through all of them (perfect fit), but that may not reflect the true relationship.
For data with more than two bends, consider higher-degree polynomials or splines, but be aware of overfitting.
Alternatives to Desmos for Cubic Regression
If you don’t have internet access or prefer a different tool, you can use:
- Microsoft Excel: Add a polynomial trendline of order 3 to a scatter plot.
- Google Sheets: Use the
LINESTfunction with a cubic array. - Python: Use
numpy.polyfit(x, y, 3). - A graphing calculator (TI-84): Use the
CubicRegfunction in the STAT menu.
Desmos is often the fastest because it requires no software installation and shows the curve immediately.
Frequently Asked Questions
How do I get Desmos to show the regression equation?
After typing the regression expression, Desmos displays the coefficients in a small box. To see the full equation, click the Show button (the folder icon) next to the expression, or use the R^2 value to assess fit.
Can Desmos do cubic regression on a table?
Yes, that’s the standard way. Create a table, enter your data, then type y_1 ~ a x_1^3 + b x_1^2 + c x_1 + d in the next expression line.
Why does my regression give a very large R^2 but the curve looks wrong?
This can happen if you have outliers or if the data has a pattern that a cubic can’t capture (like seasonal cycles). Check the residual plot and consider whether a different model (e.g., exponential) might be more appropriate.
What does the R^2 value mean in Desmos?
R^2 is the coefficient of determination, indicating how much of the variation in y is explained by the model. A value of 1 means a perfect fit, 0 means no linear relationship.
Can I use cubic regression to predict future values?
Only with caution. Extrapolation beyond the data range is risky because the cubic’s end behavior may not reflect reality. Always validate with domain knowledge.
Related
Formula used
in x | x value | - | 1 | -100 in y | y value | - | 2 | -100 out a | Cubic coefficient a | - | 0 | 6 out b | Quadratic coefficient b | - | 0 | 6 out c | Linear coefficient c | - | 1 | 6 out d | Constant d | - | 0 | 6 out fit | Predicted y at x=1 | - | a*1^3 + b*1^2 + c*1 + d | 4
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.