+ Reply to Thread
Results 1 to 11 of 11

Automate calculation of multiple slopes from data set

  1. #1
    Registered User
    Join Date
    02-08-2016
    Location
    Edmonton, AB, Canada
    MS-Off Ver
    2013
    Posts
    4

    Automate calculation of multiple slopes from data set

    Hi there. I'm doing some analysis on some data from a study we recently conducted, and we're trying to figure out a way to calculate the slopes of several different trends from one big data set. If there's a way to automate this process in Excel it'll make my life A LOT easier. Attached is the data output we get from a program we use to monitor and analyze blood pressure and heart rate during an exercise test. What we are attempting to do is calculate the slope of several sequences of varying durations. For instance, I've put a square around a few of the different sequences. Each sequence is distinguished in column G by Group. The durations are NOT equal lengths, as you can see by columns D, E, and F. Most span roughly 4 heart beats, but some are longer (like the 9 beat sequence that is circled in black).

    Is there a way to write a formula that will select each sequence (or group) based on criteria and then calculate the slope of that group? In this case, I was thinking that perhaps we could automate the process by getting a formula to select a whole "Group" from column G (like group #1 for example) and then find the slope based on plotting "Column B - R-R Interval" vs "Column A - Systolic BP" from the corresponding rows within that group. We do not need an actual plot - just the slope and r-squared value if possible.

    We have roughly 100 files of this nature, so manually doing it would become cumbersome very quickly. We have figured out a coding on R Studio that automates the slope calculation, but if any of you know of a way to do this on Excel, your help would be greatly appreciated.

    Thanks!

    BRS in Excel - Screenshot.png
    Last edited by gmpurdy; 02-09-2016 at 12:54 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Automate calculation of multiple slopes from data set

    Hi gmpurdy,
    Welcome to the forum!

    Are you able to provide us with a sample workbook showing how you normally compute the slope and r-squared values. Then, we manipulate those formulas to only accept/compute values that match the group ID.

  3. #3
    Registered User
    Join Date
    09-24-2015
    Location
    Delhi, India
    MS-Off Ver
    MS Office 2013
    Posts
    65

    Re: Automate calculation of multiple slopes from data set

    Hi gmpurdy,

    upload a sample workbook not an image. and mention your expected ans on that.

    Thanks
    Rohit.

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Automate calculation of multiple slopes from data set

    try this array-formula in cell H2 to compute Slope.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    To compute R-Square, try this Array Formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note: Array Formula must be entered/confirmed with [Ctrl]+[Shift]+[Enter]
    Do still upload a sample workbook so the forum members can advise simpler and better solutions/alternatives.
    Cheers!
    Last edited by jewelsharma; 02-09-2016 at 01:24 AM.

  5. #5
    Registered User
    Join Date
    02-08-2016
    Location
    Edmonton, AB, Canada
    MS-Off Ver
    2013
    Posts
    4

    Re: Automate calculation of multiple slopes from data set

    Thank you all for replying so quickly!

    Here's an Excel spreadsheet form of the output we get. I've included the expected slopes for each sequence on the far right.
    Again, I'm looking for a way to automate the calculation of the slope for each sequence based on the "group". I would expect the r-squared function to be essentially the same as the slope one, so if there are any suggestions to figure out a formula to
    automate the slope calculation, that would be great!

    BRS in Excel.xlsx

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Automate calculation of multiple slopes from data set

    If the group number is in J2, this will return the slope of that group.

    =SLOPE(OFFSET(INDEX(B:B, MATCH(J2, G:G, 0), 1),0,0,COUNTIF(G:G, J2)), OFFSET(INDEX(A:A, MATCH(J2, G:G, 0),1),0,0, COUNTIF(G:G, J2)))
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Automate calculation of multiple slopes from data set

    Is your data separated into negatives and positives or do you want that done as well?

    Is every worksheet named: "All" that contains every datapoint in every workbook that contains an output?
    <---If my answer helped, please click *

  8. #8
    Registered User
    Join Date
    02-08-2016
    Location
    Edmonton, AB, Canada
    MS-Off Ver
    2013
    Posts
    4

    Re: Automate calculation of multiple slopes from data set

    Hi Mike! This appears to be returning the same slopes as originally expected, so that's great to see! Just wondering, is there a way to modify that equation so the slope only appears in the the first row of every sequence, rather than in all rows? As seen in the picture, it would be a lot easier to sort through if the function would return the column on the left, rather than the one on the right (which is what the one you suggested does). I think this would make it easier to gather the information needed for further analysis.

    Thanks!

    BRS - Slope Calculation.png

  9. #9
    Registered User
    Join Date
    02-08-2016
    Location
    Edmonton, AB, Canada
    MS-Off Ver
    2013
    Posts
    4

    Re: Automate calculation of multiple slopes from data set

    Quote Originally Posted by joe31623 View Post
    Is your data separated into negatives and positives or do you want that done as well?
    Eventually we'd like them separated into negatives and positives, but the data found on sheet1 ("All") is what the output from our program is. I just manually separated them when I was troubleshooting the problem earlier, but if there's a way to have them separated that would be really helpful.

    Thanks

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Automate calculation of multiple slopes from data set

    gmpurdy,
    What exactly do you mean by automate slope calculation?

    See this XLSX file BRS in Excel.xlsx. It shows the Array Formula provided in my post above to compute SLOPE & RSQAURE values based on the Group number.

    If you looking for a button that inserts this formula automatically once you have the data on the worksheet, see this XLSM file BRS in Excel.xlsm.
    HTH!

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Automate calculation of multiple slopes from data set

    You could put this in H2 and drag down

    =IF(G1<>G2, SLOPE(OFFSET(INDEX(B:B,MATCH(G2,G:G,0),1),0,0,COUNTIF(G:G,G2)),OFFSET(INDEX(A:A,MATCH(G2,G:G,0),1),0,0,COUNTIF(G:G,G2))), "")

+ 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. To automate Calculation of time taken
    By rshnkmr39 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2014, 03:00 PM
  2. HELP: macro to automate a calculation
    By sampsulo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 09:05 AM
  3. [SOLVED] Attemepting to link and automate multiple data points
    By robstark in forum Excel General
    Replies: 5
    Last Post: 03-18-2013, 12:51 PM
  4. Excel 2007 : How to automate calculation of threshold value?
    By sandyjune1988 in forum Excel General
    Replies: 1
    Last Post: 12-28-2011, 02:50 AM
  5. Automate Calculation with help of VBA
    By Dongfang in forum Excel General
    Replies: 2
    Last Post: 03-11-2011, 04:29 AM
  6. Is it possible to automate merging data between multiple spreadsheets?
    By No_expert in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-12-2005, 07:42 PM
  7. [SOLVED] Help required to automate calculation
    By Tom in forum Excel General
    Replies: 1
    Last Post: 02-02-2005, 10:06 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