+ Reply to Thread
Results 1 to 11 of 11

LINEST for specifying polynomial regression function

  1. #1
    Registered User
    Join Date
    01-07-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    LINEST for specifying polynomial regression function

    Hi Guys,

    I am trying to specify a polynomial regression function which best matches a trend of data, to forecast future data. I would like some help on specifying the best structure of the regression equation, and I understand LINEST is the best way to achieve this goal. Using the trend fitter on the data, I understand a polynomial approach is the best way to do so.

    I have attached some example info which has a known variable, column Y, which I am trying to explain by the independent variables X (A->E), so it is a multivariate approach.

    Can we assume a polynomial order of 3 for simplicities sake?

    Your assistance is appreciated,

    Thanks
    InderpalHothi
    Attached Files Attached Files

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

    Re: LINEST for specifying polynomial regression function

    The first thing I would do is define exactly what this "polynomial" equation will look like. If I understand correctly, you have 5 independent variables. Multiply that by every possible combination of 4 exponents (0,1,2,3) for a cubic polynomial, and you have a lot of possible terms. Once you define the desired terms for the regression equation, then it will be easier to build the regression matrix for the LINEST() function.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    01-07-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: LINEST for specifying polynomial regression function

    Hi Mrshorty,

    In terms of specifying the best function for the equation, or curve fitting, is there an excel aided function which does this? I have been messing around and trying loads of differentpolynomial equations and then running regressions, seeing which produces the best results, but perhaps I misunderstood as I thought linest could help with curve fitting?

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

    Re: LINEST for specifying polynomial regression function

    Does your math education extend to linear algebra? The "linear" in linear regression/LINEST() refers to linear functions in this sense. All polynomials are "linear" functions when looked at in this way, and can, therefore, be regressed using the LINEST() function. (To within the limitations of number of predictor variables and numerical stability of the matrix inversion algorithms). Once you specify a polynomial, you should be able to build a regression matrix based on that polynomial, then use the LINEST() function to regress the parameters for that polynomial.

    In cases where you are not sure which polynomial to use, Excel does not have a utility for determining which equation to use. To choose a form for the polynomial, you may need to run through a sequence like: a) choose an equation, b) regress parameters using LINEST(), c) measure and record "goodness of fit", d) choose a different equation and repeat, e) compare your "goodness of fit" scores and decide which form of the polynomial provided the "best" fit.

    I know a lot of times people try to create the regression matrix inside of the LINEST() function. That is fine for them, but I personally prefer to create the regression matrix in the spreadsheet before sending it to the LINEST() function.

    Example in attached spreadsheet.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-07-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: LINEST for specifying polynomial regression function

    I have studied linear algebra but it has been a long time...Thanks very much for your example.

    I see you have entered the formula in your spreadsheet by selecting cells R3:W4. I am having difficulty in understand the array selection for the formula input? Is it 6 columns long to reflect the 5 variables plus the intercept? I had previously thought that 5 rows x 2 columns was required to input the formula.

    And if one were to want to derive the regression statistics, would this simply by a matter of inputting a second TRUE in the formula?

    Thanks again for your help

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: LINEST for specifying polynomial regression function

    What leads you to believe a polynomial regression is appropriate for this, aside from that a polynomial with enough terms will match anything?
    Entia non sunt multiplicanda sine necessitate

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

    Re: LINEST for specifying polynomial regression function

    I see you have entered the formula in your spreadsheet by selecting cells R3:W4. I am having difficulty in understand the array selection for the formula input? Is it 6 columns long to reflect the 5 variables plus the intercept? I had previously thought that 5 rows x 2 columns was required to input the formula.
    Row 3 is technically not a part of the LINEST() function -- in row 3 I have merely entered text labels so I know which cell contains which parameter.

    The reason for selecting a 1row by 6column array for the function output is that I have 6 parameters: the 5 "m" parameters + the final constant b, so you understood this correctly. LINEST() always outputs one more value than there are columns in the known_x matrix. You can force b to be 0 by putting FALSE in the third argument, but it is still part of the output. I'm not sure how many terms/parameters you are expecting to use in your final equation, so this may need to be larger (or smaller, though LINEST() will output N/A if you select a larger array that it actually outputs) depending on the actual equation you are going to use.

    I'm not sure where you got the idea that LINEST()'s output was in column. To my knowledge, LINEST() has always output a horizontal array. Nested inside the TRANSPOSE() function, you can get it to output a vertical array [=TRANSPOSE(LINEST(...))] if you want.

    Yes, you can access the additional statistics by adding the fourth argument = TRUE. The help file for the LINEST() function: http://office.microsoft.com/en-us/ex...in=HA010277524 The arrangement of the output matrix is shown in a table near the bottom of this page.

  8. #8
    Registered User
    Join Date
    01-07-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: LINEST for specifying polynomial regression function

    Hi Shg,

    I had to change the data before i posted it.

    With the original data, I used the trend line function and polynomial was the best match.

    By chance through changing the formula for many iterations and running multiple regressions through Excel, I came to a formula which matched the data output very closely, with some variables raised to the 3,5,7 powers.

    The regression statistics are relatively good for my requirements, posted below, but the point of me posting on here was to figure out a way to get to a good formula without guessing the specification

    SUMMARY OUTPUT

    Regression Statistics
    Multiple R 0.986615709
    R Square 0.973410558
    Adjusted R Square 0.911368525
    Standard Error 7.450439496
    Observations 21

    ANOVA
    df SS MS F Significance F
    Regression 14 12192.75523 870.911088 15.68953366 0.001399904
    Residual 6 333.0542921 55.50904868
    Total 20 12525.80952

    Coefficients Standard Error t Stat P-value Lower 95% Upper 95% Lower 95.0% Upper 95.0%
    Intercept 211.5990632 94.17886035 2.246778762 0.065731597 -18.84830628 442.0464327 -18.84830628 442.0464327
    A 3.73593E-07 1.88105E-07 1.986081011 0.094226422 -8.66848E-08 8.3387E-07 -8.66848E-08 8.3387E-07
    A^3 -1.70923E-25 4.80381E-26 -3.55806308 0.011955073 -2.88468E-25 -5.33776E-26 -2.88468E-25 -5.33776E-26
    A^5 2.66019E-44 7.52189E-45 3.536594134 0.012269364 8.19647E-45 4.50073E-44 8.19647E-45 4.50073E-44
    A^7 -1.29419E-63 3.64289E-64 -3.552653424 0.012033419 -2.18558E-63 -4.0281E-64 -2.18558E-63 -4.0281E-64
    B -6.27862E-08 1.11684E-07 -0.56217558 0.594359712 -3.36068E-07 2.10495E-07 -3.36068E-07 2.10495E-07
    B^3 -4.86615E-26 1.72492E-26 -2.821081049 0.030311032 -9.08689E-26 -6.45414E-27 -9.08689E-26 -6.45414E-27
    C 2.06182E-07 4.36931E-08 4.718876181 0.003261797 9.92691E-08 3.13095E-07 9.92691E-08 3.13095E-07
    C^3 -2.1493E-26 5.37479E-27 -3.998850675 0.007128305 -3.46446E-26 -8.34134E-27 -3.46446E-26 -8.34134E-27
    C^5 1.20151E-45 3.27443E-46 3.669381749 0.010461938 4.0029E-46 2.00274E-45 4.0029E-46 2.00274E-45
    C^7 -2.086E-65 6.52291E-66 -3.197969114 0.018647779 -3.6821E-65 -4.89908E-66 -3.6821E-65 -4.89908E-66
    D -2.0897E-07 9.49093E-08 -2.201786506 0.069929878 -4.41205E-07 2.32647E-08 -4.41205E-07 2.32647E-08
    D^3 1.51978E-26 3.9326E-27 3.864573544 0.008318047 5.57509E-27 2.48205E-26 5.57509E-27 2.48205E-26
    E 2.06376E-07 9.48272E-08 2.176338977 0.072426008 -2.56577E-08 4.3841E-07 -2.56577E-08 4.3841E-07
    E^3 -8.75271E-27 6.98088E-27 -1.253812953 0.256548313 -2.58343E-26 8.32888E-27 -2.58343E-26 8.32888E-27

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: LINEST for specifying polynomial regression function

    I have no idea how to make a best selection. In addition to the single-regressor terms, there are potentially all of the cross terms. Just for squares (coefficients omitted),

    y =
    A^0 B^0 C^0 + A^1 B^0 C^0 + A^2 B^0 C^0 +
    A^0 B^1 C^0 + A^1 B^1 C^0 + A^2 B^1 C^0 +
    A^0 B^2 C^0 + A^1 B^2 C^0 + A^2 B^2 C^0 +

    A^0 B^0 C^1 + A^1 B^0 C^1 + A^2 B^0 C^1 +
    A^0 B^1 C^1 + A^1 B^1 C^1 + A^2 B^1 C^1 +
    A^0 B^2 C^1 + A^1 B^2 C^1 + A^2 B^2 C^1 +

    A^0 B^0 C^2 + A^1 B^0 C^2 + A^2 B^0 C^2 +
    A^0 B^1 C^2 + A^1 B^1 C^2 + A^2 B^1 C^2 +
    A^0 B^2 C^2 + A^1 B^2 C^2 + A^2 B^2 C^2

    That's 27 possible coefficients (including the constant term) to regress 21 points if there were only three regressors. Increasing that to 7th order and your five regressors gives you a choice of 8^5 -1 (32767) terms, from which you could choose at most 20 (plus the constant term). More choices than the number of quarks in the universe (maybe).

    Your solution, using a little different approach that lets you explore the terms, is attached.
    Attached Files Attached Files
    Last edited by shg; 03-27-2014 at 01:20 PM.

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

    Re: LINEST for specifying polynomial regression function

    a polynomial with enough terms will match anything?
    I'm reminded of a saying that gets kicked around our office a lot. Wikiquotes attributes it to John von Neumann. "With four parameters I can fit an elephant. With five I can make him wiggle his trunk." http://en.wikiquote.org/wiki/John_von_Neumann

    Whenever we talk about high order polynomials as fitting equations, there does come a point where we get concerned with "overfitting" the data. I'm not sure exactly how one judges "adequate fit" vs "overfit" -- I'm not enough of a statistician.

    I have heard of cases where a researcher/mathematician would start with an "excess" of parameters in their modeling equation. Then, through a series of statistical tests, would identify which terms/parameters were most significant and which were less significant in predicting the dependent variable. I'm not enough of a statistician to talk about the statistical tests that would be used. Excel doesn't have them pre-programmed in (though I expect they could be programmed into Excel by someone who was familiar with the statistical algorithms), and I would not be surprised to find no applications with those algorithms pre-programmed in.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: LINEST for specifying polynomial regression function

    Quote Originally Posted by MrShorty View Post
    "With four parameters I can fit an elephant. With five I can make him wiggle his trunk."
    :ROFL: I have never heard that.

+ 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. Help with multiple regression using LINEST function
    By joe71010 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-25-2013, 11:56 AM
  2. Converting a polynomial LINEST formula to VBA
    By AARONWEBSTER in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2012, 12:23 PM
  3. Extract polynomial coefficients with LinEst in VBA
    By shamedt in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-22-2011, 08:45 PM
  4. Replies: 5
    Last Post: 06-25-2009, 10:25 AM
  5. [SOLVED] How to clear "linest ( ) function error " in regression analysis?
    By dev in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 08-21-2005, 04:05 PM

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