BillSoo
10-16-2002, 02:36 PM
I found a website through GOOGLE that has the required formulas:
http://people.hofstra.edu/faculty/S...regression.html
Basically, it calculates the line of best fit through the method of least squares. You can read the URL if you want to know why it works, but for our purposes we can say.....
For the line of best fit Y = M * X + B:
M = (n *Sxy - Sx * Sy) / (n * Sx2 - Sx * Sx)
B = (Sy - M * Sx) / n
Where:
n = number of points
Sx = the SUM of all the X coordinates
Sy = the SUM of all the Y coordinates
Sxy = the SUM of all (x * y)
Sx2 = the SUM of all (x * x)
So to calculate the line of best fit, set up a bunch of variables like above. Then, everytime you get a new datapoint, update the variables and calculate a line using the equations.
You can then check the coefficient of correlation using a formula found on the URL.
I've attached a demo program that draws the line of best fit based on points that you place on the form by clicking.
http://people.hofstra.edu/faculty/S...regression.html
Basically, it calculates the line of best fit through the method of least squares. You can read the URL if you want to know why it works, but for our purposes we can say.....
For the line of best fit Y = M * X + B:
M = (n *Sxy - Sx * Sy) / (n * Sx2 - Sx * Sx)
B = (Sy - M * Sx) / n
Where:
n = number of points
Sx = the SUM of all the X coordinates
Sy = the SUM of all the Y coordinates
Sxy = the SUM of all (x * y)
Sx2 = the SUM of all (x * x)
So to calculate the line of best fit, set up a bunch of variables like above. Then, everytime you get a new datapoint, update the variables and calculate a line using the equations.
You can then check the coefficient of correlation using a formula found on the URL.
I've attached a demo program that draws the line of best fit based on points that you place on the form by clicking.