+ Reply to Thread
Results 1 to 8 of 8

Create databased of trend line from each data point against the population

  1. #1
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Fort Worth, Texas
    MS-Off Ver
    Excel 2010
    Posts
    378

    Create databased of trend line from each data point against the population

    Hello,

    I wanted to create a database of trend line from each data point against the population like in the attached.

    However, it is time consuming to do formula and wondered if we can do it with macro.

    Please let me know if anyone can help.
    Attached Files Attached Files

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

    Re: Create databased of trend line from each data point against the population

    If I may ask, what do you find time consuming?

    I built something for this in just a few minutes. I notice that you are using all absolute references in your formulas, perhaps if you were more familiar with how to mix relative and absolute referencing. Here's what I did.

    1) Add 2 rows at the top for a LINEST() function for each date range. E1:E2 =TRANSPOSE(LINEST(E$4:$KA$4,E$3:$KA$3)) note how I mixed relative and absolute references. Copy across.
    2) Add 3 columns at the left to make a copy of the LINEST() results. Enter 1 in A20, Enter A20+1 in A21 and copy down as far as needed. B20:C20=TRANSPOSE(INDEX($E$1:$KA$2,0,$A20))
    3) E20 =IF($A20+4<=COLUMN(),$C20+$B20*e$3,NA()) copy down and across as far as needed

    No VBA needed, and it goes together fairly quickly.
    Attached Files Attached Files
    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
    07-16-2012
    Location
    Fort Worth, Texas
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Create databased of trend line from each data point against the population

    Quote Originally Posted by MrShorty View Post
    If I may ask, what do you find time consuming?

    I built something for this in just a few minutes. I notice that you are using all absolute references in your formulas, perhaps if you were more familiar with how to mix relative and absolute referencing. Here's what I did.

    1) Add 2 rows at the top for a LINEST() function for each date range. E1:E2 =TRANSPOSE(LINEST(E$4:$KA$4,E$3:$KA$3)) note how I mixed relative and absolute references. Copy across.
    2) Add 3 columns at the left to make a copy of the LINEST() results. Enter 1 in A20, Enter A20+1 in A21 and copy down as far as needed. B20:C20=TRANSPOSE(INDEX($E$1:$KA$2,0,$A20))
    3) E20 =IF($A20+4<=COLUMN(),$C20+$B20*e$3,NA()) copy down and across as far as needed

    No VBA needed, and it goes together fairly quickly.
    This is awesome. You're genius.
    I also wanted to ask if we create a chart based on this database of trend line like this. I wondered if you can find a intercept point among those lines?

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

    Re: Create databased of trend line from each data point against the population

    I am not sure I understand.

    We can create a chart if we want fairly easily. The chart can find the y-intercept for each line, if we want it to (through the trendline feature), but we have already found the y-intercept from the LINEST() functions, so it seems like extra effort to have the chart do.

    We can find x-intercepts for each line through some algebra. We have y=mx+b for each trendline, set y=0 and solve for x to get the x intercept.

    We can find the intersection point for any two lines using algebra again. Set up a system of equations y=m1*x+b1 and y=m2*x+b2 and solve the system of equations for y and x (a good tutorial on solving systems of equations, if needed: http://www.purplemath.com/modules/systlin1.htm ).

    Or are you looking for some other intercept?

  5. #5
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Fort Worth, Texas
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Create databased of trend line from each data point against the population

    Quote Originally Posted by MrShorty View Post
    I am not sure I understand.

    We can create a chart if we want fairly easily. The chart can find the y-intercept for each line, if we want it to (through the trendline feature), but we have already found the y-intercept from the LINEST() functions, so it seems like extra effort to have the chart do.

    We can find x-intercepts for each line through some algebra. We have y=mx+b for each trendline, set y=0 and solve for x to get the x intercept.

    We can find the intersection point for any two lines using algebra again. Set up a system of equations y=m1*x+b1 and y=m2*x+b2 and solve the system of equations for y and x (a good tutorial on solving systems of equations, if needed: http://www.purplemath.com/modules/systlin1.htm ).

    Or are you looking for some other intercept?
    I added few calculations to the spreadsheet that you returned. The number I highlighted yellow is the final number that I wanted to come up with. Is there a way to get these number without doing additional calculation which I highlighted gray? I guess it might be a very long formula or something. Can you help me?
    Attached Files Attached Files

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

    Re: Create databased of trend line from each data point against the population

    The blue calculations look like the average value for each row/line, and then the yellow value is the average of those averages.

    If you recall from your first calculus class, we can use the definite integral to find average values of functions (Here's a very quick refresher http://archives.math.utk.edu/visual....s/5/average.1/ ). From this, you should be able to calculate the blue cells directly from the regression coefficients in rows 1 and 2 and the starting and ending dates in row 3. The yellow cell continues to be =AVERAGE(blue cells). The programming for that should be simple, the bulk of the work is doing the calculus.

    I expect it is possible to eliminate the blue cells as well, if you are willing to do all of the algebra to do it.

  7. #7
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Fort Worth, Texas
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Create databased of trend line from each data point against the population

    Quote Originally Posted by MrShorty View Post
    The blue calculations look like the average value for each row/line, and then the yellow value is the average of those averages.

    If you recall from your first calculus class, we can use the definite integral to find average values of functions (Here's a very quick refresher http://archives.math.utk.edu/visual....s/5/average.1/ ). From this, you should be able to calculate the blue cells directly from the regression coefficients in rows 1 and 2 and the starting and ending dates in row 3. The yellow cell continues to be =AVERAGE(blue cells). The programming for that should be simple, the bulk of the work is doing the calculus.

    I expect it is possible to eliminate the blue cells as well, if you are willing to do all of the algebra to do it.
    I don't know how to calculate average by using the definite integral in excel. Any tips?

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

    Re: Create databased of trend line from each data point against the population

    Standard approach (most of this is outside of Excel)

    1) starting equation is y=mx+b
    2) Find antiderivative. Since this is a simple polynomial, can I assume you recall how to take antiderivatives of polynomials? (A quick refresher on taking antiderivatives http://www-math.mit.edu/~djk/calculu...section01.html )
    3) With the antiderivative and the formula in the link in post 6, you should be able to write an expression for the average of each curve. then program that expression into Excel
    3a) As a tip, sometimes I find it nice to use the SERIESSUM() function when working with polynomials https://support.office.com/en-us/art...4-96c49087f637 In this case, your polynomial only has 2 terms, so it probably does not help much in this case, but it can be helpful when your polynomial contains many terms.

+ 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. Excel Test - Create trend line from data set
    By ickelly in forum Excel General
    Replies: 1
    Last Post: 01-07-2016, 03:25 AM
  2. Find the point of a line where the trend changes
    By timothy040888 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-13-2015, 05:24 PM
  3. [SOLVED] How to change the start point of trend line?
    By qzqzjcjp in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-22-2015, 07:32 PM
  4. [SOLVED] How to create a line chart to compare trend of two activities
    By LWLS in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-27-2014, 09:59 AM
  5. [SOLVED] how do I create a bar graph with a trend line?
    By moshingbananas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2012, 10:35 AM
  6. Replies: 2
    Last Post: 06-27-2011, 10:47 PM
  7. How to create trend line chart for MEDIAN in Excel?
    By Nitin Gupta in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-03-2005, 08:05 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