Zananok Posted November 27, 2010 Report Share Posted November 27, 2010 (edited) How to calculate best fit line?For example:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3How would I find the equation for the best fit line through a mathematical view point (calculus) [y = mx + c]?Edit: Tried google as one could ask me and no good results where found. Best i could find was: http://www.fourmilab.ch/hackdiet/www/subsubsection1_4_1_0_8_4.html; and this did not help me. I used these keywords: calculate best fit lineA reply would be highly appreciated.Regards,Zananok Edited November 27, 2010 by Zananok Reply Link to post Share on other sites More sharing options...
Abu Posted November 27, 2010 Report Share Posted November 27, 2010 Plot them on your graph, and draw one line that goes through the middle of all those points and that line should represent those points. If you're doing it on MS Excel, it can do it for you. If there's no line that shows a positive or negative correlation (weak or strong) then there's really no correlation between those points and therefore there's no best fit line. Reply Link to post Share on other sites More sharing options...
Zananok Posted November 27, 2010 Author Report Share Posted November 27, 2010 (edited) No, I am making a graph program for doing physic and chemistry experiments as MS Excel and other graphs are a pain to work with. One that did ->some<- of the job was a trial, so i decided to make a program that does all needed graphical things programatically for physics and chemistry graphs (which is pretty simple to use), but the last thing i need to code is to plot a best fit line programatically without user's input/help; but to do that i have to understand how to make a best fit line.I thought of using the average Y value and calculate the difference of each point with that in mind, but it wouldnt work if the straight line was suppoused to be increasing as for example:X: 1,2,3,4,5Y: 1,2,3,4,5It would work partially on this:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3And I have not found out so far on how to calculate the best fit line for it.Edit: Thanks for the replyRegards,Zananok Edited November 27, 2010 by Zananok Reply Link to post Share on other sites More sharing options...
ILM Posted November 27, 2010 Report Share Posted November 27, 2010 Thank you aboo, i was going to ask this question, and i tried and i was able to do it, for more details, this is the methode:1- open an MS excell sheet.2- enter your infomation (i entered the domain in the first raw, and the range in the second raw.3- higlight them 4-then at the top barclick on the button of" Insert" .5- click on " XY scatter button".6-The scatter will be created for you.7- If you only click on the graph, you will find that the number of icon in the top bar, inceased, choose "Layout".8-Then choose the "best fit line" button. Note; if you scattered graph has no best fit line then you will not be able to click on the button. As it in your example:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3In this case it has no best fit line. Reply Link to post Share on other sites More sharing options...
Zananok Posted November 27, 2010 Author Report Share Posted November 27, 2010 Thank you aboo, i was going to ask this question, and i tried and i was able to do it, for more details, this is the methode:1- open an MS excell sheet.2- enter your infomation (i entered the domain in the first raw, and the range in the second raw.3- higlight them 4-then at the top barclick on the button of" Insert" .5- click on " XY scatter button".6-The scatter will be created for you.7- If you only click on the graph, you will find that the number of icon in the top bar, inceased, choose "Layout".8-Then choose the "best fit line" button. Note; if you scattered graph has no best fit line then you will not be able to click on the button. As it in your example:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3In this case it has no best fit line.Thanks for explain; but i did get a best fit line on Excel:y = 2.1429Straight line as I would expect from this data:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3Also, i'm looking on how to find it through calculus not through excel or other graphical program as I am coding the program.Regards,Zananok Reply Link to post Share on other sites More sharing options...
Abu Posted November 27, 2010 Report Share Posted November 27, 2010 If you're looking to do it through calculus, I'd suggest using the first and the last y and x value, get an equation for the line and plot that. It'll touch your first and last points and hopefully be in the middle of the rest of them.It's a straight line so you don't really need calculus to differentiate y = mx + b, because if you do, you'd only get m, which is the slope. Reply Link to post Share on other sites More sharing options...
Zananok Posted November 27, 2010 Author Report Share Posted November 27, 2010 (edited) If you're looking to do it through calculus, I'd suggest using the first and the last y and x value, get an equation for the line and plot that. It'll touch your first and last points and hopefully be in the middle of the rest of them.It's a straight line so you don't really need calculus to differentiate y = mx + b, because if you do, you'd only get m, which is the slope.It would only be a straight line if this was the data:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3Using this data:X: 1,2,3,4,5Y: 1,2,3,4,5The best fit line would be the line itself (y = x)And if i just use the first and last point, it would not work with this data:X values: 1, 2, 3, 4, 5Y values: 3, 1, 3, 1, 3as it starts with 3 and ends with 3, so it wouldnt be on the middle of the points, but on the top linking the point (1,3) with (5,3) making the line: y = 3; where it should actually be y = 2.1429 as previously stated.Edit: and even if it ended with 1, the line would be bended when it actually should be straight as in slope = 0.And again, thanks for the replies.Regards,Zananok Edited November 27, 2010 by Zananok Reply Link to post Share on other sites More sharing options...
Abu Posted November 27, 2010 Report Share Posted November 27, 2010 Sorry, I haven't plotted these. It would be easier if you included a scatter plot with your post.There really is no best fit line for curves. And looking at the points, it looks like you have a parabola or an x3 graph. Reply Link to post Share on other sites More sharing options...
Zananok Posted November 27, 2010 Author Report Share Posted November 27, 2010 Its ok, give me a second while i upload the images.[Posted the links as i got his warning: You are not allowed to use that image extension on this board.]http://www.darksunli...?sec=1290881776http://www.darksunli...?sec=1290881964(I made the images on a resonable size + ignore the uncertainties, forgot to remove it from the graph. The squares are the points.)Graph1 Data:X:1,2,3,4,5,6Y:3,1,3,1,3,1Graph2 Data:X:1,2,3,4,5,6Y:1,2,3,4,5,6It resambles a x^3 graph, but the line is just a line, not suppoused to touch all the points, its y=mx + c. [best fit line].Regards,Zananok Reply Link to post Share on other sites More sharing options...
Hedron123 Posted November 28, 2010 Report Share Posted November 28, 2010 Hey Zananok, the procedure to calculate a best-fit line is called least squares / least squares fitting. It can approximate data points to any polynomic function you want. I can introduce you to it via MSN / Skype since it's kind of hard to explain through the forum.If you are interested send me a private message and I'll give you my email.Regards. Reply Link to post Share on other sites More sharing options...
Drake Glau Posted November 28, 2010 Report Share Posted November 28, 2010 (edited) y-y ̅=s_xy/〖s_x〗^2 (x-x ̅)That looks terrible when copying and pasting from my IA Y minue the average of Y equals S sub xy divided by S sub x squared times (X minus the average of X)s_xy=(∑(xy))/n-x ̅y ̅S sub xy equals the (sum of X times Y divided by the total # of data points) minus (the average of X times the average of Y)s_x=√(〖∑x〗^2/n-x ̅^2 )S sub x equals the square root of the [(sum of x sqaured divided by the total number of data points) minus the average of X squared] That is incredibly complicated when trying to explain on the forum, send me a PM of your E-mail and I can send out a worked example from my IA that explains it kind of nicely. Or talk with Hedron Edited November 28, 2010 by Drake Reply Link to post Share on other sites More sharing options...
Zananok Posted November 29, 2010 Author Report Share Posted November 29, 2010 @Hedron123: Thanks for the reply and i would be thankful if you couldd walk me through it @Drake: I never liked statistics, so i don't exactly remember right now if that is standard deviation, but after talking to some of my collegues; they reminded me that the best fit line is asctually the standard deviataion of the graph, however, if your example is not, i would still like to see your explanation in a better way as you suggested Thanks for all the replies.Regards,Zananok Reply Link to post Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.