R-Squared LINEST does not match chart value

dunlop407703

New Member
Joined
Oct 8, 2014
Messages
24
I have a data set of x and y values, my aim is to come up with a formula which I can use to input an x value to give me the expected y value.

When I plot my data on a scatter chart, using a 3rd order polynomial trend line I get an r-squared value of 0.8402. When I use LINEST to get an r-squared value for the exact same data set I get an r-squared value of 0.7207.

Also, when I use the same x value in both the equation generated from the chart, and from LINEST I get different results. On this comparison using x=1.4, my chart formula returns y=12.1912, but my LINEST returns y=11.76757.

I'm curious to know why I am getting different results, and ultimately which is more accurate. In the past I would just have used the chart equation but I am working with a dynamic data set and I'm not aware of a way to have the chart update as I enter new data, and also to pull the regression equation out of the chart without manually typing it.

I'd really appreciate any insight or help.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi,

I suspect that you are using LINEST in such a way that it is giving you the statistics for a linear fit and not a polynomial one.

Here is an example of a cubic fit:

Excel 2013
ABCDEFGHI
1xy666
20486.8006x^3x^2x^1x^0
31579.6145Coeffs0.6493634.660717-28.2515518.2018
42510.7612Std Err2.32732931.91921119.501117.3971
53329.2976R^20.80724129.3459#N/A#N/A
64509.2647F8.3756066#N/A#N/A
75652.5988Sum of Sqs420380.8100382.2#N/A#N/A
86769.0935
97780.566
108729.2849
1191206.685
Sheet1
Cell Formulas
RangeFormula
B2=A2^3+2*A2^2+$C$1*RAND()
B3=A3^3+2*A3^2+$C$1*RAND()
B4=A4^3+2*A4^2+$C$1*RAND()
B5=A5^3+2*A5^2+$C$1*RAND()
B6=A6^3+2*A6^2+$C$1*RAND()
B7=A7^3+2*A7^2+$C$1*RAND()
B8=A8^3+2*A8^2+$C$1*RAND()
B9=A9^3+2*A9^2+$C$1*RAND()
B10=A10^3+2*A10^2+$C$1*RAND()
B11=A11^3+2*A11^2+$C$1*RAND()
F3:I7{=LINEST(B2:B11,A2:A11^{1,2,3},,TRUE)}
Press CTRL+SHIFT+ENTER to enter array formulas.

I have tried to label the cells but the Microsoft site has the detail: {mn,mn-1,...,m1,b;sen,sen-1,...,se1,seb;r2,sey;F,df;ssreg,ssresid}
See: https://support.office.com/en-gb/article/LINEST-function-84d7d0d9-6e50-4101-977a-fa7abf772b6d

Some details of how to use LINEST can be found here: Polynomial regression
and here: www.colby.edu/chemistry/PChem/notes/linest.pdf

Regards,
 
Upvote 0
Hi

You should get the same value.

A common error is to display just a few decimals in the coefficients of the equation displayed in the chart.

Can you post the equation displayed in the chart?
 
Upvote 0
Hi,

I suspect that you are using LINEST in such a way that it is giving you the statistics for a linear fit and not a polynomial one.

Some details of how to use LINEST can be found here: Polynomial regression
and here: www.colby.edu/chemistry/PChem/notes/linest.pdf

Regards,

Hi Rick,

I'm pretty sure I am using the right polynomial regression, although I don't understand them fully I admit.

For more info this is a sample of my worksheet. Apologies I don't know how to nicely put data into my comment.

ABCDEFGHIJKL
1
2
3
4SEAMCOUNTbC1C2C3RSQR-SQ LINEST
5WU485197.548-10996.37694.011-1775.210.7207301320.720730132

<tbody>
</tbody>











Formulas

CellFormula
E5
=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3}),1,4)

<tbody>
</tbody>
F5
=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3}),1,3)

<tbody>
</tbody>
G5
=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3}),1,2)

<tbody>
</tbody>
H5
=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3}),1)

<tbody>
</tbody>
J5
=RSQ(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5))

<tbody>
</tbody>
K5
=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5),TRUE,TRUE),3,1)

<tbody>
</tbody>

<tbody>
</tbody>

From my chart

Equation
y=-1775.2x3+7694x2-10996x+5197.5

<tbody>
</tbody>
R-Squared
R2 =0.8402

<tbody>
</tbody>

<tbody>
</tbody>

Cheers
 
Upvote 0
Hi

To find the value of r-squared you can use the linest function, like the formula that you used in K5, but you forgot the ^{1,2,3} that you used correctly in all the other Linest() functions

in K5:

=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3},TRUE,TRUE),3,1)
 
Upvote 0
Any reason not to select a 5-row by 4-column range, type this into the top left cell, and press Ctrl+Shift+Enter?

LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3})

Otherwise, I think each of your cells with the formula is calculating its own LINEST formula, making it go more slowly.
 
Upvote 0
Hi

To find the value of r-squared you can use the linest function, like the formula that you used in K5, but you forgot the ^{1,2,3} that you used correctly in all the other Linest() functions

in K5:

=INDEX(LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3},TRUE,TRUE),3,1)

That fixed it, thank you!
 
Upvote 0
Any reason not to select a 5-row by 4-column range, type this into the top left cell, and press Ctrl+Shift+Enter?

LINEST(OFFSET(CQDB_Filter!W$3,0,0,C5),OFFSET(CQDB_Filter!X$3,0,0,C5)^{1,2,3})

Otherwise, I think each of your cells with the formula is calculating its own LINEST formula, making it go more slowly.

I'm sure there is probably unnecessary parts to my workbook but I'm, not sure if this would be a good update to make.

Where I displayed one row of data previously, in reality I am doing this activity on a table of data similar to the below but with nearly 90 rows.

ABCDEFGHIJKL
4SEAMCOUNTbC1C2C3RSQR-SQ LINEST
5WU485197.548-10996.37694.011-1775.210.7207301320.720730132
6WIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
7LXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<tbody>
</tbody>










The data being accessed by the "OFFSET(CQDB_FILTER!W$3,0,0,C5)" part of the formula is data generated using a large number of array formulas as is and my understanding was that array formulas on large amounts of data would slow down the workbook.

If you are interested I would be more than happy to share the workbook with you to see if you have a more elegant solution.
 
Upvote 0
If I had that much to do, I would probably put blocks of LINEST array formulas on a backup worksheet, and my 90 row table would link to the appropriate cells of these LINEST blocks.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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