Simple Linear Regression 1. review of least squares procedure

Download Report

Transcript Simple Linear Regression 1. review of least squares procedure

Simple Linear Regression 1. review of least squares procedure 2. inference for least squares lines

1

Introduction

• We will examine the relationship between quantitative variables x and y via a mathematical equation.

• The motivation for using the technique: – Forecast the value of a dependent variable (y) from the value of independent variables (x 1 , x 2 ,…x k .).

– Analyze the specific relationships between the independent variables and the dependent variable.

2

The Model

The model has a deterministic and a probabilistic components House Cost Most lots sell for $25,000 House size 3

The Model

However, house cost vary even among same size houses!

House Cost Since cost behave unpredictably, we add a random component. Most lots sell for $25,000 House size 4

The Model

• The first order linear model y  b 0  b 1 x  e y = dependent variable x = independent variable b 0 = y-intercept b 1 = slope of the line e = error variable y b 0 b 0 and b 1 are unknown population parameters, therefore are estimated from the data.

Run Rise b 1 = Rise/Run x 5

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 w w w w Question: What should be considered a good line?

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

4 3 2.5

2

Sum of squared differences = (2 - 1) 2 + (4 - 2) 2 +(1.5 - 3) 2 Sum of squared differences = (2 -2.5) 2

(2,4) w

+ (3.2 - 4) 2 + (4 - 2.5) 2 + (1.5 - 2.5) 2 = 6.89

+ (3.2 - 2.5) 2 = 3.99

Let us compare two lines The second line is horizontal 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

Alternate formula for the slope b 1 To calculate the estimates of the slope and intercept of the least squares line , use the formulas:

b

1 

r s y s x b

1 

SS xy SS xx b

0

SS xy SS xx

 

b x

1 

x y i i

x i

2    

x i

  

x i

 2

n

n

y i

 (

n

 1)

s x

2 The regression equation that estimates the equation of the first order linear model is:

y

ˆ   0

b x

1 9

The Simple Linear Regression Line

• Example: – 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

1 37388 2 44758 3 45833 4 30862 5 31705 6 34010 Independent variable x .

Price

14636 14122 14016 15590 15568 14718 Dependent variable y .

10

The Simple Linear Regression Line

• Solution x  36 , 009 .

45 ;

SS xx

 

x i

2   

n x i

 2  43, 528, 690 y  14 , 822 .

823 ;

SS xy

  (

x y i i

) 

n y i

  2, 712, 511

b

1

b

0 where n = 100.

 (

n SS xy

 1)

s x

2

b x

1    2, 712,511   .06232

43,528, 690 yˆ  b 0  b 1 x  17 , 067  .

0623 x 11

The Simple Linear Regression Line

• Solution – continued – Using the computer 1. Scatterplot 2. Trend function 3. Tools > Data Analysis > Regression 12

The Simple Linear Regression Line

SUMMARY OUTPUT

Regression Statistics

Multiple R 0.8063

R Square 0.6501

Standard Error 303.1

Observations 100  17 , 067  .

0623

x

ANOVA Regression Residual Total

df

1 98 99

SS

16734111 9005450 25739561

MS

16734111 91892

F

182.11

Significance F

0.0000

Intercept Odometer 17067 -0.0623

169 0.0046

100.97

-13.49

P-value

0.0000

0.0000

13

17067

Interpreting the Linear Regression Equation

Odometer Line Fit Plot

16000 0 15000 14000 No data 13000

Odometer

 17 , 067  .

0623

x

The intercept is b 0 = $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

Error Variable: Required Conditions

• The error e is a critical part of the regression model.

• Four requirements involving the distribution of e be satisfied.

must – The probability distribution of e – The mean of e is zero: E( e ) = 0.

is normal.

– The standard deviation of e is s e for all values of x.

– The set of errors associated with different values of y are all independent.

15

The Normality of

e b b 0 0 E(y|x 3 ) The standard deviation remains constant, + b 1 x 3 m 3 E(y|x 2 ) + b 1 x 2 m 2 but the mean value changes with x E(y|x 1 ) b 0 + b 1 x 1 m 1 From the first three assumptions we have: y is normally distributed with mean E(y) = b 0 + deviation s e b 1 x 1 x, and a constant standard x 2 x 3 16

