1 simple linear regression chapter 17. 2 17.1 introduction in chapters 17 to 19 we examine the...
Post on 22-Dec-2015
218 views
TRANSCRIPT
1
Simple Linear Regression Simple Linear Regression
Chapter 17
2
17.1 Introduction
• In Chapters 17 to 19 we examine the relationship between interval variables via a mathematical equation.
• The motivation for using the technique:– Forecast the value of a dependent variable (y) from
the value of independent variables (x1, x2,…xk.).– Analyze the specific relationships between the
independent variables and the dependent variable.
3
House size
HouseCost
Most lots sell for $25,000
Building a house costs about
$75 per square foot.
House cost = 25000 + 75(Size)
17.2 The Model
The model has a deterministic and a probabilistic components
4
House cost = 25000 + 75(Size)
House size
HouseCost
Most lots sell for $25,000
However, house cost vary even among same size houses!
17.2 The Model
Since cost behave unpredictably, we add a random component.
5
17.2 The Model
• The first order linear model
y = dependent variablex = independent variable0 = y-intercept1 = slope of the line = error variable
xy 10 xy 10
x
y
0 Run
Rise = Rise/Run
0 and 1 are unknown populationparameters, therefore are estimated from the data.
6
17.3 Estimating the Coefficients
• The estimates are determined by – drawing a sample from the population of interest,– calculating sample statistics.– producing a straight line that cuts into the data.
Question: What should be considered a good line?
x
y
7
The Least Squares (Regression) Line
A good line is one that minimizes the sum of squared differences between the points and the line.
8
The Least Squares (Regression) Line
3
3
41
1
4
(1,2)
2
2
(2,4)
(3,1.5)
Sum of squared differences = (2 - 1)2 + (4 - 2)2 + (1.5 - 3)2 +
(4,3.2)
(3.2 - 4)2 = 6.89Sum of squared differences = (2 -2.5)2 + (4 - 2.5)2 + (1.5 - 2.5)2 + (3.2 - 2.5)2 = 3.99
2.5
Let us compare two linesThe second line is horizontal
The smaller the sum of squared differencesthe better the fit of the line to the data.
9
The Estimated Coefficients
To calculate the estimates of the line coefficients, that minimize the differences between the data points and the line, use the formulas:
xbyb
s
)Y,Xcov(b
10
2x
1
xbyb
s
)Y,Xcov(b
10
2x
1
The regression equation that estimatesthe equation of the first order linear modelis:
xbby 10 xbby 10
10
• Example 17.2 (Xm17-02)– A car dealer wants to find
the relationship between the odometer reading and the selling price of used cars.
– A random sample of 100 cars is selected, and the data recorded.
– Find the regression line.
Car Odometer Price1 37388 146362 44758 141223 45833 140164 30862 155905 31705 155686 34010 14718
. . .
. . .
. . .
Independent variable x
Dependent variable y
The Simple Linear Regression Line
11
The Simple Linear Regression Line
• Solution– Solving by hand: Calculate a number of statistics
;823.822,14y
;45.009,36x
511,712,21n
)yy)(xx()Y,Xcov(
690,528,431n
)xx(s
ii
2i2
x
where n = 100.
067,17)45.009,36)(06232.(82.822,14xbyb
06232.690,528,43511,712,1
s)Y,Xcov(
b
10
2x
1
x0623.067,17xbby 10
12
• Solution – continued– Using the computer (Xm17-02)
Tools > Data Analysis > Regression > [Shade the y range and the x range] > OK
The Simple Linear Regression Line
13
SUMMARY OUTPUT
Regression StatisticsMultiple R 0.8063R Square 0.6501Adjusted R Square0.6466Standard Error 303.1Observations 100
ANOVAdf SS MS F Significance F
Regression 1 16734111 16734111 182.11 0.0000Residual 98 9005450 91892Total 99 25739561
CoefficientsStandard Error t Stat P-valueIntercept 17067 169 100.97 0.0000Odometer -0.0623 0.0046 -13.49 0.0000
xy 0623.067,17ˆ
The Simple Linear Regression LineXm17-02
14
This is the slope of the line.For each additional mile on the odometer,the price decreases by an average of $0.0623
Odometer Line Fit Plot
13000
14000
15000
16000
Odometer
Pri
ce
xy 0623.067,17ˆ
Interpreting the Linear Regression -Equation
The intercept is b0 = $17067.
0 No data
Do not interpret the intercept as the “Price of cars that have not been driven”
17067
15
17.4 Error Variable: Required Conditions
• The error is a critical part of the regression model.• Four requirements involving the distribution of must
be satisfied.– The probability distribution of is normal.– The mean of is zero: E() = 0.– The standard deviation of is for all values of x.– The set of errors associated with different values of y are
all independent.
16
The Normality of
From the first three assumptions we have:y is normally distributed with meanE(y) = 0 + 1x, and a constant standard deviation
From the first three assumptions we have:y is normally distributed with meanE(y) = 0 + 1x, and a constant standard deviation
0 + 1x1
0 + 1x2
0 + 1x3
E(y|x2)
E(y|x3)
x1 x2 x3
E(y|x1)
The standard deviation remains constant,
but the mean value changes with x
17
17.5 Assessing the Model
• The least squares method will produces a regression line whether or not there are linear relationship between x and y.
• Consequently, it is important to assess how well the linear model fits the data.
• Several methods are used to assess the model. All are based on the sum of squares for errors, SSE.
18
– This is the sum of differences between the points and the regression line.
– It can serve as a measure of how well the line fits the data. SSE is defined by
.)yy(SSEn
1i
2ii
.)yy(SSEn
1i
2ii
Sum of Squares for Errors
2x
2Y
s
)Y,Xcov(s)1n(SSE
2x
2Y
s
)Y,Xcov(s)1n(SSE
– A shortcut formula
19
– The mean error is equal to zero.– If is small the errors tend to be close to zero
(close to the mean error). Then, the model fits the data well.
– Therefore, we can, use as a measure of the suitability of using a linear model.
– An estimator of is given by s
2
tan
n
SSEs
EstimateofErrordardS
2
tan
n
SSEs
EstimateofErrordardS
Standard Error of Estimate
20
• Example 17.3– Calculate the standard error of estimate for Example 17.2,
and describe what does it tell you about the model fit?• Solution
13.30398
450,005,92n
SSEs
450,005,9690,528,43
)511,712,2()996,259(99
s)Y,Xcov(
s)1n(SSE
996,2591n
)yy(s
2
2x
2Y
2ii2
Y
Calculated before
It is hard to assess the model based on s even when compared with the mean value of y.
823,14y1.303s
Standard Error of Estimate,Example
21
Testing the slope– When no linear relationship exists between two
variables, the regression line should be horizontal.
Different inputs (x) yielddifferent outputs (y).
No linear relationship.Different inputs (x) yieldthe same output (y).
The slope is not equal to zero The slope is equal to zero
Linear relationship.Linear relationship.Linear relationship.Linear relationship.
22
• We can draw inference about 1 from b1 by testingH0: 1 = 0H1: 1 = 0 (or < 0,or > 0)– The test statistic is
– If the error variable is normally distributed, the statistic is Student t distribution with d.f. = n-2.
1b
11
sb
t
1b
11
sb
t
The standard error of b1.
2x
bs)1n(
ss
1
2x
bs)1n(
ss
1
where
Testing the Slope
23
• Example 17.4– Test to determine whether there is enough evidence
to infer that there is a linear relationship between the car auction price and the odometer reading for all three-year-old Tauruses, in Example 17.2. Use = 5%.
Testing the Slope,Example
24
• Solving by hand– To compute “t” we need the values of b1 and sb1.
– The rejection region is t > t.025 or t < -t.025 with = n-2 = 98.Approximately, t.025 = 1.984
49.1300462
00623
00462.)690,528,43)(99(
1.303
)1(
0623.
1
1
11
2
1
.
.s
bt
sn
ss
b
b
x
b
Testing the Slope,Example
25
Price Odometer SUMMARY OUTPUT14636 3738814122 44758 Regression Statistics14016 45833 Multiple R 0.806315590 30862 R Square 0.650115568 31705 Adjusted R Square0.646614718 34010 Standard Error 303.114470 45854 Observations 10015690 1905715072 40149 ANOVA14802 40237 df SS MS F Significance F15190 32359 Regression 1 16734111 16734111 182.11 0.000014660 43533 Residual 98 9005450 9189215612 32744 Total 99 2573956115610 3447014634 37720 CoefficientsStandard Error t Stat P-value14632 41350 Intercept 17067 169 100.97 0.000015740 24469 Odometer -0.0623 0.0046 -13.49 0.0000
• Using the computer
There is overwhelming evidence to inferthat the odometer reading affects the auction selling price.
Testing the Slope,Example Xm17-02
26
– To measure the strength of the linear relationship we use the coefficient of determination.
2
i
22y
2x
22
)yy(
SSE1Ror
ss
)Y,Xcov(R
2i
22y
2x
22
)yy(
SSE1Ror
ss
)Y,Xcov(R
Coefficient of determination
27
Coefficient of determination
• To understand the significance of this coefficient note:
Overall variability in yThe regression model
Remains, in part, unexplained The error
Explained in part by
28
Coefficient of determination
x1 x2
y1
y2
y
Two data points (x1,y1) and (x2,y2) of a certain sample are shown.
22
21 )yy()yy( 2
22
1 )yy()yy( 222
211 )yy()yy(
Total variation in y = Variation explained by the regression line
+ Unexplained variation (error)
Variation in y = SSR + SSE
29
Coefficient of determination
• R2 measures the proportion of the variation in y that is explained by the variation in x.
2i
2i
2i
2i
2
)yy(
SSR
)yy(
SSE)yy(
)yy(
SSE1R
• R2 takes on any value between zero and one.R2 = 1: Perfect match between the line and the data points.R2 = 0: There are no linear relationship between x and y.
30
• Example 17.5– Find the coefficient of determination for Example 17.2;
what does this statistic tell you about the model?• Solution
– Solving by hand; 6501.)],[cov(
)996,259)(688,528,43(]511,712,2[
22
22 2
yx ss
yxR
Coefficient of determination,Example
31
SUMMARY OUTPUT
Regression StatisticsMultiple R 0.8063R Square 0.6501Adjusted R Square0.6466Standard Error 303.1Observations 100
ANOVAdf SS MS F Significance F
Regression 1 16734111 16734111 182.11 0.0000Residual 98 9005450 91892Total 99 25739561
CoefficientsStandard Error t Stat P-valueIntercept 17067 169 100.97 0.0000Odometer -0.0623 0.0046 -13.49 0.0000
– Using the computer From the regression output we have
65% of the variation in the auctionselling price is explained by the variation in odometer reading. Therest (35%) remains unexplained bythis model.
Coefficient of determination
32
17.6 Finance Application: Market Model
• One of the most important applications of linear regression is the market model.
• It is assumed that rate of return on a stock (R) is linearly related to the rate of return on the overall market.
R = 0 + 1Rm +Rate of return on a particular stock Rate of return on some major stock index
The beta coefficient measures how sensitive the stock’s rate of return is to changes in the level of the overall market.
33
The Market Model, Example
SUMMARY OUTPUT
Regression StatisticsMultiple R 0.5601R Square 0.3137Adjusted R Square0.3019Standard Error0.0631Observations 60
ANOVAdf SS MS F Significance F
Regression 1 0.10563 0.10563 26.51 0.0000Residual 58 0.231105 0.003985Total 59 0.336734
CoefficientsStandard Error t Stat P-valueIntercept 0.0128 0.0082 1.56 0.1245TSE 0.8877 0.1724 5.15 0.0000
• Estimate the market model for Nortel, a stock traded in the Toronto Stock Exchange (TSE).
• Data consisted of monthly percentage return for Nortel and monthly percentage return for all the stocks.
This is a measure of the stock’smarket related risk. In this sample, for each 1% increase in the TSE return, the average increase in Nortel’s return is .8877%.
This is a measure of the total market-related risk embedded in the Nortel stock.Specifically, 31.37% of the variation in Nortel’sreturn are explained by the variation in the TSE’s returns.
Example 17.6 (Xm17-06)
34
• If we are satisfied with how well the model fits the data, we can use it to predict the values of y.
• To make a prediction we use– Point prediction, and– Interval prediction
17.7 Using the Regression Equation
• Before using the regression model, we need to assess how well it fits the data.
35
Point Prediction
• Example 17.7– Predict the selling price of a three-year-old Taurus
with 40,000 miles on the odometer (Example 17.2).
– It is predicted that a 40,000 miles car would sell for $14,575.
– How close is this prediction to the real price?
575,14)000,40(0623.17067x0623.17067y A point prediction
36
Interval Estimates• Two intervals can be used to discover how closely the
predicted value will match the true value of y.– Prediction interval – predicts y for a given value of x,– Confidence interval – estimates the average y for a given x.
– The confidence interval– The confidence interval
2x
2g
2 s)1n()xx(
n1
sty
2x
2g
2 s)1n()xx(
n1
sty
– The prediction interval– The prediction interval
2x
2g
2 s)1n()xx(
n1
1sty
2x
2g
2 s)1n()xx(
n1
1sty
37
Interval Estimates,Example
• Example 17.7 - continued – Provide an interval estimate for the bidding price on
a Ford Taurus with 40,000 miles on the odometer.– Two types of predictions are required:
• A prediction for a specific car• An estimate for the average price per car
38
Interval Estimates,Example
• Solution– A prediction interval provides the price estimate for a
single car:
2x
2g
2 s)1n()xx(
n1
1sty
605575,14690,528,43)1100(
)009,36000,40(
100
11)1.303(984.1)]40000(0623.067,17[
2
t.025,98
Approximately
39
• Solution – continued– A confidence interval provides the estimate of the
mean price per car for a Ford Taurus with 40,000 miles reading on the odometer.
• The confidence interval (95%) =
2
i
2g
2)xx(
)xx(
n1
sty
70575,14690,528,43)1100(
)009,36000,40(
100
1)1.303(984.1)]40000(0623.067,17[
2
Interval Estimates,Example
40
– As xg moves away from x the interval becomes longer. That is, the shortest interval is found at x.
2x
2g
2 s)1n(
)xx(
n1
sty
x
g10 xbby
The effect of the given xg on the length of the interval
41
x1x)1x( 1x)1x(
g10 xbby
)1xx(y g )1xx(y g
1x 1x
– As xg moves away from x the interval becomes longer. That is, the shortest interval is found at x.
The effect of the given xg on the length of the interval
2x
2g
2 s)1n(
)xx(
n1
sty
2x
2
2 s)1n(1
n1
sty
42
x
– As xg moves away from x the interval becomes longer. That is, the shortest interval is found at x.
g10 xbby
2x)2x( 2x)2x(
2x 2x
2x
2g
2 s)1n()xx(
n1
sty
2x
2
2 s)1n(1
n1
sty
2x
2
2 s)1n(2
n1
sty
The effect of the given xg on the length of the interval
43
17.8 Coefficient of Correlation
• The coefficient of correlation is used to measure the strength of association between two variables.
• The coefficient values range between -1 and 1.– If r = -1 (negative association) or r = +1 (positive
association) every point falls on the regression line.– If r = 0 there is no linear pattern.
• The coefficient can be used to test for linear relationship between two variables.
44
• To test the coefficient of correlation for linear relationship between X and Y– X and Y must be observational– X and Y are bivariate normally distributed
Testing the coefficient of correlation
X
Y
45
yxss
yxrbycalculated
ncorrelatiooftcoefficien
sampletheisrwherer
nrt
),cov(
1
22
• When no linear relationship exist between the two variables, = 0.
• The hypotheses are:H0: 0H1: 0
• The test statistic is:
The statistic is Student t distributed with d.f. = n - 2, provided the variables are bivariate normally distributed.
Testing the coefficient of correlation
46
Testing the Coefficient of correlation
• Foreign Index Funds (Index)– A certain investor prefers the investment in an index
mutual funds constructed by buying a wide assortment of stocks.
– The investor decides to avoid the investment in a Japanese index fund if it is strongly correlated with an American index fund that he owns.
– From the data shown in Index.xls should he avoid the investment in the Japanese index fund?
47
Testing the Coefficient of correlation
• Foreign Index Funds– A certain investor prefers the investment in an index
mutual funds constructed by buying a wide assortment of stocks.
– The investor decides to avoid the investment in a Japanese index fund if it is strongly correlated with an American index fund that he owns.
– From the data shown in Index.xls should he avoid the investment in the Japanese index fund?
48
• Solution– Problem objective: Analyze relationship between two
interval variables.– The two variables are observational (the return for
each fund was not controlled).– We are interested in whether there is a linear
relationship between the two variables, thus, we need to test the coefficient of correlation
Testing the Coefficient of Correlation,Example
49
• Solution – continued– The hypotheses
H0: 0H1: 0.
– Solving by hand: • The rejection region:
|t| > t/2,n-2 = t.025,59-2 2.000.
• The sample coefficient of correlation: Cov(x,y) = .001279; sx = .0509; sy = 0512 r = cov(x,y)/sxsy=.491
The value of the t statistic is
Conclusion: There is sufficientevidence at = 5% to infer thatthere are linear relationshipbetween the two variables.
26.4r12n
rt2
Testing the Coefficient of Correlation,Example
50
– Excel solution (Index)
Testing the Coefficient of Correlation,Example
US Index Japanese IndexUS Index 1Japanese Index 0.4911 1
51
Spearman Rank Correlation Coefficient • The Spearman rank test is a nonparametric procedure.• The procedure is used to test linear relationships
between two variables when the bivariate distribution is nonnormal.
• Bivariate nonnormal distribution may occur when– at least one variable is ordinal, or– both variables are interval but at least one variable is not
normal.
52
– The hypotheses are:• H0: s 0
• H1: s 0
– The test statistic is
where ‘a’ and ‘b’ are the ranks of x and y respectively.
bas ss
)b,acov(r
1nrz s
– For a large sample (n > 30) rs is approximately normally distributed
Spearman Rank Correlation Coefficient
53
Spearman Rank Correlation Coefficient,Example
• Example 17.8 (Xm17-08)– A production manager wants to examine the
relationship between: • Aptitude test score given prior to hiring, and • Performance rating three months after starting work.
– A random sample of 20 production workers was selected. The test scores as well as performance rating was recorded.
54
Spearman Rank Correlation Coefficient,Example
Aptitude Performance Employee test rating
1 59 32 47 23 58 44 66 35 77 2. . .. . .. . .
Scores range from 0 to 100 Scores range from 1 to 5
55
Spearman Rank Correlation Coefficient,Example
• Solution– The problem objective is to analyze the
relationship between two variables.(Note: Performance rating is ordinal.)
– The hypotheses are:• H0:s = 0
• H1: s = 0
– The test statistic is rs, and the rejection region is |rs| > rcritical (taken from the Spearman rank correlation table).
56
Spearman Rank Correlation Coefficient,Example
Aptitude Performance Employee test rating
1 59 32 47 23 58 44 66 35 77 2. . .. . .. . .
Ties are brokenby averaging theranks.
– Solving by hand• Rank each variable separately.
• Calculate sa = 5.92; sb =5.50; cov(a,b) = 12.34
• Thus rs = cov(a,b)/[sasb] = .379.• The critical value for = .05 and n = 20 is .450.
Rank(a)938
1420...
Rank(b)10.53.517
10.53.5
.
.
.
57
Conclusion: Do not reject the null hypothesis. At 5% significance level there is insufficient evidence to infer that the two variables are related to one another.
Conclusion: Do not reject the null hypothesis. At 5% significance level there is insufficient evidence to infer that the two variables are related to one another.
Spearman Rank Correlation Coefficient,Example
58
• Excel Solution (Data Analysis Plus; Xm17-08)
Spearman Rank Correlation Coefficient,Example
Spearman Rank Correlation
Aptitude and PerformanceSpearman Rank Correlation 0.3792z Stat 1.65P(Z<=z) one tail 0.0492z Critical one tail 1.6449P(Z<=z) two tail 0.0984z Critical two tail 1.96
> 0.05
59
17.9 Regression Diagnostics - I
• The three conditions required for the validity of the regression analysis are:– the error variable is normally distributed.– the error variance is constant for all values of x.– The errors are independent of each other.
• How can we diagnose violations of these conditions?
60
Residual Analysis
• Examining the residuals (or standardized residuals), help detect violations of the required conditions.
• Example 17.2 – continued:– Nonnormality.
• Use Excel to obtain the standardized residual histogram.• Examine the histogram and look for a bell shaped.
diagram with a mean close to zero.
61
For each residual we calculate the standard deviation as follows:
2x
2i
i
ir
s)1n()xx(
n1
h
whereh1ssi
A Partial list ofStandard residuals
ObservationPredicted Price Residuals Standard Residuals1 14736.91 -100.91 -0.332 14277.65 -155.65 -0.523 14210.66 -194.66 -0.654 15143.59 446.41 1.485 15091.05 476.95 1.58
Standardized residual ‘i’ =Residual ‘i’
Standard deviation
Residual Analysis
62
Standardized residuals
0
10
20
30
40
-2 -1 0 1 2 More
It seems the residual are normally distributed with mean zero
Residual Analysis
63
Heteroscedasticity• When the requirement of a constant variance is violated we have
a condition of heteroscedasticity.• Diagnose heteroscedasticity by plotting the residual against the
predicted y.
+ + ++
+ ++
++
+
+
+
+
+
+
+
+
+
+
++
+
+
+
The spread increases with y
y
Residualy
+
+++
+
++
+
++
+
+++
+
+
+
+
+
++
+
+
64
Homoscedasticity• When the requirement of a constant variance is not violated we have a
condition of homoscedasticity.• Example 18.2 - continued
-1000
-500
0
500
1000
13500 14000 14500 15000 15500 16000
Predicted Price
Re
sid
ua
ls
65
Non Independence of Error Variables
– A time series is constituted if data were collected over time.
– Examining the residuals over time, no pattern should be observed if the errors are independent.
– When a pattern is detected, the errors are said to be autocorrelated.
– Autocorrelation can be detected by graphing the residuals against time.
66
Patterns in the appearance of the residuals over time indicates that autocorrelation exists.
+
+++ +
++
++
+ +
++ + +
+
++ +
+
+
+
+
+
+Time
Residual Residual
Time+
+
+
Note the runs of positive residuals,replaced by runs of negative residuals
Note the oscillating behavior of the residuals around zero.
0 0
Non Independence of Error Variables
67
Outliers• An outlier is an observation that is unusually small or large.• Several possibilities need to be investigated when an outlier
is observed:– There was an error in recording the value.– The point does not belong in the sample.– The observation is valid.
• Identify outliers from the scatter diagram.• It is customary to suspect an observation is an outlier if its |
standard residual| > 2
68
+
+
+
+
+ +
+ + ++
+
+
+
+
+
+
+
The outlier causes a shift in the regression line
… but, some outliers may be very influential
++++++++++
An outlier An influential observation
69
Procedure for Regression Diagnostics
• Develop a model that has a theoretical basis.• Gather data for the two variables in the model.• Draw the scatter diagram to determine whether a linear model
appears to be appropriate.• Determine the regression equation.• Check the required conditions for the errors.• Check the existence of outliers and influential observations• Assess the model fit.• If the model fits the data, use the regression equation.