Simple Linear Regression 1. Review of Least Squares Procedure 2. Inference For Least Squares Lines
Simple Linear Regression 1. Review of Least Squares Procedure 2. Inference For Least Squares Lines
1
Introduction
House
Cost
bout
o s t sa
u s ec ze)
ho o t. S i
in g a r e fo + 75(
d a
Buil er squ 25000
p =
$75 e cost
Most lots sell s
Hou
for $25,000
House size
3
The Model
However, house cost vary even among same size
houses! Since cost behave unpredictably,
House we add a random component.
Cost
4
The Model
• The first order linear model
yy 00 11xx
y = dependent variable 0 and 1 are unknown population
x = independent variable y parameters, therefore are estimated
from the data.
0 = y-intercept
1 = slope of the line
Rise = Rise/Run
= error variable Run
0
x
5
Estimating the Coefficients
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
Let us compare two lines
4 (2,4)
The second line is horizontal
3 (4,3.2)
2.5
2
(1,2)
(3,1.5)
1 The smaller the sum of
squared differences
the better the fit of the
1 2 3 4
line to the data.
8
The Estimated Coefficients
Alternate formula for the slope b1
To calculate the estimates of the slope
and intercept of the least squares line , ssyy
use the formulas: bb11rr s
sxx
SS xy
SS
bb11
xy
SS xx The regression equation that estimates
SS xx
the equation of the first order linear
bb00 yybb11xx model
xx
yy is:
SS xy
SS xxyy
ii ii
ii ii
nn
xy
xx
22 ŷŷ bb00 bb11xx
SS xx
SS 22
xx n ((nn1)1)ss
ii 22
xx ii xx
n
9
The Simple Linear Regression Line
• Example:
– A car dealer wants to find
the relationship between Car Odometer Price
the odometer reading and 1 37388 14636
the selling price of used cars. 2 44758 14122
3 45833 14016
– A random sample of 100 cars 4 30862 15590
is selected, and the data 5 31705 15568
recorded. 6 34010 14718
. .
Independent .
Dependent
– Find the regression line. . .
variable .
x variable y
. . .
10
The Simple Linear Regression Line
• Solution
– Solving by hand: Calculate a number of statistics
x
2
x 36,009.45; SS xx xi
i
2
43, 528, 690
n
y 14,822.823; SS xy ( xi yi )
xi yi
2, 712, 511
n
where n = 100.
SS xy 2, 712,511
b1 .06232
(n 1) sx2 43,528, 690
b0 y b1 x 14,822.82 ( .06232)(36, 009.45) 17, 067
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
Adjusted R Square
0.6466
Standard Error 303.1
Observations 100 yˆ 17,067 .0623x
ANOVA
df SS MS F Significance F
Regression 1 16734111 16734111 182.11 0.0000
Residual 98 9005450 91892
Total 99 25739561
13
Interpreting the Linear Regression
-Equation
17067 Odometer Line Fit Plot
16000
15000
Price
14000
0 No data 13000
Odometer
yˆ 17,067 .0623x
0 + 1x1
From the
From the first
first three
three assumptions
assumptions we we have:
have:
yy isis normally
normally distributed
distributed with
with mean
mean x1 x2 x3
E(y) == 00 ++ 11x,
E(y) x, and
and aa constant
constant standard
standard
deviation
deviation
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
nn
SSE
SSE
( y ŷ 22 .
)
( y i i ŷ i )i .
i i 11
– A shortcut formula
SStan
tandard
dard Error
Error of
of Estimate
Estimate
SSE
SSE
ss
nn22 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
b1111
b ss
tt where ssbb11
ssbb11 SSxxxx
SS
The standard error of b1.
23
Testing the Slope,
Example
• Solving by hand
– To compute “t” we need the values of b1 and sb1.
b1 .0623
s 303.1
sb1 .00462
(n 1) s x2 (99)(43,528,690)
b1 1 .0623 0
t 13.49
sb1 .00462
– The rejection region is t > t.025 or t < -t.025 with = n-2 = 98.
Approximately, t.025 = 1.984
24
Testing the Slope,
Example
• 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
15568 31705 Adjusted R Square
0.6466 There is overwhelming evidence to infer
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.
((xx i
xx )(
)( yy i
yy
22
RR
22 i i
2 22
ssxxssyy
2
2 1
2 SSE
SSE
or R
or R 1
i ((yy i
y
y ))22
26
Coefficient of determination
27
Coefficient of determination
y2
Two data points (x1,y1) and (x2,y2)
of a certain sample are shown.
x1 x2
Total variation in y = Variation explained by the + Unexplained variation (error)
regression line
28
(y1 y)2 (y 2 y)2 ( ŷ 1 y ) 2 ( ŷ 2 y ) 2 ( y 1 ŷ 1 ) 2 ( y 2 ŷ 2 ) 2
Coefficient of determination
2
R 1
SSE
( y i y ) 2 SSE
SSR
(y i y) 2
(y y)
i
2
(y i y) 2
( xi x )( yi y
2
[ 2,712,511]2
R
2
2 2
(43,528,688)(259,996) .6501
sx s y
30
Coefficient of determination
– Using the computer
From the regression output we have
SUMMARY OUTPUT
Regression Statistics
Multiple R 0.8063 65% of the variation in the auction
R Square 0.6501 selling price is explained by the
Adjusted R Square
0.6466
Standard Error 303.1
variation in odometer reading. The
Observations 100 rest (35%) remains unexplained by
this model.
ANOVA
df SS MS F Significance F
Regression 1 16734111 16734111 182.11 0.0000
Residual 98 9005450 91892
Total 99 25739561
32
Point Prediction
• Example
– Predict the selling price of a three-year-old Taurus
with 40,000 miles on the odometer.
A point prediction
ŷ 17067 .0623x 17067 .0623( 40,000) 14,575
–– The
The prediction
prediction interval
interval – The confidence interval
11 xx))22
((xxgg 1 ( xg x ) 2
ˆ tt 22ss 11
yˆy yˆ t 2 s
nn ((xxii
xx))
22
n ( x x )2
i
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:
1 ( xg x ) 2
yˆ t 2 s 1
n ( xi x ) 2
t.025,98
Approximately
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.
1 ( x g x)2
• The confidence interval (95%) = ŷ t 2 s
n
( x i x)2
37
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.
ŷ b 0 b1x g
1 ( x g x)
2
ŷ t 2 s
n (n 1)s 2x
38
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.
ŷ b 0 b1x g
1 ( x g x)
2
ŷ t 2 s
n (n 1)s 2x
ŷ( x g x 1)
ŷ( x g x 1) 1 12
ŷ t 2 s
n (n 1)s 2x
x 1 x 1
x
( x 1) x 1 ( x 1) x 1
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.
ŷ b 0 b1x g
1 ( x g x)
2
ŷ t 2 s
n (n 1) s 2x
1 12
ŷ t 2 s
n (n 1)s 2x
x2 x2 1 22
x ŷ t 2 s
n (n 1)s 2x
( x 2) x 2 ( x 2) x 2
40
Regression Diagnostics - I
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 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
A Partial list of
For each residual we calculate Standard residuals
the standard deviation as follows:
s ri s 1 hi where Standardized residual ‘i’ =
1 ( x i x)2 Residual ‘i’
hi Standard deviation
n (n 1)s x2
43
Residual Analysis
Standardized residuals
40
30
20
10
0
-2 -1 0 1 2 More
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
+ + ++ +
+ + +
+ + ++
+ + ++
1000
500
Residuals
0
13500 14000 14500 15000 15500 16000
-500
-1000
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
Non Independence of Error Variables
Patterns in the appearance of the residuals over time indicates
that autocorrelation exists.
Residual Residual
+
+ ++
+
+ + +
+ + +
0 + 0 + +
+ Time Time
+ + + + + +
+
+
+ ++ +
+
Note the runs of positive residuals, Note the oscillating behavior of the
replaced by runs of negative residuals 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
+++++++++++
+ +
+ … 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