Assessing the Model

• The least squares method will produces 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. 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 SSE  i n   1 ( y i – A shortcut formula  yˆ i ) 2 .

SSE

 

y i

2 

b

0 

y i

b

1 

x y i i

18

Standard Error of Estimate

– The mean error is equal to zero.

– If s e 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 s e as a measure of the suitability of using a linear model.

– An estimator of s e is given by s e

S

tan

dard Error of Estimate s

e 

SSE n

 2 19

Standard Error of Estimate, Example

• Example: – Calculate the standard error of estimate for the previous example and describe what it tells you about the model fit.

• Solution

SSE

 9, 005, 450

s

e 

n SSE

 2  9, 005, 450 98  303.13

It is hard to assess the model based on s e 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 q q q q q q q q q Different inputs (x) yield different outputs (y).

The slope is not equal to zero

No linear relationship.

Different inputs (x) yield the same output (y).

The slope is equal to zero 21

Testing the Slope

• We can draw inference about b 1 from b 1 by testing H 0 : b 1 = 0 H 1 : b 1 = 0 (or < 0,or > 0) – The test statistic is t  b 1  s b 1 b 1 where

s b

1 

s

e

SS xx

The standard error of b 1 .

– If the error variable is normally distributed, the statistic is Student t distribution with d.f. = n-2.

22

Testing the Slope, Example

• Example – 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 the previous example . Use a = 5%.

23

Testing the Slope, Example

• Solving by hand – To compute “t” we need the values of b 1 and s b1 .

b

1   .

0623

t s b

1  

b

1 

s b

1 b 1

s

e (

n

 1 )

s

2

x

  

.

.

0623 00462  0  303 .

1 ( 99 )( 43 , 528 , 690 )  13 .

49  .

00462 – The rejection region is t > t .025

Approximately, t .025 = 1.984 or t < -t .025 with n = n-2 = 98.

24

Testing the Slope, Example

• Using the computer Price 14636 Odometer 37388 SUMMARY OUTPUT 14122 14016 15590 15568 14718 14470 15690 15072 44758 45833

Regression Statistics

Multiple R 0.8063

30862 31705 R Square 0.6501

34010 Standard Error 45854 Observations 303.1

100 19057 40149 ANOVA 14802 15190 14660 15612 15610 14634 14632 15740 40237 32359 Regression 43533 Residual 32744 Total 34470 37720 41350 Intercept 24469 Odometer

df SS

99 25739561

MS

1 16734111 16734111 98 9005450 91892 17067 -0.0623

169 0.0046

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

100.97

-13.49

F

182.11

Significance F

0.0000

P-value

0.0000

0.0000

25

Coefficient of determination

– To measure the strength of the linear relationship we use the coefficient of determination.

R

