Cubic coefficients using LINEST

johnsonlort

New Member
Joined
Apr 23, 2016
Messages
4
Hi,

I am trying to LINEST to return coefficients using a cubic function in Excel 2013 but I am getting wrong results for two of the coefficients. Using the builtin Chart Trendline produces correct coefficient for my regression but LINEST (and Data Analysis Regression for that matter) produces wrong results according Microsoft (https://support.microsoft.com/en-us/kb/828533) due to collinearity.

This is my data:

xy
20067798
20078027
20089526
200911661
201016014
201118731
201223405
201325294
201428578

<tbody>
</tbody>

Results:

Coef
Chart Trendline
LINEST
x3
-62.295<strike></strike>
-62.295<strike></strike>
x2
1098.254
163.834<strike></strike>
x1
-2746.214
3564.226<strike></strike>
intercept
9528.659
15467.104<strike></strike>

CORRECT
X3 correct, rest WRONG

<tbody>
</tbody>

My first LINEST looks like this:
Code:
={LINEST(y;(x-AVERAGE(x))^{1,2,3})}

I have tried with a second LINEST function it also only calculates x3 correctly but not the x2, x1 and intercept.
Code:
=MMULT(LINEST(y;(x-AVERAGE(x))^{1,2,3});IFERROR(COMBIN({3;2;1;0};{3,2,1,0})*(-AVERAGE(x))^({3;2;1;0}-{3,2,1,0});0))

Any help is appreciated - maybe my formula are wrong?

linest.png



 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I managed to solve it. Apparently using Line, Bar and Column charts to produce coeffiecients for polynomia of "n>1" degrees will produce wrong coefficients since Line, Bar and Column charts treat the x-data as linear. So, if you are working with quadratic, cubic and higher order functions ALWAYS use an XY Scatter Plot if you want Excel to calculate the coefficients for you.

The second LINEST code is correct:
Code:
={MMULT(LINEST(y;(x-AVERAGE(x))^{1,2,3});IFERROR(COMBIN({3;2;1;0};{3,2,1,0})*(-AVERAGE(x))^({3;2;1;0}-{3,2,1,0});0))}

Indexing can of course also be used:

=INDEX(MMULT(LINEST(y;(x-AVERAGE(x))^{1,2,3});IFERROR(COMBIN({3;2;1;0};{3,2,1,0})*(-AVERAGE(x))^({3;2;1;0}-{3,2,1,0});0));1)  ' will produce x3
=INDEX(MMULT(LINEST(y;(x-AVERAGE(x))^{1,2,3});IFERROR(COMBIN({3;2;1;0};{3,2,1,0})*(-AVERAGE(x))^({3;2;1;0}-{3,2,1,0});0));2)  ' will produce x2
=INDEX(MMULT(LINEST(y;(x-AVERAGE(x))^{1,2,3});IFERROR(COMBIN({3;2;1;0};{3,2,1,0})*(-AVERAGE(x))^({3;2;1;0}-{3,2,1,0});0));3)  ' will produce x1
=INDEX(MMULT(LINEST(y;(x-AVERAGE(x))^{1,2,3});IFERROR(COMBIN({3;2;1;0};{3,2,1,0})*(-AVERAGE(x))^({3;2;1;0}-{3,2,1,0});0));4)  ' will produce intercept
=INDEX(LINEST(y;(x-AVERAGE(x))^{1,2,3};TRUE;TRUE);3) ' will produce r2

Hope somebody else will benefit from this :)
 
Upvote 0

Forum statistics

Threads
1,215,745
Messages
6,126,629
Members
449,323
Latest member
Smarti1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top