Results 1 to 4 of 4

Thread: A nice easy linear expression question for you (or is it?)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    Wink A nice easy linear expression question for you (or is it?)

    Hiya, i have a database full of records and each has 4 points. i want to take these four points, and plot a line of best fit for them without having to draw the graph for them (cause i want to make my program do it you see). So.. how can you, given four not exactly straight line points, obtain an approxiamte linear equation for them?


    Thanks for you time
    Ang

  2. #2
    sql_lall
    Guest

    I think...

    Not exactly sure, but it has something to do with the sum of the squares of the differences between the points and the line.
    Kinda like Chi-squared

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391
    Psycho_NZ

    What you want to do is called regression. You're trying to choose a slope and intercept that give you the smallest differences between the fitted line and your data points (least-squares).

    Anyway, here are the formulas:

    The slope of the best-fit line, m, is given by

    m = [nSum(xy) - Sum(x)Sum(y)]/[nSum(x^2) - (Sum(x))^2]


    where
    n is the number of data points

    and

    Sum(x) is the sum of all your x values
    Sum(xy) is the sum of the product of each x and y pair
    and so on...

    The intercept, b, is given by


    b = Yavg - mXavg

    where

    Yavg = the average of all Y values
    Xavg = the average of all X values


    That will give you the best fit line.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    Hey your notation is way easier to understand than the websites i found on it.

    Thanks
    Ang

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width