10-4. The Least Squares Regression Line
Last updated
Last updated
Once the scatter diagram of the data has been drawn and the model assumptions described in the previous sections at least visually verified (and perhaps the correlation coefficient computed to quantitatively verify the linear trend), the next step in the analysis is to find the straight line that best fits the data. We will explain how to measure how well a straight line fits a collection of points by examining how well the line fits the data set
x 2 2 6 8 10 y 0 1 2 3 3
(which will be used as a running example for the next three sections). We will write the equation of this line as with an accent on the to indicate that the -values computed using this equation are not from the data. We will do this with all lines approximating data sets. The line was selected as one that seems to fit the data reasonably well.
The idea for measuring the goodness of fit of a straight line to data is illustrated in Figure 10.6 "Plot of the Five-Point Data and the Line ", in which the graph of the line has been superimposed on the scatter plot for the sample data set.
Figure 10.6 Plot of the Five-Point Data and the Line
To each point in the data set there is associated an “error,” the positive or negative vertical distance from the point to the line: positive if the point is above the line and negative if it is below the line.
The computation of the error for each of the five points in the data set is shown in Table 10.1 "The Errors in Fitting Data with a Straight Line".
Table 10.1 The Errors in Fitting Data with a Straight Line
2
0
0
0
0
2
1
0
1
1
6
2
2
0
0
8
3
3
0
0
10
3
4
−1
1
-
-
-
0
2
A first thought for a measure of the goodness of fit of the line to the data would be simply to add the errors at every point, but the example shows that this cannot work well in general. The line does not fit the data perfectly (no line can), yet because of cancellation of positive and negative errors the sum of the errors (the fourth column of numbers) is zero.
Instead goodness of fit is measured by the sum of the squares of the errors. Squaring eliminates the minus signs, so no cancellation can occur. For the data and line in Figure 10.6 "Plot of the Five-Point Data and the Line " the sum of the squared errors (the last column of numbers) is 2. This number measures the goodness of fit of the line to the data.
We will compute the least squares regression line for the five-point data set, then for a more practical example that will be another running example for the introduction of new concepts in this and the next three sections.
EXAMPLE 2. Find the least squares regression line for the five-point data set
x 2 2 6 8 10 y 0 1 2 3 3
[ Solution ]
so that
The least squares regression line for these data is
TABLE 10.2 THE ERRORS IN FITTING DATA WITH THE LEAST SQUARES REGRESSION LINE
2
0
0.5625
−0.5625
0.31640625
2
1
0.5625
0.4375
0.19140625
6
2
1.9375
0.0625
0.00390625
8
3
2.6250
0.3750
0.14062500
10
3
3.3125
−0.3125
0.09765625
EXAMPLE 3. Table 10.3 "Data on Age and Value of Used Automobiles of a Specific Make and Model" shows the age in years and the retail value in thousands of dollars of a random sample of ten automobiles of the same make and model.
Construct the scatter diagram.
Compute the linear correlation coefficient r. Interpret its value in the context of the problem.
Compute the least squares regression line. Plot it on the scatter diagram.
Interpret the meaning of the slope of the least squares regression line in the context of the problem.
Suppose a four-year-old automobile of this make and model is selected at random. Use the regression equation to predict its retail value.
Suppose a 20-year-old automobile of this make and model is selected at random. Use the regression equation to predict its retail value. Interpret the result.
Comment on the validity of using the regression equation to predict the price of a brand new automobile of this make and model.
TABLE 10.3 DATA ON AGE AND VALUE OF USED AUTOMOBILES OF A SPECIFIC MAKE AND MODEL
x
2
3
3
3
4
4
5
5
5
6
y
28.7
24.8
26.0
30.5
23.8
24.6
23.8
20.4
21.6
22.1
[ Solution ]
Figure 10.7 Scatter Diagram for Age and Value of Used Automobiles
The scatter diagram is shown in Figure 10.7 "Scatter Diagram for Age and Value of Used Automobiles".
so that
which corresponds to $24,630.
For emphasis we highlight the points raised by parts (f) and (g) of the example.
The process of using the least squares regression equation to estimate the value of y at a value of x that does not lie in the range of the x-values in the data set that was used to form the regression line is called extrapolation. It is an invalid use of the regression equation that can lead to errors, hence should be avoided.
In general, in order to measure the goodness of fit of a line to a set of data, we must compute the predicted y-value yˆy^ at every point in the data set, compute each error, square it, and then add up all the squares. In the case of the least squares regression line, however, the line that best fits the data, the sum of the squared errors can be computed directly from the data using the following formula.
The sum of the squared errors for the least squares regression line is denoted by SSE.SSE. It can be computed using the formula
x 2 2 6 8 10 y 0 1 2 3 3
Do so in two ways:
.
[ Solution ]
[ Solution ]
Then
Therefore
The error can be computed as the actual -value of the point minus the -value that is “predicted” by inserting the x-value of the data point into the formula for the line:
The goodness of fit of a line to a set of pairs of numbers in a sample is the sum of the squared errors
( terms in the sum, one for each data pair).
Given any collection of pairs of numbers (except when all the -values are the same) and the corresponding scatter diagram, there always exists exactly one straight line that fits the data better than any other, in the sense of minimizing the sum of the squared errors. It is called the least squares regression line. Moreover there are formulas for its slope and y-intercept.
Given a collection of pairs of numbers (in which not all the x-values are the same), there is a line that best fits the data in the sense of minimizing the sum of the squared errors. It is called the least squares regression line. Its slope and -intercept are computed using the formulas
and
where ,
is the mean of all the -values, is the mean of all the -values, and is the number of pairs in the data set.
The equation specifying the least squares regression line is called the least squares regression equation.
Remember from Section 10.3 "Modelling Linear Relationships with Randomness Present" that the line with the equation is called the population regression line. The numbers and are statistics that estimate the population parameters and .
and verify that it fits the data better than the line considered in Section 10.4.1 "Goodness of Fit of a Straight Line to Data".
The computations for measuring how well it fits the sample data are given in Table 10.2 "The Errors in Fitting Data with the Least Squares Regression Line". The sum of the squared errors is the sum of the numbers in the last column, which is 0.75. It is less than 2, the sum of the squared errors for the fit of the line to this data set.
We must first compute which means computing , , , , and . Using a computing device we obtain Thus
The age and value of this make and model automobile are moderately strongly negatively correlated. As the age increases, the value of the automobile tends to decrease.
Using the values of and computed in part (b),
Thus using the values of from part (b),
The equation of the least squares regression line for these sample data is
Figure 10.8 "Scatter Diagram and Regression Line for Age and Value of Used Automobiles" shows the scatter diagram with the graph of the least squares regression line superimposed. Figure 10.8 Scatter Diagram and Regression Line for Age and Value of Used Automobiles
The slope −2.05 means that for each unit increase in (additional year of age) the average value of this make and model vehicle decreases by about 2.05 units (about $2,050).
Since we know nothing about the automobile other than its age, we assume that it is of about average value and use the average value of all four-year-old vehicles of this make and model as our estimate. The average value is simply the value of obtained when the number 4 is inserted for in the least squares regression equation:
Now we insert into the least squares regression equation, to obtain
which corresponds to −$8,170. Something is wrong here, since a negative makes no sense. The error arose from applying the regression equation to a value of not in the range of -values in the original data, from two to six years.
Applying the regression equation to a value of outside the range of -values in the data set is called extrapolation. It is an invalid use of the regression equation and should be avoided.
The price of a brand new vehicle of this make and model is the value of the automobile at age 0. If the value is inserted into the regression equation the result is always , the -intercept, in this case 32.83, which corresponds to $32,830. But this is a case of extrapolation, just as part (f) was, hence this result is invalid, although not obviously so. In the context of the problem, since automobiles tend to lose value much more quickly immediately after they are purchased than they do after they are several years old, the number $32,830 is probably an underestimate of the price of a new automobile of this make and model.
EXAMPLE 4. Find the sum of the squared errors for the least squares regression line for the five-point data set
using the definition ;
using the formula .
The least squares regression line was computed in Note 10.18 "Example 2" and is . was found at the end of that example using the definition . The computations were tabulated in Table 10.2 "The Errors in Fitting Data with the Least Squares Regression Line". is the sum of the numbers in the last column, which is 0.75.
The numbers and were already computed in Note 10.18 "Example 2" in the process of finding the least squares regression line. So was the number . We must compute . To do so it is necessary to first compute Then
so that
EXAMPLE 5. Find the sum of the squared errors for the least squares regression line for the data set, presented in Table 10.3 "Data on Age and Value of Used Automobiles of a Specific Make and Model", on age and values of used vehicles in Note 10.19 "Example 3".
From Note 10.19 "Example 3" we already know that , , and .
To compute we first compute
.