Consulting

Results 1 to 7 of 7

Thread: Sleeper: Linear interpolation in Excel

  1. #1

    Sleeper: Linear interpolation in Excel

    Hi,

    I am using FORECAST function in Excel to estimate values using linear interpolation. My input data is as follows

    0.04
    0.50%
    0.08
    0.65%
    0.25
    0.80%
    0.50
    1.05%
    1.00
    1.40%
    2.00
    1.80%
    3.00
    2.10%
    5.00
    2.50%
    10.00
    3.05%
    15.00
    3.50%
    20.00
    4.00%
    30.00
    4.50%

    Now I estimate the values at below points

    0.50
    1.00
    1.50
    2.00
    2.50
    3.00

    However using FORECAST() function I get below estimates

    0.50
    1.27%
    1.00
    1.34%
    1.50
    1.40%
    2.00
    1.47%
    2.50
    1.53%
    3.00
    1.60%

    This looks strange to me. Because, as per the input data, the values corresponding to x = 1 is 1.40%. However FORECAST() function estimates 1.34%. This also differs from corresponding estimates from VBA'a LINTERP() function which gives estimate as 1.40%.

    Am I doing any mistake correctly using FORECAST() function?

    Any pointer will be very helpful.

    Thanks for your time.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Looks expected, but not too accurate since FORECAST assumes linear interpolation, but your data look expotential

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    there is also a tutorial here using Forecast() on linear interpolation:
    Linear Interpolation in Excel | How to do Linear Interpolation with Examples (wallstreetmojo.com)

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Quote Originally Posted by volabos View Post
    I am using FORECAST function in Excel to estimate values using linear interpolation. My input data is as follows
    You could write a formula to do linear interpolation between only the two points above and below the x value you're trying to get the y value of, but it still wouldn't be very accurate.
    In the attached, I've plotted your data and added a trendline to the chart and the trendline which best fits your data is a Power trendline. I've also shown the equation and the R-squared (0.9984) on the chart which means it's a good fit.
    The equation shown on the chart has had a few digits added to it using the method described here: https://www.ablebits.com/office-addi...dline-equation
    I've copied those values to cells C15:C16 and used them in the formulae in cells C17:C23. The results are good. A fiddly solution.

    Another way is to dispense with the equation on the chart (and the chart) and calculate for ourselves the 2 coefficients, that's been done in cells E15:E16. Cells E17:E23 do the interpolation. Same results (near enough).

    You can incorporate the coefficients calculation and interpolation into a single formula, see cells G17:G23.

    If you have office 365 you can convert this formula into a lambda formula (see the Names in the workbook) which makes things a lot easier for the user. It makes a new function Forecast.Power which you use in exactly the same way as you use FORECAST and you don't anything else. This has been done in cells H17:H23. What's more, with Excel's spilling formulae you can make this into a single cell formula, see cell I17 (green highlight) which spills down:
    =Forecast.Power(A17:A23,B1:B12,A1:A12)
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    So nice when 3 people have gone to significant effort to help volabos and he can't even be bothered to feed back whether anything has helped, sigh.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,055
    Location
    Quote Originally Posted by p45cal View Post
    So nice when 3 people have gone to significant effort to help volabos and he can't even be bothered to feed back whether anything has helped, sigh.
    Sadly, it seems that there are people out there who either don't acknowledge the assistance received from others or respond to members asking for clarification to a question. My initial thinking was "Volabos is busy" and will get back to the forum, but..., in reviewing the threads created by Volabos, it seems that he creates a thread by asking a question, and then in most cases never ever responds. Since assistance is provided within the forum on a voluntary basis, (and we are extremely grateful to those who do so), then it's at your discretion as to whether any further assistance is provided. Eventually the message will get through, when very few if any, members offer to help that person.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Newbie
    Joined
    Apr 2023
    Posts
    1
    Location
    Per the documentation, the FORECAST() Function is a linear regression, not an interpolation function.
    https://support.microsoft.com/en-us/...4-7ad38bbeda99

    The regression line does not necessarily go through each data-point.

Posting Permissions

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