+ Reply to Thread
Results 1 to 12 of 12

Solving via Formula rather than Solver Tool Pack

  1. #1
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Solving via Formula rather than Solver Tool Pack

    Hi Everyone,

    I'm incorporating a statistical model to predict customer buying behavior. In this model, please see attached it uses microsoft's Solver tool to solve for Alpha, Beta, Gamma, and Delta. It uses solver to solve for the values in parameter estimation tab. The current objective is set to B6 and it changes the values in B1:B4.

    I'd like it to be powered by formulas instead of using solver. Here is explanatory detail on how the model works: http://www.brucehardie.com/notes/010...2011-01-20.pdf

    Thank you so much for the help!
    Attached Files Attached Files
    Last edited by scruz9; 09-11-2016 at 08:49 PM.

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

    Re: Solving via Formula rather than Solver Tool Pack

    I think converting to all formulas is going to be a lot of work. How much work are you ready to put into this?

    As a starting point (for exactly what you are asking for), I would suggest you review this thread (post #8 in particular http://www.excelforum.com/tips-and-t...ind-roots.html ) where I have a sample spreadsheet that finds the maxima of 2D polynomials using the NR algorithm. However, extending this to 5D -- with a formula where the "slopes" are going to be fairly complex to work out, is going to a significant amount of effort to program into a spreadsheet using only worksheet formulas.

    What is your motivation for this? If I had to guess, I would guess that you are trying to get the Solver algorithm (or program your own algorithm) to run automatically, without user input. I would suggest that, if this is your motivation, it will be easier to call Solver using a worksheet_change or worksheet_calculate event that will trigger Solver automatically. Using this approach, you would still be using the built in Solver utility, you would just be getting Solver to run without user input. Would that be a suitable approach? If it is, let us know where you need help (if you search this site and the rest of the internet, there are several examples of calling Solver from VBA, including event code).
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Re: Solving via Formula rather than Solver Tool Pack

    Hi MrShorty,

    This is great. Thank you so much for your thoughtful answer.

    And I am okay having it as a Macro and it running it manually. So, I will be adapting this model against multiple cohorts, so I'll have to perform the same Solver against multiple columns (same criteria).

    The data will all be in the same rows in which it's needed. Is this something you could help me?

  4. #4
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Re: Solving via Formula rather than Solver Tool Pack

    I should have been clearer:

    All of the values that need to be solved are on a single worksheet:

    Objective will be: Row 8, starting with $B$8
    By Changing Variables Cells: Row 2:5 starting with B2:B5

    Subject to constrains of Row 2:5 >= 0.0001

    Solving Method: GRG Nonlinear

    This would need to be done until column NA.

    Thanks again for the help!

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

    Re: Solving via Formula rather than Solver Tool Pack

    I'm sure I could help, but it isn't the kind of programming I do a lot of, so I would probably just end up referring to others' examples. As I indicated before, this forum and the internet have a lot of examples of calling Solver from VBA -- often as part of a loop to solve several copies of the same problem. Here's one example http://www.excelforum.com/showthread...=1#post4470911 see post #8 by Alf. So, let's start with Alf's code (or any other example you come across that you like better) and see where you get stuck.

  6. #6
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Re: Solving via Formula rather than Solver Tool Pack

    Hmm so I was able to find something online and modify it, but I still can't get it to work. This is what I have so far. Do you recommend I post this in hte Macro Section?


    The solver attached is the parameters I'd like for it solve but moving across each column until column NA.

    Please Login or Register  to view this content.
    Solver.PNG

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

    Re: Solving via Formula rather than Solver Tool Pack

    This
    Please Login or Register  to view this content.
    is not correct syntax for the cells() method. The cells() method takes only 2 arguments: a row number and a column number.

    From the help file for the Range object (https://msdn.microsoft.com/en-us/lib.../ff838238.aspx ), you can use the cells() method to return multiple cells. Note the example from the help file:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Solving via Formula rather than Solver Tool Pack

    Try

    Please Login or Register  to view this content.
    and see if this works better.

    And since you are running Solver in a loop I would recommend you start you solver macro with the line

    Please Login or Register  to view this content.
    before the "SolverOk" line in order delete previous constraint settings.

    Alf
    Last edited by Alf; 09-12-2016 at 05:44 PM. Reason: added extra info

  9. #9
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Re: Solving via Formula rather than Solver Tool Pack

    Alf & MrShorty,

    Thank you so much for the help. I ended up getting it to work and loop through each cell. The only problem I am facing now is after column B, solver is calculating incorrectly - even when run manually. I've attached a sample of my spreadsheet.


    So if you toggle the headings in Row 1 and give it a try and put 1628 and calcualte it in B then set all your parameters to 1, and than switch 1628 and 1627 into separate columns and try to calculate 1628 in column B, the numbers differ.

    1.png

    2.png
    Attached Files Attached Files

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Solving via Formula rather than Solver Tool Pack

    I don't understand you formula in range B6:B7 but testing by manually inserting values in column range row 2 to 5 don't seem to make much difference to the target value in row 8 but changing the value in row 1 makes a difference.

    Constraint.jpg

    Alf

  11. #11
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Re: Solving via Formula rather than Solver Tool Pack

    Yes row 1 is the Cohort name. I guess what I am trying to say is ... if I run solver outside of column B even if it's the same Row 1, I get different answers even when I change the critiera for solver. What am I doing wrong?

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

    Re: Solving via Formula rather than Solver Tool Pack

    I haven't gone through your spreadsheet thoroughly (how thoroughly do you need us to go through it for you?), but I think I can see the problem. There is something different about the calculation when it is called from column C than column B. My testing steps:

    1) Put 1627 into B1.
    2) Run Solver on column B
    3) Result maximum looks similar to 1628
    1627
    alpha 0.875877066
    beta 0.828953298
    gamma 0.802503139
    delta 3.217015364
    B(alpha,beta) 1.357
    B(gamma,delta) 0.466
    LL -2374.8

    4) Put 1628 into C1 and copy alpha-delta values for 1628 into C2:C5
    5) I note that the LL value in C8 is not the same as B8 was when these same values were in B2:B5 -- I have not decomposed the entire calculations, but the calculation string from C2:C5 back to LL in C8 is not the same as it is for column B.

    One of the challenges when I come into the middle of a large development project like this is that I don't know all that went into the project, nor do I understand all of the formulas along the way. I do note that column J's formulas have some fixed references to column B where I might have expected to see additional lookup functions -- could it be that simple?

    Since column B seems to work correctly, I would be tempted to structure the loop differently. Instead of having several columns that are optimized, use the existing column B, and loop through the different input values in B1
    Please Login or Register  to view this content.
    If it is an advantage, one possible advantage is that you should not need to modify the Solver model at all throughout the loop, simply change B1 and run the existing Solver model.
    Last edited by MrShorty; 09-14-2016 at 12:02 PM.

+ 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] Regression Output without Analyst Tool Pack
    By dinesh_ltjd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 08:38 AM
  2. Loading Analysis Tool Pack w/o CD
    By gettingthere in forum Excel General
    Replies: 1
    Last Post: 07-11-2009, 05:31 AM
  3. Loading Analysis Tool Pack without Cd
    By gettingthere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2009, 05:14 AM
  4. Replies: 1
    Last Post: 12-15-2005, 01:00 PM
  5. [SOLVED] After adding Analysis Tool Pack, still no PRICE function, why?
    By mtburdett in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-05-2005, 05:50 AM
  6. [SOLVED] anaysis tool pack
    By Dan Perry in forum Excel General
    Replies: 4
    Last Post: 05-11-2005, 12:06 PM
  7. Analysis Tool Pack: Random function help
    By Scott P in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2005, 12:29 AM

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