+ Reply to Thread
Results 1 to 13 of 13

LINEST Function returning different Value from Trendline, Questions regarding MMULT fix

  1. #1
    Registered User
    Join Date
    11-19-2022
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    6

    Question LINEST Function returning different Value from Trendline, Questions regarding MMULT fix

    Hi!

    I had a problem when I was trying to fit some values into an equation using LINEST, it returned 0 for some coefficients. It clearly was different from the equation given by the trendline. I read from some forums that this was because of the precision limitation of excel however, I was able to discover some function somewhere that uses something like this

    =MMULT(LINEST(D4:D8,(C4:C8-AVERAGE(C4:C8))^{1,2,3,4}),IFERROR(COMBIN({4;3;2;1;0},{4,3,2,1,0})*(-AVERAGE(C4:C8))^({4;3;2;1;0}-{4,3,2,1,0}),0))

    This has been bugging me for 3 months already, my mathematics isn't that advanced so I learned about some simple matrix ideas just like getting the roots using Inverse Matrix and I used that instead to get the coefficients. It worked for some order however as I reached higher orders the discrepancy was more prominent. I have been trying to find the concept behind what the MMULT function is. I tried to separate the function into its parts. I noticed that he used LINEST to determine an equation of a line with respect to the deviations of the X's from the average, then he used some concept to rescale it back to the original value.

    Can somebody shed some light on how this works or if that's not possible what concept is this in matrixes so I can read about it. It's been constantly passing my mind for 3 months already and I always think how he did it while doing other things. If there are other ways to get the coefficients that would be great too. Thanks!

    I've attached the sample excel regarding my work


    MMULT.xlsx

  2. #2
    Registered User
    Join Date
    11-19-2022
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    6

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Bumping Up!

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,369

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    My first observation, since I don't have Excel on this computer, is that LINEST() and your MMULT(...) function return the same coefficients when opened in LO Calc. Perhaps one solution is to move away from Excel for this?

    Years ago, when I first upgraded from 2002 to 2007, I encountered an issue with LINEST() incorrectly detecting collinearity and forcing regression constants to 0. A registry mod was suggested in accordance with a MSFT kb article: https://www.excelforum.com/excel-for...ion-error.html

    Not sure if any of that really helps, but maybe another bump if nothing else.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    11-19-2022
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    6

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    I also read that this was something about collinearity and excel recognizing those coefficients as not important, another reason I found out for this issue was because of the relative size of my X's compared to their differences. My X-values are 682,683,684,686,686 with some decimal point, I noticed that if the differences are big enough like 650,660,670,680,690 the linest functions works perfectly well.

    I'm just very curious what concept was used to rescale this function that
    seemingly came from "scaled down X values (deviations from average)" -0.002792777 -0.001848141 0.007677567 -0.101549847 0.408487246

    and using matrices he was able to scale it up to the function with original x's -0.002792777 7.648467801 -7854.949122 3585331.605 -613685800.9

    I'm sure I'm not going to be using the function again but I can't help but be curious, and the fact that it's bugging me everyday for the past 3 months is another thing. I'll bump this up frequently, maybe one day somebody might be able to answer. I'll probably ask in Mathematics Focused Forums maybe they'll be able to help.

    Thanks McShorty!!

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Just watching this... if you DO get any feedback elsewhere, can I ask you to provide a link here?
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    I am no mathematician/statistician, not at all. I'm an analytical chemist, who likes playing with numbers. I've been playing with your data and other datasets. The problem seems to arise when a polynomial fit, with an order HIGHER than that NEEDED to achieve a good fit, is used in LINEST.

    Using a 2nd, or even a 3rd order polynomial fit on your dataset, LINEST works perfectly.

    The problem then is defining what is meant by "higher than that needed".

    Fascinating...
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-19-2022
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    6

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    If I get some results from elsewhere, I'll make sure to share it here.


    Your exactly correct I tried it with other data points and yeah it happens as you've stated. There are two problem that I've noticed 1 is your point which when there is too few data points compared to the order, and also the relative size of their differences compared value itself as I stated in the previous post like 862 863 the difference is just 1 compared to the size of 862, it probably fails some precision test of excel specially since in higher order these are being magnified since its raised to the order .

    Regarding the excel itself I'm actually quite convinced that this has occurred due to precision limits of excel and their collinearity test in LINEST Function however, what I'm really curious about is what concept the method was in Algebra or Matrices

    Yeah it's really fascinating, that's why its bugging me for months.

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    I daresay you also saw this page:

    https://newtonexcelbach.com/2011/01/...curve-fitting/

    I tried the

    =MMULT(MMULT(TRANSPOSE(Y),X^N),MINVERSE(MMULT(TRANSPOSE(X^N),X^N)))

    formula in Lori Millar's comments at the end.... but (unless I was doing something daft) it, too went a bit odd with higher order polynomials. Your MMULT/LINEST combination, however, does seem pretty robust. I tidied it up a little, converting it to a O365 friendly format and will keep it for future use.

    =LET(x,C4:C8,y,D4:D8,n,2,MMULT(LINEST(y,(x-AVERAGE(x))^SEQUENCE(,n)),IFERROR(COMBIN(SEQUENCE(n+1,,n,-1),SEQUENCE(,n+1,n,-1))*(-AVERAGE(x))^(SEQUENCE(n+1,,0,-1)-SEQUENCE(,n+1,0,-1)),0)))

    where the value in red is the polynomial order.

  9. #9
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Quote Originally Posted by MrShorty View Post
    when I first upgraded from 2002 to 2007, I encountered an issue with LINEST() [...] forcing regression constants to 0.
    When I open the Excel file (click here) attached to the 2013 thread in __manual__ calculation mode, I do indeed see zero for the first LINEST coefficient in two of three examples (I3 and I4).

    But when I enable __automatic__ calculation mode in Excel 2010, the LINEST coefficients are corrected.

    They equal the values returned by SLOPE to 15 significant digits. In fact, their binary values differ by only 1 in the least-significant bit; probably a binary arithmetic anomaly.

    So whatever problem existed in Excel 2007 seems to have been corrected, assuming MSFT did not screw it up again in a later release.

    (FYI, the LINEST coefficients are also corrected in Web Excel at onedrive.live.com.)

    -----
    Quote Originally Posted by MrShorty View Post
    A registry mod was suggested in accordance with a MSFT kb article
    Be that as it may, it would be nice know what the registry mod was.

    The URL for the MSFT KB article (click here) no longer works. No surprise.

    But I'm surprised that I cannot find the KB article in a wiki database that I discovered some time ago (click here).

    Did you happen to keep a copy of the KB article?

    Or do you happen to remember the (9-year-old !) registry mod?
    Last edited by curiouscat408; 11-20-2022 at 04:14 PM. Reason: cosmetic

  10. #10
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Quote Originally Posted by poternerer2 View Post
    I had a problem when I was trying to fit some values into an equation using LINEST, it returned 0 for some coefficients. It clearly was different from the equation given by the trendline.
    It doesn't surprise me that the LINEST and trendline coefficients might be very different.

    The trendline understands that we are trying to fit an order-4 polynomial. It might have a special algorithm for that.

    In contrast, LINEST sees only 4 "independent" variables. It uses a multiple linear regression algorithm (click here).

    Quote Originally Posted by poternerer2 View Post
    I also read that this was something about collinearity and excel recognizing those coefficients as not important
    I'm not surprised that LINEST might find collinearity among one or more of those "independent" variables. For your x-values in C4:C8:

    RSQ(C4:C8, C4:C8^2) = 0.999999204972925
    RSQ(C4:C8, C4:C8^3) = 0.999996820402988
    RSQ(C4:C8, C4:C8^4) = 0.999992847079310

    where 1 indicates an exactly linear relationship. Perhaps more to the point:

    1-RSQ(C4:C8, C4:C8^2) = 7.95E-07
    1-RSQ(C4:C8, C4:C8^3) = 3.18E-06
    1-RSQ(C4:C8, C4:C8^4) = 7.15E-06

    My guess: LINEST considers 1-RSQ < 1E-6 or equivalently RSQ > 0.999999 to be "collinear".

    I don't see a problem with that.

    PS.... That is over-simplified to provide the gist of it. We really need to look at the multicorrelation of each variable with all of the others.

    -----
    Quote Originally Posted by poternerer2 View Post
    I read from some forums that this was because of the precision limitation
    IMHO, that would only explain relatively small differences.

    -----
    Quote Originally Posted by poternerer2 View Post
    I was able to discover some function somewhere that uses something like this
    Please Login or Register  to view this content.
    It would be nice know where "somewhere" is (URL) and what "something" is (specific data model and solution for it).

    Off-hand, I cannot imagine why that formula would work, especially the use of COMBIN. But admittedly, I haven't taken even a millisecond to try to understand it.

    In contrast, the formula presented by Lori Miller in comments (click here; thanks to Glenn) might be derived directly from the math formulas in the Multicollinearity wikipage (click here), cited by Lori, and in the Linear Regression wikipage (click here).

    -----
    Quote Originally Posted by poternerer2 View Post
    Can somebody shed some light on how this works or if that's not possible what concept is this in matrixes so I can read about it.
    That's my question, as well. It has been 50 years since I worked with math like this. Unfortunately, I've forgotten it all; and I don't have the patience to relearn it.

    -----
    PS.... Besides the wikipage references above, the following are some other references that might be useful.
    https://www.real-statistics.com/mult...n/collinearity
    https://www.real-statistics.com/mult...hout-intercept

    Disclaimer: I have not read these pages myself. And I do not have the blind faith in the website that others do. I often find mistakes -- some significant -- when I do a deep-dive. But he usually does a good job of explaining the concepts. (But not for this, IMHO.)
    Last edited by curiouscat408; 11-21-2022 at 12:10 PM. Reason: cosmetic; PS

  11. #11
    Registered User
    Join Date
    11-19-2022
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    6

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Thank you everybody for giving your thoughts on this, even the discussion itself is helpful I've learned a lot of possible resources I could read.

    Quote Originally Posted by curiouscat408 View Post
    When I open the Excel file attached to the 2013 thread in __manual__ calculation mode, I do indeed see zero for the first LINEST coefficient in two of three examples (I3 and I4).
    For your data set my excel also works and linest gives the same as the trendline. However for the data set like mine it still returns 0 coefficients


    Quote Originally Posted by curiouscat408 View Post
    It would be nice know where "somewhere" is (URL) and what "something" is (specific data model and solution for it).
    So I retraced the questions I had last 3 months and searched google and I was able to find where I found the function
    Its on the website "mrexcel.com cubic coefficients using linest 936926" just search that in google since I an't post links yet.

    However, there really isn't a concept being mentioned there.


    Additionally, in the website stated earlier
    Lori Miller stated on
    December 6, 2011 at 10:38 am
    That collinearity could be removed by centering around the mean, which is what is seen in the function, when he got a equation of the line using the function

    LINEST(D4:D8,(C4:C8-AVERAGE(C4:C8))^{1,2,3,4})

    However, she didn't mention how to rework back to the original equation after you got the equation using the values centered around the mean.

  12. #12
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Quote Originally Posted by poternerer2 View Post
    So I retraced the questions I had last 3 months and searched google and I was able to find where I found the function
    Its on the website "mrexcel.com cubic coefficients using linest 936926" just search that in google since I an't post links yet.
    Thanks for the pointer.

    For posterity, I find it at https://www.mrexcel.com/board/thread...-linest.936926 .

    And to work around the forum limitation (until you have enough postings), you can edit URLs as follows:

    mrexcel dot com /board/threads/cubic-coefficients-using-linest.936926

  13. #13
    Registered User
    Join Date
    11-19-2022
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    6

    Re: LINEST Function returning different Value from Trendline, Questions regarding MMULT fi

    Bumping Up!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Trendline and linest gives incoherent results
    By olhey in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-10-2019, 09:25 AM
  2. Mmult returning #value!
    By pliger in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-04-2019, 10:51 PM
  3. [SOLVED] Adding a Polynomial Trendline Using Linest
    By danielexcelvba in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-18-2018, 01:53 PM
  4. Linest and chart trendline show different results
    By VictorOnline in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 12-01-2016, 11:28 AM
  5. Linest different from trendline
    By Fishhooky in forum Excel General
    Replies: 6
    Last Post: 10-16-2012, 06:26 AM
  6. Trendline Coefficients Differ from Linest
    By jzmuda in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 05-28-2009, 04:44 PM
  7. Why does LINEST vs. Trendline give different values?
    By gshock in forum Excel General
    Replies: 5
    Last Post: 09-02-2008, 03:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1