Simple Linear Regression and Correlation

Download Report

Transcript Simple Linear Regression and Correlation

Chapter 18
Simple Linear Regression
1
18.1 Introduction
• In Chapters 18 to 20 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.
2
18.2 The Model
The model has a deterministic and a probabilistic components
House
Cost
Most lots sell
for $25,000
House size
3
18.2 The Model
However, house cost vary even among same size
houses!
Since cost behave unpredictably,
House
Cost
we add a random component.
Most lots sell
for $25,000
House size
4
18.2 The Model
• The first order linear model
y  b 0  b1x  e
y = dependent variable
x = independent variable
b0 = y-intercept
b1 = slope of the line
e = error variable
y
b0 and b1 are unknown population
parameters, therefore are estimated
from the data.
Rise
b0
b1 = Rise/Run
Run
x
5
18.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.
y
w
Question: What should be
considered a good line?
w
w
w
w
w
w
w
w
w
w
w
w
w
w
x
6
The Least Squares (Regression) Line
A good line is one that minimizes
the sum of squared differences between the
points and the line.
7
The Least Squares (Regression) Line
Sum of squared differences = (2 - 1)2 + (4 - 2)2 +(1.5 - 3)2 + (3.2 - 4)2 = 6.89
Sum of squared differences = (2 -2.5)2 + (4 - 2.5)2 + (1.5 - 2.5)2 + (3.2 - 2.5)2 = 3.99
4
3
2.5
2
Let us compare two lines
The second line is horizontal
(2,4)
w
w (4,3.2)
(1,2) w
w (3,1.5)
1
1
2
3
4
The smaller the sum of
squared differences
the better the fit of the
line to the data.
8
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:
b1 
cov(X, Y)
s 2x
The regression equation that estimates
the equation of the first order linear model
is:
yˆ  b 0  b1x
b 0  y  b1x
9
The Simple Linear Regression Line
• Example 18.2 (Xm18-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
Price
1 37388
14636
2 44758
14122
3 45833
14016
4 30862
15590
5 31705
15568
6 34010
14718
.
.
.
Independent
Dependent
.
.
.
variable
x variable
y
.
.
.
10
The Simple Linear Regression Line
• Solution
– Solving by hand: Calculate a number of statistics
( x  x)


2
 43,528,690
x  36,009.45;
s 2x
y  14,822.823;
( x  x)(y

cov (X, Y) 
i
n 1
i
i
 y)
n 1
 2,712,511
where n = 100.
b1 
cov (X, Y)  1,712,511

 .06232
2
sx
43,528,690
b 0  y  b1x  14,822.82  ( .06232)(36,009.45)  17,067
yˆ  b0  b1x  17,067  .0623x
11
The Simple Linear Regression Line
• Solution – continued
– Using the computer (Xm18-02)
Tools > Data Analysis > Regression >
[Shade the y range and the x range] > OK
12
The Simple Linear Regression Line
Xm18-02
SUMMARY OUTPUT
Regression Statistics
Multiple R
0.8063
R Square
0.6501
Adjusted R Square
0.6466
Standard Error 303.1
Observations
100
yˆ  17,067 .0623x
ANOVA
df
Regression
Residual
Total
SS
MS
1 16734111 16734111
98 9005450
91892
99 25739561
CoefficientsStandard Error t Stat
Intercept
17067
169
100.97
Odometer
-0.0623
0.0046
-13.49
F
Significance F
182.11
0.0000
P-value
0.0000
0.0000
13
Odometer Line Fit Plot
16000
Price
17067
Interpreting the Linear Regression Equation
0
15000
14000
No data 13000
Odometer
yˆ  17,067 .0623x
The intercept is b0 = $17067.
Do not interpret the intercept as the
“Price of cars that have not been driven”
This is the slope of the line.
For each additional mile on the odometer,
the price decreases by an average of $0.0623
14
18.4 Error Variable: Required Conditions
• The error e is a critical part of the regression model.
• Four requirements involving the distribution of e must
be satisfied.
–
–
–
–
The probability distribution of e is normal.
The mean of e is zero: E(e) = 0.
The standard deviation of e is se for all values of x.
The set of errors associated with different values of y are
all independent.
15
The Normality of e
E(y|x3)
The standard deviation remains constant,
m3
b0 + b1x3
E(y|x2)
b0 + b1x2
m2
but the mean value changes with x
b0 + b1x1
E(y|x1)
m1
From the first three assumptions we have:
x1
y is normally distributed with mean
E(y) = b0 + b1x, and a constant standard
deviation se
x2
x3
16
18.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.
17
Sum of Squares for Errors
– 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
n
SSE 
– A shortcut formula

( y i  yˆ i ) 2 .
i 1
SSE  (n  1)s 2Y

cov(X , Y )
s 2x
18
Standard Error of Estimate
– The mean error is equal to zero.
– If se 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 se as a measure of the
suitability of using a linear model.
– An estimator of se is given by se
S tan dard Error of Estimate
SSE
se 
n2
19
Standard Error of Estimate,
Example
• Example 18.3
– Calculate the standard error of estimate for Example 18.2,
and describe what does it tell you about the model fit?
• Solution
s 2Y 

( y i  yˆ i ) 2
n 1
Calculated before
 259,996
2
cov(
X
,
Y
)
(

2
,
712
,
511
)
SSE  (n  1)s 2Y 
 99(259,996) 
 9,005,450
2
43,528,690
sx
SSE
9,005,450
se 

 303.13
n2
98
It is hard to assess the model based
on se even when compared with the
mean value of y.
s e  303.1 y  14,823
20
Testing the slope
– When no linear relationship exists between two
variables, the regression line should be horizontal.
q
q
qq
q
q
q
q
q
q
q
q
Linear relationship.
Different inputs (x) yield
different outputs (y).
No linear relationship.
Different inputs (x) yield
the same output (y).
The slope is not equal to zero
The slope is equal to zero
21
Testing the Slope
• We can draw inference about b1 from b1 by testing
H0: b1 = 0
H1: b1 = 0 (or < 0,or > 0)
– The test statistic is
b 1  b1
t
s b1
The standard error of b1.
where
s b1 
se
(n  1)s 2x
– If the error variable is normally distributed, the statistic
is Student t distribution with d.f. = n-2.
22
Testing the Slope,
Example
• Example 18.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 18.2.
Use a = 5%.
23
Testing the Slope,
Example
• Solving by hand
– To compute “t” we need the values of b1 and sb1.
b1  .0623
sb1 
t
se
(n  1) s x2

303.1
 .00462
(99)(43,528,690)
b1  b1  .0623 0

 13.49
.
00462
sb1
– The rejection region is t > t.025 or t < -t.025 with n = n-2 = 98.
Approximately, t.025 = 1.984
24
Testing the Slope,
Example Xm18-02
• Using the computer
Price
Odometer SUMMARY OUTPUT
14636
37388
14122
44758 Regression Statistics
14016
45833 Multiple R
0.8063
15590
30862 R Square
0.6501
There is overwhelming evidence to infer
15568
31705 Adjusted R Square
0.6466
14718
34010 Standard Error 303.1
that the odometer reading affects the
14470
45854 Observations
100
auction selling price.
15690
19057
15072
40149 ANOVA
14802
40237
df
SS
MS
F
Significance F
15190
32359 Regression
1 16734111 16734111
182.11
0.0000
14660
43533 Residual
98 9005450
91892
15612
32744 Total
99 25739561
15610
34470
14634
37720
Coefficients
Standard Error t Stat
P-value
14632
41350 Intercept
17067
169
100.97
0.0000
15740
24469 Odometer
-0.0623
0.0046
-13.49
0.0000
25
Coefficient of determination
– To measure the strength of the linear relationship we
use the coefficient of determination.
2

cov(
X
,
Y
)

R2 
s2x s2y
2
or R  1 
SSE
2
(
y

y
)
 i
26
Coefficient of determination
• To understand the significance of this coefficient
note:
The regression model
Overall variability in y
The error
27
Coefficient of determination
y2
Two data points (x1,y1) and (x2,y2)
of a certain sample are shown.
y
y1
x1
Total variation in y =
(y1  y ) 2  (y 2  y ) 2 
Variation in y = SSR + SSE
x2
Variation explained by the + Unexplained variation (error)
regression line
(yˆ 1  y) 2  (yˆ 2  y) 2
 (y1  yˆ 1 ) 2  (y 2  yˆ 2 ) 2
28
Coefficient of determination
• R2 measures the proportion of the variation in y
that is explained by the variation in x.
2
R  1

SSE
(y i  y)


(y  y)
(y i  y) 2  SSE
2
i
2


SSR
(y i  y) 2
• 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.
29
Coefficient of determination,
Example
• Example 18.5
– Find the coefficient of determination for Example 18.2;
what does this statistic tell you about the model?
• Solution
– Solving by hand;R 
2
[cov(x, y)]2
s x2 s 2y

[ 2,712,511]2
( 43,528,688)( 259,996 )
 .6501
30
Coefficient of determination
– Using the computer
From the regression output we have
SUMMARY OUTPUT
Regression Statistics
Multiple R
0.8063
R Square
0.6501
Adjusted R Square
0.6466
Standard Error
303.1
Observations
100
65% of the variation in the auction
selling price is explained by the
variation in odometer reading. The
rest (35%) remains unexplained by
this model.
ANOVA
df
Regression
Residual
Total
Intercept
Odometer
SS
16734111
9005450
25739561
MS
16734111
91892
CoefficientsStandard Error
17067
169
-0.0623
0.0046
t Stat
100.97
-13.49
1
98
99
F
Significance F
182.11
0.0000
P-value
0.0000
0.0000
31
18.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 = b0 + b1Rm +e
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.
32
The Market Model,
Example
Example 18.6 (Xm18-06)
SUMMARY OUTPUT
Regression Statistics
Multiple R
0.5601
R Square
0.3137
Adjusted R Square
0.3019
Standard Error0.0631
Observations
60
•
•
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 isANOVA
a measure of the stock’s
df
SS
marketRegression
related risk. In this
sample,
1 0.10563
for each
1% increase in58the0.231105
TSE
Residual
59 0.336734
return,Total
the average increase
in
Nortel’s return is .8877%.
This is a measure of the total market-related risk
MS
F Significance F
embedded
in
the Nortel
stock.
0.10563
26.51
0.0000
Specifically, 31.37% of the variation in Nortel’s
0.003985
return are explained by the variation in the
TSE’s returns.
Coefficients
Standard Error t Stat
P-value
Intercept
0.0128
0.0082
1.56
0.1245
TSE
0.8877
0.1724
5.15
0.0000
33
18.7 Using the Regression Equation
• Before using the regression model, we need to
assess how well it fits the data.
• 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
34
Point Prediction
• Example 18.7
– Predict the selling price of a three-year-old Taurus
with 40,000 miles on the odometer (Example 18.2).
A point prediction
yˆ  17067  .0623x  17067  .0623(40,000)  14,575
– It is predicted that a 40,000 miles car would sell for
$14,575.
– How close is this prediction to the real price?
35
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 prediction interval
yˆ  t a 2 s e
2
1 ( x g  x)
1 
n (n  1)s 2x
– The confidence interval
yˆ  t a 2 s e
2
1 ( x g  x)

n (n  1)s 2x
36
Interval Estimates,
Example
• Example 18.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
37
Interval Estimates,
Example
• Solution
– A prediction interval provides the price estimate for a
single car:
yˆ  t a 2 s e
t.025,98
2
1 ( x g  x)
1 
n (n  1)s 2x
Approximately
1
(40,000 36,009) 2
[17,067 .0623(40000)]  1.984(303.1) 1 

 14,575 605
100 (100 1)43,528,690
38
Interval Estimates,
Example
• 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%) = yˆ  t a 2 se
1

