+ Reply to Thread
Results 1 to 11 of 11

run several separate regressions from one data base

  1. #1
    Registered User
    Join Date
    03-25-2016
    Location
    north carolina
    MS-Off Ver
    2010
    Posts
    15

    run several separate regressions from one data base

    Is it possible to run several separate regressions from one data base automatically?
    For example - I have a data base with 3 columns, A,B,C. Column A has the department number (e.g. 1,2,3, up to 10), column B has the "Y" data and column C has the "X" data.

    Each department may have 10 to 100 rows of data.

    I would like to have regressions that would run each department separately and provide the regression response in separate tabs.

    So, for my example I would have 10 regressions run where each of rows of data would match the department number.
    I hope this makes sense.
    Thanks for any help.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: run several separate regressions from one data base

    I am not quite sure what you mean by "regression." I'm guessing you may want to use a pivot table. You can set the pivot table up on one sheet, and make multiple copies of that sheet. Then you can go back and set the filters for the departments on each sheet.

    One of the features of a pivot table is that if you refresh one pivot table, all other pivot tables built on that data source will also refresh.

    On the other hand, if you are talking about linear regression, or something like that, then either array formulas, or maybe a pivot table with a named dynamic range overlay will meet your needs.

    We'd have to see how the source data is organized, and what you would like the desired results to look like.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    03-25-2016
    Location
    north carolina
    MS-Off Ver
    2010
    Posts
    15

    Re: run several separate regressions from one data base

    Would you like me to provide an example of the data base and the resulting linear regression?
    Do I just copy both into this box?

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

    Re: run several separate regressions from one data base

    For others, this looks like an extension of http://www.excelforum.com/excel-gene...eviations.html

    A sample data base would help us provide more specific suggestions. To add a sample file, click on "Go Advanced" below the quicky reply box, find "Manage Attachments", then work through the add attachment window.

    As I explained in the previous thread, Excel's regression algorithms require that the input data be in a single block of cells. Every question like this that I have seen usually ends up being about how to separate out or compile the desired data for each regression into a single block. There are many different strategies for this. I illustrate one strategy in the attached spreadsheet. Note the following:

    1) Start with unsorted list
    2) Sort list by department. Note that you would likely not end up with two copies of the database, as you would normally sort the list in place. I copied the list before sorting so you could see the before and after. Sort command is on the Data Menu.
    3) In the regression table (M2:Q13) I have:
    3a) a list of all departments
    3b) a MATCH() function to locate each department in the list
    3c) a COUNTIFS() function to determine how many entries for each department
    3d) an OFFSET() function inside of the LINEST() function to extract the desired data for each regression. (help files for all functions here: https://support.office.com/en-us/art...rs=en-US&ad=US ).

    No VBA was required for this. The only step that needs user input is the "sort" step.

    Since you may ask, the regressions in S3:T4 are there to check the main LINEST() functions. The input ranges were manually selected to make sure the OFFSET() functions were retrieving the correct data.
    Attached Files Attached Files
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    03-25-2016
    Location
    north carolina
    MS-Off Ver
    2010
    Posts
    15

    Re: run several separate regressions from one data base

    MrShorty,

    Thanks for the response. It appears pretty much exactly what I need.


    I uploaded the attachment, so I hope you get it.

    However, in my attached file you will see the regression tab. In that tab I have highlighted the three regression results that I need to have rather than the results that you have placed in your sample.

    I am not familiar with extracting specific results from the regression as you have done.

    I would appreciate the assistance in providing those regression results as replacements.

    My data tab has my attempt to use the formulas as you have provided.

    With the regression results that I need placed in those columns, it would be perfect for me to use.

    Thanks very much for this.
    Attached Files Attached Files

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

    Re: run several separate regressions from one data base

    I'm not sure exactly what you are doing here. The first observation I make is that you are using A2 as the reference cell for the offset function, which is the first cell with data in it. In my example, I used G2 as the reference cell for the offset function, which is the cell above the first cell with data. If you use the Evaluate Formula tool (Formulas -> Evaluate formula https://support.office.com/en-us/art...6-a70aa409b8a7 ), you will see that the regression for department 3 is using data from rows 14 through 30. It appears that your data for dept 3 is in rows 13 to 29, so it is looking one row below the desired data. I think this part is fixed if you adjust the reference cell for your offset functions up one row.

    The other observation I make is that you have only entered the LINEST() function in one cell. The LINEST() function is an array function that returns two values. To use this function in Excel, one usually selects two adjacent cells, P2:Q2 for example, then enters the formula and confirms with ctrl-shift-enter to designate the formula as an array function.

    I think with those two corrections, you should get the correct results.

  7. #7
    Registered User
    Join Date
    03-25-2016
    Location
    north carolina
    MS-Off Ver
    2010
    Posts
    15

    Re: run several separate regressions from one data base

    Thanks

    I made the changes, but I need the linest formula to give me the t-stat and p-value as well as the coefficient. How do I add those?

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

    Re: run several separate regressions from one data base

    I would suggest that you review the help file for the LINEST() function to learn all of its capabilities. (from list of function linked to above https://support.office.com/en-us/art...a-fa7abf772b6d ). Also, if you need a quick refresher on the statistics of linear regression, I found this a quick explanation of the t-stat and P-score: http://stattrek.com/regression/slope-test.aspx

    If you set the optional 4th argument for the LINEST() function to TRUE (up to now, we have only used the first two arguments), then LINEST() will output additional statistics. You will also need to enter the function over a larger, 2D array of cells -- 5 rows by 2 columns if you want all of the information. The helpfile describes the extra statistics and how they are output. t-stat and P-score are not included, but they are easily calculated from the other statistics, as explained in the stattrek article.
    t for a given coefficient = coefficient/standard error for that coefficient
    P-score is simply the value from the tdistribution for that t score, which is easily calculated using the TDIST() or T.DIST() functions.

  9. #9
    Registered User
    Join Date
    03-25-2016
    Location
    north carolina
    MS-Off Ver
    2010
    Posts
    15

    Re: run several separate regressions from one data base

    Mr. Shorty

    Thanks for those links and the info that the t stat can be calculated with the coefficient and standard error.

    I have attempted to have all the linest results show up in my base opposite each department, but I can't seem to get them to show up so the results are lined up with each department. Mostly I still just get the coefficient result.

    Could you take a look at my attachment to see if you can get the linest results to display by department.

    Sorry for the continued bother, but this is all new to me.

    Thanks again.
    Attached Files Attached Files

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

    Re: run several separate regressions from one data base

    You did not include any of your failed attempts, so I could not tell what you are specifically having trouble with. I have entered the formulas for dept. 2. Is this what you are looking for?
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-25-2016
    Location
    north carolina
    MS-Off Ver
    2010
    Posts
    15

    Re: run several separate regressions from one data base

    Yes. This works completely.

    Thanks again for your time on this.

+ 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. run the regressions
    By Tamimami in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-06-2014, 12:18 PM
  2. [SOLVED] Want to separate unique and duplicate data from large data base
    By sambha in forum Excel Programming / VBA / Macros
    Replies: 39
    Last Post: 08-02-2014, 12:30 AM
  3. Excel data base or access data base collection?
    By mcdonalds in forum Excel General
    Replies: 0
    Last Post: 02-17-2014, 08:04 AM
  4. need print separate file base on the cell value of the PDF file (100 Pages).
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2013, 02:36 PM
  5. how to transform data from row-base to column-base
    By fei2010 in forum Excel General
    Replies: 3
    Last Post: 11-23-2012, 12:17 AM
  6. convert non data base to data base format using formula
    By murarihyd in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-22-2011, 11:42 AM
  7. Many Ols Regressions on Many Columns of Data
    By Carpenter9 in forum Excel General
    Replies: 0
    Last Post: 09-12-2006, 02:32 AM

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