1 simple linear regression and correlation chapter 17

50
1 Simple Linear Simple Linear Regression Regression and Correlation and Correlation Chapter 17

Post on 21-Dec-2015

272 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Simple Linear Regression and Correlation Chapter 17

1

Simple Linear Regression Simple Linear Regression and Correlationand Correlation

Chapter 17

Page 2: 1 Simple Linear Regression and Correlation Chapter 17

2

17.1 Introduction

• In this chapter we employ Regression Analysisto examine the relationship among quantitative variables.

• The technique is used to predict the value of one variable (the dependent variable - y)based on the value of other variables (independent variables x1, x2,…xk.)

Page 3: 1 Simple Linear Regression and Correlation Chapter 17

3

17.2 The Model

• The first order linear model

y = dependent variablex = independent variable0 = y-intercept

1 = slope of the line

= error variable

xy 10 xy 10

x

y

0 Run

Rise = Rise/Run

0 and 1 are unknown,therefore, are estimated from the data.

Page 4: 1 Simple Linear Regression and Correlation Chapter 17

4

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.

The question is:Which straight line fits best?

x

y

Page 5: 1 Simple Linear Regression and Correlation Chapter 17

53

3

The best line is the one that minimizes the sum of squared vertical differences between the points and the line.

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.

Page 6: 1 Simple Linear Regression and Correlation Chapter 17

6

To calculate the estimates of the coefficientsthat 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

Page 7: 1 Simple Linear Regression and Correlation Chapter 17

7

• Example 17.1 Relationship between odometer reading and a used car’s selling price.

– 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 53182 44758 50613 45833 50084 30862 57955 31705 57846 34010 5359

. . .

. . .

. . .

Independent variable x

Dependent variable y

Page 8: 1 Simple Linear Regression and Correlation Chapter 17

8

• Solution– Solving by hand

• To calculate b0 and b1 we need to calculate several statistics first;

;41.411,5y

;45.009,36x

