+ Reply to Thread
Results 1 to 8 of 8

Polynomial fit data across multiple sheets?

  1. #1
    Registered User
    Join Date
    10-23-2019
    Location
    New Hampshire, USA
    MS-Off Ver
    2016
    Posts
    3

    Polynomial fit data across multiple sheets?

    I'm trying to build a polynomial fit across large arrays of data (5Mpixel imagery) across a number of different sheets (each sheet is a frame). I'm using LINEST to generate the coefficients for a 4th order polynomial:

    A Column B Column
    $A$2 $B$2
    $A$3 $B$3
    $A$4 $B$5
    $A$5 $B$5
    $A$6 $B$6

    X^4 Coefficient =INDEX(LINEST($A$2:$A$6,$B$2:$B$6^{1,2,3,4}),1)
    X^3 Coefficient =INDEX(LINEST($A$2:$A$6,$B$2:$B$6^{1,2,3,4}),1,2)
    X^2 Coefficient =INDEX(LINEST($A$2:$A$6,$B$2:$B$6^{1,2,3,4}),1,3)... etc

    This only works when all the data is on a single sheet. If I want to pull corresponding imagery cells from multiple sheets, as if for example $A$2 instead resides at 'sheet 2'!$A$2 and $A$3 resides at 'sheet 3'!$A$2 etc,

    X^4 Coefficient =INDEX(LINEST('sheet 2'!$A$2:'sheet 3'!$A$2:'sheet 4'!$A$2:'sheet 5'!$A$2:'sheet 6'!$A$2,$B$2:$B$6^{1,2,3,4}),1)

    throws a reference error. Maybe I shouldn't be separating the elements with a colon, but it doesn't like a comma either. I'm thinking of doing this in Matlab, but I have a number of routines in Excel that make other pieces of this analysis very easy - just this one hitch. VBA perhaps? I can't possible go through the 5M pixels per image * X images and pull all of the individual cells element by element onto a single sheet.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Polynomial fit data across multiple sheets?

    I can't possible go through the 5M pixels per image * X images and pull all of the individual cells element by element onto a single sheet.
    My experience is that LINEST() really just does not play nice with discontinuous ranges, and it does not support 3D referencing, so one way or another, you've got to extract the data from the all of the separate sheets and combine them into one range/array. When you say that you cannot possibly do this, are referring only to the time and tedium that comes with doing such a task manually, or is there some other restriction that prevents you from extracting data from all of the sheets and combining them together in a single spot?

    If it is just the difficulty of doing it manually, I'm sure we can come up with a programmatic way of extracting and compiling the data. For example, I could use the INDIRECT() function to process your 5 sheet example. =INDIRECT("'sheet "&ROW(A2)&"'!$A$2") copied down would extract the 5 values in A2 of those 5 sheets. At which point you could easily use that helper range in your LINEST() function. If you pay attention to relative and absolute references and all the other stuff that goes into spreadsheet programming, this kind of thing can work fairly well for the simple example you give in the OP. The main downside is that INDIRECT() is a volatile function, so, on a large spreadsheet (5 MP sounds like it could be pretty large), it might slow Excel down significantly. If that becomes a concern, there are ways to mitigate the computation delays.

    And that is likely not the only possible way. It could probably be done with lookup functions or even a utility like power pivot (get and transform) could extract the needed data. Or you could do this in VBA (or any other programming language that can extract data from a spreadsheet) where VBA extracts each value from each sheet and combines them into an array, then feed that array into the LINEST() function.

    But if there is some broader restriction that prohibits you from extracting data from the sheets, then that is a bigger problem.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Polynomial fit data across multiple sheets?

    My recommendation is to use Get & Transform to combine/transform data from multiple sheets.

    Return it as table in a sheet and use that as basis of your calculation.

    Alternately, you can use xlwings to integrate Python and use numpy's polyfit.
    xlwings: extension that allows use of python powered analysis in Excel
    https://www.xlwings.org/

    How to run/set up python powered udf in Excel (Windows only).
    https://docs.xlwings.org/en/stable/udfs.html#udfs

    polyfit
    https://docs.scipy.org/doc/numpy/ref...nomial.polyfit

    EDIT: Remembered the excellent article by Doug Jenkins at Newton Excel Bach.
    https://newtonexcelbach.com/2018/05/...l-and-xlwings/
    Last edited by CK76; 10-23-2019 at 05:09 PM.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Registered User
    Join Date
    10-23-2019
    Location
    New Hampshire, USA
    MS-Off Ver
    2016
    Posts
    3

    Re: Polynomial fit data across multiple sheets?

    It's the time of manually putting all the sheets together that does it. I would essentially be combining 5 x 5M sheets into a single 25M cell sheet. I suppose I could just paste them all together, so instead of a 2500x2000 array I end up with a 12500 x 2000 array (or I suppose a 2500 x 10000 array). No idea how long it would take Excel to crunch through it. I know there used to be a pretty trivial limit to the number of Excel cells on a single sheet, but I'm thinking way back in Office 95. Is something like that still true today?

  5. #5
    Registered User
    Join Date
    10-23-2019
    Location
    New Hampshire, USA
    MS-Off Ver
    2016
    Posts
    3

    Re: Polynomial fit data across multiple sheets?

    I've been reading a book on Python - have done zero actual programming in it. Once I'm writing in Python, would it be easier to just do the whole thing in Python and not spend the time integrating it into Excel?

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,618

    Re: Polynomial fit data across multiple sheets?

    Please note: there are 1,048,576 rows in Excel 2016.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Polynomial fit data across multiple sheets?

    Since 2007, Excel has been limited to 1E6 rows and 16k columns, so your 2500x2000 and 12500x2000 data sets should easily fit within one Excel sheet. If your limitation is just about manual processing, then we should be able to figure out how to programmatically combine, extract, filter, otherwise manipulate the data so that you don't need to manually manipulate the data.

    I'm sure there are enough Python programmers out there who dislike spreadsheets that you could easily find someone who believes you should just move all of your data analysis into Python and abandon spreadsheets altogether. I expect that doing this task in Python will involve all the same steps (extract data for each regression, perform regression, apply regression). At this point, you have phase 3 completed in the spreadsheet, you know how to do phase 2 in the spreadsheet, and you are up against learning how to do phase 1. That feels to me like a much smaller learning curve than starting over at square 1 with a new programming language. The only reason I could see in converting everything to Python (or other language) is if you felt the investment in learning a new language was going to be valuable in the long run.

    I gave one simple example of how one might do the data extraction/manipulation step. How well did it work? If you help us understand exactly what needs to happen at the data extraction/manipulation step, we should be able to help you get an Excel based solution to that step, which, if I understand, should allow you to finish the task with the rest of the spreadsheet that you already have.

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Polynomial fit data across multiple sheets?

    ... not spend the time integrating it into Excel?
    Depends on your need. If integrated and packaged with your solution, you can actually share it with others.

    Also, Excel can serve as GUI/Userform for python code. While python does have GUI frameworks, I find it easier just to use Excel in many cases.

    Added benefit, is that you have access to Excel's built-in tools, which you don't have to spend time making/tweaking in python.

+ 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. Using LINEST to derive a multiple polynomial equation
    By Richatom in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-08-2014, 09:09 AM
  2. Polynomial regression for multiple variables
    By dirxess in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-29-2013, 10:37 AM
  3. Replies: 1
    Last Post: 03-06-2013, 09:37 AM
  4. fitting polynomial to data
    By DaveKimble in forum Excel General
    Replies: 3
    Last Post: 01-13-2011, 08:51 AM
  5. Replies: 5
    Last Post: 06-25-2009, 10:25 AM
  6. Fitting data by a cubic polynomial
    By bhokalivarun in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-04-2009, 06:48 AM
  7. [SOLVED] fitting a polynomial to data
    By Mike Kamermans in forum Excel General
    Replies: 4
    Last Post: 05-11-2006, 03:30 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