THE LEAST SQUARES LINE

advertisement
1
THE LEAST SQUARES LINE (other names ‘Best-Fit Line’ or ‘Regression Line’) 2015
Problem:
A sales manager noticed that the annual sales of his employees increase with years of experience. To estimate the annual
sales for his potential new sales person he collected data concerning annual sales and years of experience of his current
employees: We’ll use his data to create a formula that will help him estimate annual sales based on years of experience.
3
100
8
110
10
120
Work:
Figure to the right shows scatter graph of his data. Each
point represents data on one single current employee.
For example: the first employee has 1 year of
experience and made 80 thousands in sales, so he is
represented by the point with coordinates (1,80).
13
140
Sales
1
80
Years of experience
Annual sales in thousands
150
140
130
120
110
100
90
80
70
60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Years
We’ll create equation of the least squares line, which
is also called best-fit line or regression line. The line is
passing in between our points while the sum of the
squares of the vertical distances from the data points to
the line is as small as possible. The picture to the left
shows the least square line passing in between our
points, and the distances d1, d2, d3, d4, and d5. The
equation of the least square line is found by minimizing
the sum:
(d1 ) 2  (d 2 ) 2  (d 3 ) 2  (d 4 ) 2  (d 5 ) 2
The procedure will be omitted in this paper. The final
result of the minimization are formulas that let us
calculate coefficients a and b for equation of the least
square line y  ax  b . This equation may be used for
the prediction of sales.
FORMULAS FOR COEFFICIENTS OF THE LEAST SQUARES LINE:
a
n xy   x  y 


n  x 2   x 
2
b
 y  a   x 
n
In this formula n stands for number of observed cases. In our case that is 5 employees. So:
Symbol
is called “sigma” and stands for the “sum of all”. In our case:

 x  1  3  8  10  13  35
 y  80  100  110  110  120  140  550
 x  1  3  8  10  13  343
 xy  1 80  3 100  8 110  10 120  13 140  4280
2
2
2
2
2
2
(sum of all x values)
(sum of all y values)
(sum of squares of x values)
(sum of xy products)
n5
2
We are now ready to use results of our calculations in the formula:
a
5  4280  35  550 2150

 4.388
490
5  343  35 2
b
550  4.388  35 396.42

 79.284
5
5
That means that the equation of the least square line is y  4.388 x  79.284
Conclusion:
We created the formula y  4.388 x  79.284 that may be used to predict sales in thousands for a future employee. For
example, formula may predict that an employee with x=15 years of experience will generate:
y  4.388  15  79.284  145 thousands in sales per year.
Is our prediction reliable?
Once an equation is found for the least square line, we need to have some way of judging just how good the equation is
for predictive purposes. In order to have a quantitative basis for confidence in our predictions, we need to calculate
coefficient of correlation, denoted r. It may be calculated using the following formula:
FORMULA FOR COEFFICIENT OF CORRELATION
r

n xy   x  y 



n  x 2   x   n  y 2   y 
2
2
We’ll calculate the coefficient of correlation for data in our example:
y
 80 2  100 2  110 2  120 2  140 2  62500
5  4280  35  550
2150
2150
r


 0.971
490  10000 2213.594
5  343  35 2  5  62500  550 2
2
The value of r that is close to 1 indicates that our formula will give us a reliable prediction for sales level, based on years
of experience of the employee.
What does coefficient of correlation tell us?
The correlation coefficient is always a number between  1 and 1 . The picture bellow shows how its value numerically
describes our data:
The equation may be used as a source for reliable prediction if the correlation coefficient is a number that is close to
 1 or 1 . That means that your observed values are close to the least square line (second and fourth picture above).
If not, the value of the correlation coefficient is closer to 0. Such a small value for the coefficient of correlation indicates
that the observed data are widely spread around, so our formula is not reliable source of prediction (like on first and third
picture above).
It is usually more convenient to numerically measure reliability of our formula using the square of correlation
coefficient. Some books and computer software are using symbol R 2 for it (read as ‘r square’) In our example;
R 2  0.9712  0.943
R square is always a number between 0 and 1. Values of R 2 that are close to 1 indicate reliable formula.
3
FINDING THE LEAST SQUARES LINE USING EXCEL 2007
Problem:
A sales manager noticed that the annual sales of his employees increase with years of experience. We’ll use Excel to
graph his data and create a formula that will help him estimate annual sales based on years of experience.
Years of experience
Annual sales in thousands
1
80
3
100
8
110
10
120
13
140
Work
Open a new blank sheet in Excel and type in data as shown to the
right.
Step in cell B1. While keeping left finger down, pool cursor to cell
F2. This procedure will highlight (color blue) coordinates of points
that should be graphed. Once your data are highlighted, click on
insert and select chart from the menu as shown bellow left.
New Chart Wizard pop-up screen will ask you what kind of chart do
you want. Select XY(Scatter) that compares pairs of values as shown
bellow right.
Click on finish. A simple scatter graph of your
data will appear, as shown to the right.
The next step is to draw the least squares line and
calculate its equation and R square. Carefully
right-click on any data point on the graph. A
small pop-up screen will come out as pictured
bellow. Select Add trendline.
160
140
120
100
80
Series1
60
40
20
0
0
2
4
6
8
10
12
14
4
A new pop-up screen will come out. Select Linear Trend and click on tab
Options as on the picture to the right..
In Options tab check Display equation on chart and check Display RSquared value as shown on picture bellow to the left. Click OK to
obtain the final picture.
The final picture shown bellow features the equation of the least squares line
y  4.3878 x  79.286 and the value of R square R 2  0.9434
160
y = 4.3878x + 79.286
140
2
R = 0.9434
120
100
80
60
40
20
0
0
2
4
6
8
10
12
14
NOTICE
 You can switch x and y on your graph and in your formula by clicking on ‘chart tools’ ‘switch x-y’
 to get both chart and table printed next to each other: click on blank area outside of your chart right before