n
( x g  x) 2

( x i  x) 2
1
(40,000 36,009) 2
[17,067 .0623(40000)]  1.984(303.1)

 14,575 70
100 (100 1)43,528,690
39
The effect of the given xg on the
length of the interval
– As xg moves away from x the interval becomes
longer. That is, the shortest interval is found at x.
yˆ  b 0  b1x g
yˆ  t a 2 s e
2
1 ( x g  x)

n (n  1)s 2x
x
40
The effect of the given xg on the
length of the interval
– As xg moves away from x the interval becomes
longer. That is, the shortest interval is found at x.
yˆ  b 0  b1x g
yˆ ( x g  x  1)
yˆ ( x g  x  1)
yˆ  t a 2 s e
yˆ  t a 2 s e
2
1 ( x g  x)

n (n  1)s 2x
1
12

n (n  1)s 2x
x 1 x  1
x
( x  1)  x  1 ( x  1)  x  1
41
The effect of the given xg on the
length of the interval
– As xg moves away from x the interval becomes longer. That
is, the shortest interval is found at x.
yˆ  b 0  b1x g
x 2
x
x2
( x  2)  x   2 ( x  2 )  x  2
yˆ  t a 2 s e
2
1 ( x g  x)

n (n  1)s 2x
yˆ  t a 2 s e
1
12

