08-09-2006 10:22 PM
08-10-2006 10:08 AM
I hope I understand your question correctly
If you want a line that is parallel to the best fit line found by LinFit() but has a y intercept of zero then simply change the intercept value returned to be zero before using the values that LinFit() returns to plot your data (I am assuming you are plotting something).
If you want to bend the end of the line to move the y intercept to pass through zero then recalculate the slope based on the points (0,0) and a point that is far away from the y axis. To do this use the slope and intercept returned by LinFit() to find a point far away from the y axis. Y2=mX2+b where X2 is the point you picked away from the y axis, m is the slope from linfit and b is the intercept from LinFit(). Now recalculate the slope from (0, 0) and (X2,Y2). You can use LinFit() again if you want to find the new slope or just use the standard line fit formulas.
08-10-2006 11:09 AM - edited 08-10-2006 11:09 AM
Message Edited by cdk52 on 08-11-2006 03:15 AM
08-10-2006 08:30 PM
Thanks Guys - I think we are on the right track, but I have not explained my issue correctly it seems.
Colin, your idea of calculating the slope (from the included code) works but it does not force the line through zero. ie. the slope will return the same slope as the LinFit() routine.
I think the idea of using a point far outside the data and then an additional point at (0,0) is also quite smart and will force the data through zero, but the resulting line is not a 'best-fit' of the data. The resulting line could be quite different.
for eg.
X, Y
0, 0
1, 2
2, 3
3, 4
4, 5
The linear line of best fit is Y = 1.6 X + 1.2, if I was to force the data through 0,0 then the line of best fit gives Y = 2.0 X. Using the idea of a point 'way out' from the first line of best fit, (say X = 20) then using the equation above give Y as 1.6* 20 + 1.2 => Y = 33.2. Whereas the real result I am 'hoping' to acheive would be Y = 2.0 * X = 2.0 * 20 = 40. Quite a different result.
I assume I can just iterate through the Y = mX and look for a minimun least-squares error, but I thought that would be rather agricultural.
08-10-2006 11:44 PM - edited 08-10-2006 11:44 PM
Message Edited by cdk52 on 08-11-2006 03:53 PM
05-04-2008 11:58 AM