• To use ordinary least squares to find the line y=m⁢x+b that minimizes the distance in the y coordinate
    • We begin with a set of n points given by
    • (x0,y0), (x1,y1), (x2,y2) ,…, (xn-1, yn-1)
    • To find the least squares line, we want to minimize this function
    • F(m,b)= ∑ i=0 n-1 [ yi- (mxi+b) ]2
    • To minimize the function, we need the partial derivatives to be zero.
    • ∂∂b F(m,b) = - 2 ∑ i=0 n-1 [ yi- (mxi+b) ] ∂∂m F(m,b) = - 2 ∑ i=0 n-1 xi [ yi- (mxi+b) ]
    • This can be rewritten as the following system of equations
    • b⁢n + m⁢ ∑ i=0 n-1 xi = ∑ i=0 n-1 yi b⁢ ∑ i=0 n-1 xi + m⁢ ∑ i=0 n-1 xi2 = ∑ i=0 n-1 xi yi
    • Writing this as a matrix equation, we have
    • [ a11 a12 a21 a22 ] [ b m ] = [ c1 c2 ]
      where the labels correspond to the values in the equations (i.e. a11 =n )
    • The solution is given by finding the inverse
    • [ b m ] = 1 a11 a22 - a12 a12 [ a22 -a12 -a21 a11 ] [ c1 c2 ]
    • This gives the solution
    • b = a22 c1 - a12 c2 a11 a22 - a12 a12 = ∑ i=0 n-1 xi2 ⁢ ∑ i=0 n-1 yi - ∑ i=0 n-1 xi ⁢ ∑ i=0 n-1 xiyi n⁢ ∑ i=0 n-1 xi2 - ( ∑ i=0 n-1 xi)2 m = a11⁢ c2 - a21⁢ c1 a11⁢ a22 - a12⁢ a12 = n⁢ ∑ i=0 n-1 xiyi - ∑ i=0 n-1 xi ∑ i=0 n-1 yi n⁢ ∑ i=0 n-1 xi2 - ( ∑ i=0 n-1 xi)2
    • For the homogeneous equation A⁢x+ B⁢y+ C=0, we have
    • A= ∑ i=0 n-1 xi ∑ i=0 n-1 yi - n⁢ ∑ i=0 n-1 xiyi B= n⁢ ∑ i=0 n-1 xi2 - ( ∑ i=0 n-1 xi)2 C= ∑ i=0 n-1 xi ⁢ ∑ i=0 n-1 xiyi - ∑ i=0 n-1 xi2 ⁢ ∑ i=0 n-1 yi
    • Using vector notation and setting 1→= (1,1,…1) , we have
    • A= (1→⋅x→)⁢ (1→⋅y→)- (1→⋅1→)⁢ (x→⋅y→) B= (1→⋅1→)⁢ (x→⋅x→)- (1→⋅x→)⁢ (1→⋅x→) C= (1→⋅x→)⁢ (x→⋅y→)- (x→⋅x→)⁢ (1→⋅y→)