256,356,11n

)yy)(xx()Y,Xcov(

688,528,431n

)xx(s

ii

2i2

x

where n = 100.

533,6)45.009,36)(0312.(41.5411xbyb

0312.688,528,43256,356,1

s

)Y,Xcov(b

10

2x

1

x0312.533,6xbby 10

Page 9: 1 Simple Linear Regression and Correlation Chapter 17

9

4500

5000

5500

6000

19000 29000 39000 49000

OdometerPrice

– Using the computer (see file Xm17-01.xls)

SUMMARY OUTPUT

Regression StatisticsMultiple R 0.806308R Square 0.650132Adjusted R Square0.646562Standard Error151.5688Observations 100

ANOVAdf SS MS F Significance F

Regression 1 4183528 4183528 182.1056 4.4435E-24Residual 98 2251362 22973.09Total 99 6434890

CoefficientsStandard Error t Stat P-valueIntercept 6533.383 84.51232 77.30687 1.22E-89Odometer -0.03116 0.002309 -13.4947 4.44E-24

x0312.533,6y

Tools > Data analysis > Regression > [Shade the y range and the x range] > OK

Page 10: 1 Simple Linear Regression and Correlation Chapter 17

10

This is the slope of the line.For each additional mile on the odometer,the price decreases by an average of $0.0312

4500

5000

5500

6000

19000 29000 39000 49000

Odometer

Price

x0312.533,6y

The intercept is b0 = 6533.

6533

0 No data

Do not interpret the intercept as the “Price of cars that have not been driven”

Page 11: 1 Simple Linear Regression and Correlation Chapter 17

11

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.

Page 12: 1 Simple Linear Regression and Correlation Chapter 17

12

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

Page 13: 1 Simple Linear Regression and Correlation Chapter 17

13

17.5 Assessing the Model

• The least squares method will produce a regression line whether or not there is a 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:– Testing and/or estimating the coefficients.– Using descriptive measurements.

Page 14: 1 Simple Linear Regression and Correlation Chapter 17

14

– 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.

– This statistic plays a role in every statistical technique we employ to assess the model.

2x

2Y

s

)Y,Xcov(s)1n(SSE

2x

2Y

s

)Y,Xcov(s)1n(SSE

.)yy(SSEn

1i

2ii

• Sum of squares for errors

Page 15: 1 Simple Linear Regression and Correlation Chapter 17

15

– 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 unbiased estimator of

2 is given by s2

2nSSE

s

EstimateofErrordardtanS

2nSSE

s

EstimateofErrordardtanS

• Standard error of estimate

Page 16: 1 Simple Linear Regression and Correlation Chapter 17

16

• Example 17.2– Calculate the standard error of estimate for example

17.1, and describe what does it tell you about the model fit?

• Solution

6.15198

363,251,22n

SSEs

,Thus

363,252,2688,528,43

)256,356,1()999,64(99

s

)Y,Xcov(s)1n(SSE

999,6499

890,434,61n

)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.

4.411,5y,6.151s

Page 17: 1 Simple Linear Regression and Correlation Chapter 17

17

• Testing the slope– When no linear relationship exists between two

variables, the regression line should be horizontal.

Linear relationship.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

Page 18: 1 Simple Linear Regression and Correlation Chapter 17

18

• We can draw inference about 1 from b1 by testingH0: 1 = 0

H1: 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

Page 19: 1 Simple Linear Regression and Correlation Chapter 17

19

• Solution– Solving by hand– To compute “t” we need the values of b1 and sb1.

49.1300231.

0312.s

bt

00231.688,528,43)(99(

6.151

s)1n(

ss

312.b

1

1

b

11

2x

b

1

– Using the computerCoefficients Standard Error t Stat P-value

Intercept 6533.383035 84.51232199 77.30687 1.22E-89Odometer -0.031157739 0.002308896 -13.4947 4.44E-24

There is overwhelming evidence to inferthat the odometer reading affects the auction selling price.

Page 20: 1 Simple Linear Regression and Correlation Chapter 17

20

• Coefficient of determination

– When we want to measure the strength of the linear relationship, we use the coefficient of determination.

22

22

22

)(1

)],[cov(

yy

SSERor

ss

YXR

iyx

22

22

22

)(1

)],[cov(

yy

SSERor

ss

YXR

iyx

Page 21: 1 Simple Linear Regression and Correlation Chapter 17

21

– To understand the significance of this coefficient note:

Overall variability in y

The regression model

Remains, in part, unexplained The error

Explained in part by

Page 22: 1 Simple Linear Regression and Correlation Chapter 17

22

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)

Page 23: 1 Simple Linear Regression and Correlation Chapter 17

23

• 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

Variation in y = SSR + SSE

• 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.

Page 24: 1 Simple Linear Regression and Correlation Chapter 17

24

Regression StatisticsMultiple R 0.8063R Square 0.6501

Adjusted R Square 0.6466Standard Error 151.57Observations 100

• Example 17.4– Find the coefficient of determination for example 17.1;

what does this statistic tell you about the model?• Solution

– Solving by hand;– Using the computer

• From the regression output we have

6501.ss

)]Y,X[cov(R )999,64)(688,528,43(

]256,356,1[2y

2x

22 2

65% of the variation in the auctionselling price is explained by the variation in odometer reading. Therest (35%) remains unexplained bythis model.

Page 25: 1 Simple Linear Regression and Correlation Chapter 17

25

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.

Page 26: 1 Simple Linear Regression and Correlation Chapter 17

26

• Example 17.5 The market modelSUMMARY OUTPUT

Regression StatisticsMultiple R 0.560079R Square 0.313688Adjusted R Square0.301855Standard Error0.063123Observations 60

ANOVAdf SS MS F Significance F

Regression 1 0.10563 0.10563 26.50969 3.27E-06Residual 58 0.231105 0.003985Total 59 0.336734

CoefficientsStandard Error t Stat P-valueIntercept 0.012818 0.008223 1.558903 0.12446TSE 0.887691 0.172409 5.148756 3.27E-06

• Estimate the market model for Nortel, a stock traded in the Toronto Stock Exchange.

• Data consisted of monthly percentage return for Nortel and monthly percentage returnfor 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 risk embeddedin the Nortel stock, that is market-related.Specifically, 31.37% of the variation in Nortel’sreturn are explained by the variation in the TSE’s returns.

Page 27: 1 Simple Linear Regression and Correlation Chapter 17

27

17.7 Using the Regression Equation

• If we are satisfied with how well the model fits the data, we can use it to make predictions for y.

• Illustration– Predict the selling price of a three-year-old Taurus

with 40,000 miles on the odometer (Example 17.1).285,5)000,40(0312.6533x0312.6533y

• 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 make predictions for y.

• Illustration– Predict the selling price of a three-year-old Taurus

with 40,000 miles on the odometer (Example 17.1).

Page 28: 1 Simple Linear Regression and Correlation Chapter 17

28

• Prediction interval and confidence interval

– Two intervals can be used to discover how closely the predicted value will match the true value of y.

• Prediction interval - for a particular value of y,• Confidence interval - for the expected value of y.

– The confidence interval– The confidence interval

2

i

2g

2)xx(

)xx(

n1

sty

2

i

2g

2)xx(

)xx(

n1

sty

– The prediction interval– The prediction interval

2

i

2g

2)xx(

)xx(

n1

1sty

2

i

2g

2)xx(

)xx(

n1

1sty

The prediction interval is wider than the confidence interval

Page 29: 1 Simple Linear Regression and Correlation Chapter 17

29

• Example 17.6 interval estimates for the car auction price

– Provide an interval estimate for the bidding price on a Ford Taurus with 40,000 miles on the odometer.

– Solution• The dealer would like to predict the price of a single car

• The prediction interval(95%) =

2

i

2g

2)xx(

)xx(

n1

1sty

303285,5160,340,309,4

)009,36000,40(100

11)6.151(984.1)]40000(0312.6533[

2

t.025,98

Page 30: 1 Simple Linear Regression and Correlation Chapter 17

30

– The car dealer wants to bid on a lot of 250 Ford Tauruses, where each car has been driven for about 40,000 miles.

– Solution• The dealer needs to estimate the mean price per car.

• The confidence interval (95%) =

2

i

2g

2)xx(

)xx(

n1

sty

35285,5160,340,309,4

)009,36000,40(100

1)6.151(984.1)]40000(0312.6533[

2

Page 31: 1 Simple Linear Regression and Correlation Chapter 17

31

2

i

2g

2)xx(

)xx(

n1

sty

x 2

i

2

2)xx(

2n1

sty

2

i

2

2)xx(

1n1

sty

• The effect of the given value of x on the interval – As xg moves away from x the interval becomes longer. That is, the shortest

interval is found at x.

2x 2x

1x)1x( 1x)1x(

g10 xbby

)1xx(y g )1xx(y g

2x)2x( 2x)2x(

1x 1x

The confidence intervalwhen xg = x

The confidence intervalwhen xg = 1x

The confidence intervalwhen xg = 2x

Page 32: 1 Simple Linear Regression and Correlation Chapter 17

32

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.

Page 33: 1 Simple Linear Regression and Correlation Chapter 17

33

• Testing the coefficient of correlation– When there are no linear relationship between two

variables, = 0.– The hypotheses are:

H0: = 0H1: = 0

– The test statistic is:

yx

2

ss)Y,Xcov(

rbycalculated

ncorrelatiooftcoefficiensampletheisrwherer1

2nrt

The statistic is Student t distributedwith d.f. = n - 2, provided the variables are bivariate normally distributed.

X

Y

Page 34: 1 Simple Linear Regression and Correlation Chapter 17

34

• Example 17.7 Testing for linear relationship

– Test the coefficient of correlation to determine if linear relationship exists in the data of example 17.1.

• Solution– We test H0: = 0

H1: 0.

– Solving by hand: • The rejection region is

|t| > t/2,n-2 = t.025,98 = 1.984 or so.• The sample coefficient of

correlation r=cov(X,Y)/sxsy=-.806

The value of the t statistic is

Conclusion: There is sufficientevidence at = 5% to infer thatthere are linear relationshipbetween the two variables.

49.13r1

2nrt

2

Page 35: 1 Simple Linear Regression and Correlation Chapter 17

35

• Spearman rank correlation coefficient

– The Spearman rank test is used to test whether relationship exists between variables in cases where

• at least one variable is ranked, or• both variables are quantitative but the normality

requirement is not satisfied

Page 36: 1 Simple Linear Regression and Correlation Chapter 17

36

– The hypotheses are:• H0: s = 0

• H1: s = 0

– The test statistic is

a and b are the ranks of the data. – For a large sample (n > 30) rs is approximately

normally distributed

bas ss

)b,acov(r

1nrz s

Page 37: 1 Simple Linear Regression and Correlation Chapter 17

37

• Example 17.8

– 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.

Page 38: 1 Simple Linear Regression and Correlation Chapter 17

38

Aptitude Performance Employee test rating

1 59 32 47 23 58 44 66 35 77 2. . .. . .. . .

• Solution– The problem objective is

to analyze the relationship between two variables.

– Performance rating is ranked.

– 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).

Scores range from 0 to 100 Scores range from 1 to 5

Page 39: 1 Simple Linear Regression and Correlation Chapter 17

39

Aptitude Performance Employee test rating

1 59 32 47 23 58 44 66 35 77 2. . .. . .. . .

Rank(a)938

1420...

Rank(b)10.53.517

10.53.5

.

.

.

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.

Conclusion: Do not reject the null hypothesis. At 5% significance level there is insufficient evidence to infer that the two variable are related to one another.

Page 40: 1 Simple Linear Regression and Correlation Chapter 17

40

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?

Page 41: 1 Simple Linear Regression and Correlation Chapter 17

41

• Residual Analysis

– Examining the residuals (or standardized residuals), we can identify violations of the required conditions

– Example 17.1 - continued• Nonnormality.

– Use Excel to obtain the standardized residual histogram.– Examine the histogram and look for a bell shaped diagram with

mean close to zero.

Page 42: 1 Simple Linear Regression and Correlation Chapter 17

42

For each residual we calculate the standard deviation as follows:

2j

2i

i

ir

)xx(

)xx(n1

h

whereh1ssi

RESIDUAL OUTPUT

Observation Residuals Standard Residuals1 -50.45749927 -0.3345958952 -77.82496482 -0.5160761863 -97.33039568 -0.6454214214 223.2070978 1.4801403125 238.4730715 1.58137268

0

10

20

30

40

-2.5 -1.5 -0.5 0.5 1.5 2.5 More

A Partial list ofStandard residuals

Standardized residual i =Residual i / Standard deviation

We can also apply the Lilliefors testor the 2 test of normality.

Page 43: 1 Simple Linear Regression and Correlation Chapter 17

43

• Heteroscedasticity

– When the requirement of a constant variance is violated we have heteroscedasticity.

+ + ++

+ ++

++

+

+

+

+

+

+

+

+

+

+

++

+

+

+

The spread increases with y

y

Residualy

+

+++

+

++

+

++

+

+++

+

+

+

+

+

++

+

+

Page 44: 1 Simple Linear Regression and Correlation Chapter 17

44

+

+

+

+

++

+

++

+

+

+

+

+

+

+

+

+

+

++

+

+

+

y

Residualy

+

+++

+

++

+

++

+

+++

+

+

+

+

+

++

+

+

+

+++

+

+++

+++

+

++

+

+

++

+

++

The spread of the data pointsdoes not change much.

• When the requirement of a constant variance is not violated we have homoscedasticity.

Page 45: 1 Simple Linear Regression and Correlation Chapter 17

45

+

+

+

+

++

+

++

+

+

+

+

+

+

+

+

+

+

++

+

+

+

y

Residualy

+

++

+

+++

+

+

+

+

+

++

+

++

+

+

+

++

+

++

+

++

++

+

+

+

+

++

+

++

As far as the even spread, this isa much better situation

• When the requirement of a constant variance is not violated we have homoscedasticity.

Page 46: 1 Simple Linear Regression and Correlation Chapter 17

46

• Nonindependence 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.

Page 47: 1 Simple Linear Regression and Correlation Chapter 17

47

+

+++ +

++

++

+ +

++ + +

+

++ +

+

+

+

+

+

+Time

Residual Residual

Time+

+

+

Patterns in the appearance of the residuals over time indicates that autocorrelation exists.

Note the runs of positive residuals,replaced by runs of negative residuals

Note the oscillating behavior of the residuals around zero.

0 0

Page 48: 1 Simple Linear Regression and Correlation Chapter 17

48

• 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

Page 49: 1 Simple Linear Regression and Correlation Chapter 17

49

+

+

+

+

+ +

+ + ++

+

+

+

+

+

+

+

The outlier causes a shift in the regression line

… but, some outliers may be very influential

++++++++++

An outlier An influential observation

Page 50: 1 Simple Linear Regression and Correlation Chapter 17

50

• 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.– Check the required conditions for the errors.– Assess the model fit.– If the model fits the data, use the regression

equation.