Menu Close

I-have-a-question-I-am-unsure-how-this-is-done-because-I-have-never-learnt-it-How-do-you-determine-the-line-of-best-fit-




Question Number 5117 by FilupSmith last updated on 14/Apr/16
I have a question. I am unsure how this  is done because I have never learnt it.    How do you determine the line of best fit?
Ihaveaquestion.IamunsurehowthisisdonebecauseIhaveneverlearntit.Howdoyoudeterminethelineofbestfit?
Commented by Yozzii last updated on 14/Apr/16
Least squares method is one way.  Given a set of n points (x_i ,y_i ), suppose  that the line of bestfit has the form  y=mx+c. Then, for each x_i , we get  the result y_j =mx_i +c. The least squares  method requires that for the regression line  y on x, the quantity Q must be minimised  where Q=Σ_(i=1) ^n (y_i −y_j )^2 =Σ_(i=1) ^n (y_i −mx_i −c)^2   This means that we aim to minimise  the squared distances between a given y_i  and  the point on the line y_j  corresponding to  x_i . Q is a function of two variables m  and c since we assume that (x_i ,y_i ) are  known. We can then employ techniques  of multivariable calculus to find m and  c. Since Q is of a quadratic form its  stationary value is a minimum one;  in 3D space, the locus of points (m,c,Q) is a bowl surface  where Q≥0.   ⇒(∂Q/∂m)=Σ_(i=1) ^n (−2x_i )(y_i −mx_i −c)  (∂Q/∂m)=2m(Σ_(i=1) ^n x_i ^2 )+2c(Σ_(i=1) ^n x_i )−2(Σ_(i=1) ^n x_i y_i )  and (∂Q/∂c)=Σ_(i=1) ^n (−2)(y_i −mx_i −c)  (∂Q/∂c)=2m(Σ_(i=1) ^n x_i )+2c(Σ_(i=1) ^n 1)−2Σ_(i=1) ^n y_i   or (∂Q/∂c)=2m(Σ_(i=1) ^n x_i )+2cn−2(Σ_(i=1) ^n y_i )  At the stationary point, (∂Q/∂m)=0 and (∂Q/∂c)=0.  You get the following result for m  from these two equations by eliminating c.  m=((nΣ_(i=1) ^n x_i y_i −(Σ_(i=1) ^n x_i )(Σ_(i=1) ^n y_i ))/(nΣ_(i=1) ^n x_i ^2 −(Σ_(i=1) ^n x_i )^2 ))  It can shown that (x^− ,y^− )=(((Σ_(i=1) ^n x_i )/n),((Σ_(i=1) ^n y_i )/n))  lies on the line of best fit, so c can be  found from c=y^− −mx^− . The result  of y=mx+c is the least squares line of  best fit.  (x^− ,y^− ) is the centroid of all the points  (x_i ,y_i ). m has another form.  m=((Σ_(i=1) ^n x_i y_i −nx^− y^− )/(Σ_(i=1) ^n x_i ^2 −n(x^− )^2 )).
Leastsquaresmethodisoneway.Givenasetofnpoints(xi,yi),supposethatthelineofbestfithastheformy=mx+c.Then,foreachxi,wegettheresultyj=mxi+c.Theleastsquaresmethodrequiresthatfortheregressionlineyonx,thequantityQmustbeminimisedwhereQ=ni=1(yiyj)2=ni=1(yimxic)2Thismeansthatweaimtominimisethesquareddistancesbetweenagivenyiandthepointonthelineyjcorrespondingtoxi.Qisafunctionoftwovariablesmandcsinceweassumethat(xi,yi)areknown.Wecanthenemploytechniquesofmultivariablecalculustofindmandc.SinceQisofaquadraticformitsstationaryvalueisaminimumone;in3Dspace,thelocusofpoints(m,c,Q)isabowlsurfacewhereQ0.Qm=ni=1(2xi)(yimxic)Qm=2m(ni=1xi2)+2c(ni=1xi)2(ni=1xiyi)andQc=ni=1(2)(yimxic)Qc=2m(ni=1xi)+2c(ni=11)2ni=1yiorQc=2m(ni=1xi)+2cn2(ni=1yi)Atthestationarypoint,Qm=0andQc=0.Yougetthefollowingresultformfromthesetwoequationsbyeliminatingc.m=nni=1xiyi(ni=1xi)(ni=1yi)nni=1xi2(ni=1xi)2Itcanshownthat(x,y)=(ni=1xin,ni=1yin)liesonthelineofbestfit,soccanbefoundfromc=ymx.Theresultofy=mx+cistheleastsquareslineofbestfit.(x,y)isthecentroidofallthepoints(xi,yi).mhasanotherform.m=ni=1xiyinxyni=1xi2n(x)2.

Leave a Reply

Your email address will not be published. Required fields are marked *