n (n  1)s 2x
yˆ  t a 2 s e
1
22

n (n  1)s 2x
42
18.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.
43
Testing the coefficient of correlation
• 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
Y
X
44
Testing the coefficient of correlation
• When no linear relationship exist between the two
variables, r = 0.
• The hypotheses are:
H0: r  0
H1: r  0
• The test statistic is:
The statistic is Student t
distributed with d.f. = n - 2,
provided the variables
are bivariate normally
distributed.
tr
n2
1 r 2
where r is the sample
coefficient of correlation
cov(x, y )
calculatedby r 
sx s y
45
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?
46
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?
47
Testing the Coefficient of Correlation,
Example
• 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
48
Testing the Coefficient of Correlation,
Example
• Solution – continued
– The hypotheses
H0: r  0
H1: r  0.
– Solving by hand:
• The rejection region:
|t| > ta/2,n-2 = t.025,59-2  2.000.
The value of the t statistic is
n2
t r
 4.26
2
1 r
Conclusion: There is sufficient
evidence at a = 5% to infer that
there are linear relationship
between the two variables.
• The sample coefficient of correlation:
Cov(x,y) = .001279; sx = .0509; sy = 0512
r = cov(x,y)/sxsy=.491
49
Testing the Coefficient of Correlation,
Example
– Excel solution (Index)
US Index
US Index
Japanese Index
1
0.4911
Japanese Index
1
50
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.
51
Spearman Rank Correlation Coefficient
– The hypotheses are:
• H0: rs  0
• H1: rs  0
– The test statistic is
cov(a, b)
rs 
s a sb
where ‘a’ and ‘b’ are the ranks of x and y respectively.
– For a large sample (n > 30) rs is approximately
normally distributed
z  rs n  1
52
Spearman Rank Correlation Coefficient,
Example
• Example 18.8 (Xm18-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.
53
Spearman Rank Correlation Coefficient,
Example
Employee
1
2
3
4
5
.
.
.
Aptitude Performance
rating
test
3
59
2
47
4
58
3
66
2
77
.
.
.
.
.
.
Scores range from 0 to 100
Scores range from 1 to 5
54
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: rs = 0
• H1: rs = 0
– The test statistic is rs,
and the rejection region
is |rs| > rcritical (taken from
the Spearman rank
correlation table).
55
Spearman Rank Correlation Coefficient,
Example
Employee
1
2
3
4
5
.
.
.
Aptitude
test
59
47
58
66
77
.
.
.
Rank(a)
9
3
8
14
20
.
.
.
Performance
rating
3
2
4
3
2
.
.
.
Rank(b)
10.5
3.5
17
10.5
3.5
.
.
.
Ties are broken
by averaging the
ranks.
– 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 a = .05 and n = 20 is .450.
56
Spearman Rank Correlation Coefficient,
Example
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.
57
Spearman Rank Correlation Coefficient,
Example
• Excel Solution (Data Analysis Plus; Xm18-08)
Spearman Rank Correlation
Aptitude and Performance
Spearman Rank Correlation
z Stat
P(Z<=z) one tail
z Critical one tail
P(Z<=z) two tail
z Critical two tail
0.3792
1.65
0.0492
1.6449
0.0984
1.96
> 0.05
58
18.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?
59
Residual Analysis
• Examining the residuals (or standardized
residuals), help detect violations of the required
conditions.
• Example 18.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.
60
Residual Analysis
ObservationPredicted Price Residuals Standard Residuals
1
14736.91
-100.91
-0.33
2
14277.65
-155.65
-0.52
3
14210.66
-194.66
-0.65
4
15143.59
446.41
1.48
5
15091.05
476.95
1.58
For each residual we calculate
the standard deviation as follows:
A Partial list of
Standard residuals
s ri  s e 1  hi w here Standardized residual ‘i’ =
Residual ‘i’
1 ( x i  x)2
hi  
Standard deviation
2
n (n  1)s x
61
Residual Analysis
Standardized residuals
40
30
20
10
0
-2
-1
0
1
2
More
It seems the residual are normally distributed with mean zero
62
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.
+
^y
++
Residual
+ + +
+
+
+
+
+
+
+
+
+
++ +
+
+ +
+
+ +
+ +
+
+ +
+
+
+
The spread increases with ^y
y^
++
+ ++
++
++
+
+
++
+
+
63
Homoscedasticity
• When the requirement of a constant variance is not
violated we have a condition of homoscedasticity.
• Example 18.2 - continued
Residuals
1000
500
0
13500
-500
14000
14500
15000
15500
16000
-1000
Predicted Price
64
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.
65
Non Independence of Error Variables
Patterns in the appearance of the residuals over time indicates
that autocorrelation exists.
Residual
Residual
+ ++
+
0
+
+
+
+
+
+ +
+
+
+
++
+
+
+
Time
Note the runs of positive residuals,
replaced by runs of negative residuals
+
+
+
0 +
+
+
+
Time
+
+
Note the oscillating behavior of the
residuals around zero.
66
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
67
An outlier
+ +
+
+ +
+ +
+ +
An influential observation
+++++++++++
… but, some outliers
may be very influential
+
+
+
+
+
+
+
The outlier causes a shift
in the regression line
68
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.
69