2   (

x i

 2 2

s s x y i

y

2

or R

2

SSE

 (

y i

y

) 2 Note that the coefficient of determination is r 2 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

y 2 Two data points (x 1 ,y 1 ) and (x 2 ,y 2 ) of a certain sample are shown.

y y 1 Variation in y = SSR + SSE x 1

Total variation in y =

( y 1  y ) 2  ( y 2  y ) 2  Variation explained by the regression line ( yˆ 1  y ) 2  ( yˆ 2  y ) 2 x 2 + Unexplained variation (error)  ( y 1  yˆ 1 ) 2  ( y 2  yˆ 2 ) 2 28

Coefficient of determination

• R 2 measures the proportion of the variation in y that is explained by the variation in x.

R 2  1   ( SSE y i  y ) 2   ( y  i  ( y y ) i  2  SSE y ) 2   ( SSR y i  y ) 2 • R 2 takes on any value between zero and one.

R 2 = 1: Perfect match between the line and the data points.

R 2 = 0: There are no linear relationship between x and y.

29

Coefficient of determination, Example

• Example – Find the coefficient of determination for the used car price –odometer example.what does this statistic tell you about the model?

• Solution – Solving by hand;

R

2   (

x i

x

)(

y i

2 2

s s x y

y

2   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

Standard Error Observations 303.1

100 ANOVA Regression Residual Total

df

1 98 99

SS

16734111 9005450 25739561

MS

16734111 91892 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.

F

182.11

Significance F

0.0000

Intercept Odometer

CoefficientsStandard Error

17067 -0.0623

169 0.0046

t Stat

100.97

-13.49

P-value

0.0000

0.0000

31

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 32

Point Prediction

• Example – Predict the selling price of a three-year-old Taurus with 40,000 miles on the odometer. yˆ

A point prediction

 17067  .

0623 x  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? 33

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 

t

a 2

s

e 1

n

( 

x g

(

x i

 

x x

) 2 ) 2 – The confidence interval 

t

a 2

s

e 1

n

  (

x g

(

x i

 

x x

) 2 ) 2 34

Interval Estimates, Example

• Example - 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 35

Interval Estimates, Example

• Solution – A prediction interval provides the price estimate for a single car: 

t

a 2

s

e t .025,98 Approximately 1

n

( 

x g

(

x i

 

x x

) 2 ) 2  1 100  4,309,340,310 2  36

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 s e 1 n  (  g x ( x  i x ) 2  x ) 2 1 100  4,309,340,310 2  37

The effect of the given x

g

length of the interval on the

– As x g moves away from x the interval becomes longer. That is, the shortest interval is found at x.

yˆ  b 0  b 1 x g yˆ  t a 2 s e 1 n  ( x g ( n  x )  1 ) s 2 x 2 x 38

The effect of the given x

g

length of the interval on the

– As x g moves away from x the interval becomes longer. That is, the shortest interval is found at x.

yˆ  b 0  b 1 x g yˆ ( x yˆ ( x g g   x x   1 ) 1 ) yˆ  t a 2 s e 1 n  ( x g ( n  x )  1 ) s 2 x 2 yˆ  t a 2 s e 1 n  1 2 ( n  1 ) s 2 x ( x  1 )  x   1 x  ( x 1  x 1 ) x   x 1  1 39

The effect of the given x

g

length of the interval on the

– As x g moves away from x the interval becomes longer. That is, the shortest interval is found at x.

yˆ  b 0  b 1 x g yˆ  t a 2 s e 1  n ( x g  x ) ( n  1 ) s 2 x 2 yˆ  t a 2 s e 1  n 1 2 ( n  1 ) s 2 x x  2 ( x  2 )  x   2 ( x  x 2 )  x x  2  2 yˆ  t a 2 s e 1  n 2 2 ( n  1 ) s 2 x 40

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?

41

Residual Analysis

• Examining the residuals (or standardized residuals), help detect violations of the required conditions.

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

42

Residual Analysis

ObservationPredicted Price Residuals Standard Residuals

1 14736.91

-100.91

-0.33

2 3 4 5 14277.65

14210.66

15143.59

15091.05

-155.65

-194.66

446.41

476.95

-0.52

-0.65

1.48

1.58

For each residual we calculate the standard deviation as follows: A Partial list of Standard residuals s h i r i   1 n s e  ( ( 1  h i x i n   x ) where 1 ) s 2 x 2 Standardized residual ‘i’ = Residual ‘i’ Standard deviation 43

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 44

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 + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + + + + y^ + + + + + + + The spread increases with y^ 45

Homoscedasticity

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

• Example - continued 1000 500 0 13500 -500 -1000 14000 14500 15000 15500 16000

Predicted Price

46

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.

47

Residual

Non Independence of Error Variables

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

Residual 0

+ +++ + + + + + + + + + + + + + +

Time 0

+ + + + + + + + + +

Time Note the runs of positive residuals, replaced by runs of negative residuals Note the oscillating behavior of the residuals around zero. 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 49

An outlier An influential observation

+ + ++++++++++ + + + + + + + + + + + + + + +

The outlier causes a shift in the regression line … but, some outliers may be very influential 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.

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

51