saving the document
Practice questions:
1) Find the equation of the least squares line and the coefficient of
correlation for the data shown:
(Answer: y  0.614 x  10.68 , R² = 0.9759, r=-0.9879 )
x
y
2) The table to the right shows the relationship between MPG (miles per
gallon) and HP (horsepower) for some sports cars produced in year 2015.
Find the equation of the least squares line and use it to estimate MPG for
Chevrolet Corvette that has 460 HP engine.
(Answer: Using the obtained equation y = -0.03x + 30.88
2
R  0.8258 we estimate 17 MPG. Notice that the real Corvette MPG is 21
so we conclude that this car has better than expected MPG.)
3
8.7
5
7.9
7
6.2
Mitcubishi Lancer
Mazda Miata
Subaru WRX
Porche Boxter
Chevy Camaro
Ferrari Spider
x=HP
148
158
268
315
323
570
8
5.8
y=MPG
29
23
24
23
20
14
3) Millers are buying a house in NWI so they’d like to estimate yearly house taxes in Valparaiso. Using data from
ReMax web site they obtained 2014 taxes for 5 houses in that city. Use the table to create the least squares line equation
and its coefficient of correlation. Use this equation to estimate yearly taxes for a $200,000 house in Valparaiso.
x=house price in thousands
y=tax paid in year 2014
425
3570
340
2370
140
1000
250
1700
70
810
(Answer: using y = 7.6x + 34.1 we estimate yearly tax for 200 thousands house to be $1554. r=0.972)
5
4) The table below gives monthly sales y (in thousands), corresponding to advertising expenditures x (in thousands).
Advertising expenditures x 0 1 2
3
4
5
6
Monthly sales y
3 9 11 15 17 20 27
Create the least squares line. Examine if advertising expenditures appear to have strong effect on monthly sales by
calculating and interpreting R 2 , and if so, predict the monthly sales if 11 thousands dollars is spent on advertising.
(Answer: y  3.57 x  3.86 and R 2  0.97 , so if we spend 11 thousand dollars on advertising the monthly sales will
increase to 43 thousand dollars.)
5) A hospital conducted study to determine relation between age and blood pressure of their patients. The table bellow
shows collected data. Find the equation of the least squares line and use it to calculate blood pressure of a 50 years old
patient.
Age x
43
48
56
61
67
70
Pressure y 128 120 135 143 141 152
(Answer: y  0.964 x  81.048 , so 50 years old patient should have 129.)
6) Find the equation of the least squares line for the data shown below:
x
0
5
10
20
y
8
7
5
2
7) A researcher wishes to see whether there is a relationship between number of hours of study and test scores on
exam, so she collected data shown in the table bellow. Find the equation of the least squares line and use it to calculate
how many hours should a student study to obtain 93 percent on the test.
Hours of study x
Score on test y
6
82
2
63
1
57
5
88
2
68
3
75
8) The table bellow compares rents for one-bedroom and two-bedroom apartments in 7 different cities. Find the
equation of the least squares line and R square. A one-bedroom rent in a doorman building in Lower Manhattan averaged
$3000 in august 2007. Calculate a two bedroom rent using the obtained formula.
One-bedroom rent x
Two bedroom rent y
782
1223
486
902
451
739
529
954
618
1055
520
875
845
1455
9) Thanks to the progress of science the cancer survival rate is
diagnosis year
71 81 91 101
improving over time. The table shows 10-year survival rate for
percent
lived
over
10
years
18 22 25 27
ovary cancer in England, diagnosed in year 1971, 1981, 1991
and 2001. According to the table 27% of the patients diagnosed in year 2001 survived over 10 years. Find the equation
of the least squares line and R square. Use it to estimate the 10-year ovary cancer survival rate for the patients who are
diagnosed in year 2015.
10) Millers are buying a house in NWI so they’d like to estimate yearly house taxes in Crown Point. Using data from
ReMax web site they obtained 2014 taxes for 6 houses in that city. Use the table to create the least squares line equation.
Use this equation to estimate yearly taxes for a $200,000 house in Crown Point.
x=price in thousands
y=tax for year 2014
155
3096
125
1217
205
2819
275
3852
110
877
780
13390
Download