You are on page 1of 2

LEAST SQUARES TRENDLINE

INTRO In the real world, we often gather data that looks like it would be well fit by a certain function or model, but not perfectly. For example, you might have data that looks like it's well fit by a line, but it's a bit scattered. In order to find the line that best fits the data, we need to figure out the correct slope and y-intercept, but it's not always easy to tell what the best line will be...the "least squares" method helps us find this!

LEAST SQUARES LINE In order to find the best line, we want to minimize the distance of the data points to the line that we select. The most common way to do this is the "least squares" method, where we minimize the square of the distance of the points to the line. This method is illustrated in the diagram below, where we minimize the area of the yellow boxes.

If we want to minimize the sum of the squares, the appropriate formula for the slope and y-intercept of the line of best fit becomes: n( xy ) ( x )( y ) x 2 ( y ) ( x )( xy ) m= b= 2 2 n x 2 ( x ) n x 2 ( x )

) (

_______________________________________________________________________ Example: Consider the three data points: (2, 10), (3, 14), (4, 20). Find the least squares line for this set of data.

Solution: First, lets find the quantities that we need to substitute into the formulas. n = 3, x = 9, y = 44, xy = 142, x 2 = 29
At this point, we just have to plug in the values we found above into the formula for the slope and the y-intercept:
m= = n( xy ) ( x )( y ) 3(142 ) (9 )(44 ) 3(29 ) (9 )
2

n x 2 ( x )

( x )( y ) ( x )( xy ) b= n( x ) ( x )
2 2 2

and

(29)(44) (9)(142) 2 3(29 ) (9 )


1 3

=5

1 3 _______________________________________________________________________
So, finally, our least squares line (i.e. the line of best fit) is y = 5 x

CORRELATION In order to determine whether our data is well fit by a line, we define something called the coefficient of correlation, denoted r. Here's how to interpret it: A value close to 1 means that the data is extremely well fit by a line with positive slope. A value close to -1 means that the data is extremely well fit by a line with negative slope. A value close 0 means that the data is not well fit by a line.

r=

n x 2 ( x ) n y 2 ( y )
2

n( xy ) ( x )( y )

_______________________________________________________________________ Example: Lets again consider the three data points: (2, 10), (3, 14), (4, 20) that we found the least squares line for in the example above. Find the coefficient of correlation.

Solution: We first need to find the quantities that we need to substitute into the formula (all of these were already found above except the last one). n = 3, x = 9, y = 44, xy = 142, x 2 = 29, y 2 = 696 Now, we just go ahead and substitute everything into the formula:

r= = =

n x 2 ( x ) n y 2 ( y )
2

n( xy ) ( x )( y )

3(142 ) (9)(44)
2

3(29 ) (9 ) 3(696 ) (44 )

30 6 152 0.9934
Since we obtain a value that is very close to 1, it appears that the data is well fit by a line with positive slope. _______________________________________________________________________

You might also like