1 least squares procedure inference for least squares lines simple linear regression

35
1 Least squares Least squares procedure procedure Inference for least Inference for least squares lines squares lines Simple Linear Simple Linear Regression Regression

Upload: hannah-sparks

Post on 28-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

1

Least squares procedureLeast squares procedureInference for least squares lines Inference for least squares lines

Simple Linear RegressionSimple Linear Regression

Page 2: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

2

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 (x1, x2,…xk.).– Analyze the specific relationships between the

independent variables and the dependent variable.

Page 3: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

3

House size

HouseCost

Most lots sell for $25,000

Building a house costs about

$75 per square foot.

House cost = 25000 + 75(Size)

The Model (Example)

The model has a deterministic and a probabilistic components

Page 4: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

4

House cost = 25000 + 75(Size)

House size

HouseCost

Most lots sell for $25,000

However, house cost vary even among same size houses!

The Model

Since cost behave unpredictably, we add a random component.

Page 5: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

5

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.

Page 6: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

6

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

Page 7: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

7

The Least Squares (Regression) Line

A good line is one that minimizes the sum of squared differences between the points and the line.

Page 8: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

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.

Page 9: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

9

The Estimated Coefficients

To calculate the estimates of the slope and intercept of the least squares line , use the formulas:

1

0 1

2

2 2( 1)

xy

xx

i i

xy i i

i

xx i x

SSb

SS

b y b x

x ySS x y

n

xSS x n s

n

1

0 1

2

2 2( 1)

xy

xx

i i

xy i i

i

xx i x

SSb

SS

b y b x

x ySS x y

n

xSS x n s

n

The regression equation that estimatesthe equation of the first order linear modelis:

0 1y b b x 0 1y b b x

1y

x

sb r

s

1y

x

sb r

s

Alternate formula for the slope b1

Page 10: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

10

• 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 Price1 37388 146362 44758 141223 45833 140164 30862 155905 31705 155686 34010 14718

. . .

. . .

. . .

Independent variable x

Dependent variable y

The Simple Linear Regression Line

Page 11: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

11

The Simple Linear Regression Line

• Solution– Solving by hand: Calculate a number of statistics

;823.822,14y

;45.009,36x

22 43,528,690

( ) 2,712,511

i

xx i

i ixy i i

xSS x

n

x ySS x y

n

where n = 100.

1 2

0 1

2,712,511.06232

( 1) 43,528,690

14,822.82 ( .06232)(36,009.45) 17,067

xy

x

SSb

n s

b y b x

x0623.067,17xbby 10

Page 12: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

12

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 Line

Page 13: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

13

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

Page 14: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

14

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 15: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

15

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

Page 16: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

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.

Page 17: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

17

– 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

20 1i i i iSSE y b y b x y 20 1i i i iSSE y b y b x y

– A shortcut formula

Page 18: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

18

– 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

Page 19: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

19

• Example:– Calculate the standard error of estimate for the previous

example and describe what it tells you about the model fit.• Solution

9,005,450

9,005,450303.13

2 98

SSE

SSEs

n

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

Page 20: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

“p-values” and Significance Levels

Each independent variable has “p-value” or significance level.

The p-value tells how likely it is that the coefficient for that independent variable emerged by chance and does not

describe a real relationship.

A p-value of .05 means that there is a 5% chance that the relationship emerged randomly and a 95% chance that the

relationship is real.It is generally accepted practice to consider variables with a p-value of less than .1 as significant, though the only basis

for this cutoff is convention20

Page 21: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

21

• 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

Using the Regression Equation

• Before using the regression model, we need to assess how well it fits the data.

Page 22: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

22

Point Prediction

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

with 40,000 miles on the odometer.

– 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

Page 23: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

23

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 interval2

2 2

( )1ˆ

( )

g

i

x xy t s

n x x

2

2 2

( )1ˆ

( )

g

i

x xy t s

n x x

– The prediction interval– The prediction interval2

2 2

( )1ˆ 1

( )

g

i

x xy t s

n x x

2

2 2

( )1ˆ 1

( )

g

i

x xy t s

n x x

Page 24: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

24

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

Page 25: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

25

Interval Estimates,Example

• Solution– A prediction interval provides the price estimate for a

single car: 2

2 2

( )1ˆ 1

( )

g

i

x xy t s

n x x

21 (40,000 36,009)[17,067 .0623(40000)] 1.984(303.1) 1 14,575 605

100 4,309,340,310

t.025,98

Approximately

Page 26: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

26

• 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

21 (40,000 36,009)[17,067 .0623(40000)] 1.984(303.1) 14,575 70

100 4,309,340,310

Interval Estimates,Example

Page 27: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

27

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.

Page 28: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

28

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

Page 29: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

29

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

+

+++

+

++

+

++

+

+++

+

+

+

+

+

++

+

+

Page 30: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

30

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

condition of homoscedasticity.• Example - continued

-1000

-500

0

500

1000

13500 14000 14500 15000 15500 16000

Predicted Price

Re

sid

ua

ls

Page 31: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

31

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.

Page 32: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

32

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

Page 33: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

33

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 34: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

34

+

+

+

+

+ +

+ + ++

+

+

+

+

+

+

+

The outlier causes a shift in the regression line

… but, some outliers may be very influential

++++++++++

An outlier An influential observation

Page 35: 1 Least squares procedure Inference for least squares lines Simple Linear Regression

35

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.