Inference for Simple Linear Regression

Download Report

Transcript Inference for Simple Linear Regression

Lecture Unit 8.1 - 8.3
Inference for Least
Squares Lines
1
The Estimated Coefficients
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
To calculate the estimates of the slope and
intercept of the least squares line , use the
formulas:
b1  r
sy
sx
b0  y  b1 x
r  correlation coefficient
The least squares prediction equation
that estimates the mean value of y for a
particular value of x is:
ŷ  b0  b1 x
n
sy 
2
(
y

y
)
 i
i 1
n 1
n
sx 
2
(
x

x
)
 i
i 1
n 1
2
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
Price
1 37400
14600
2 44800
14100
3 45800
14000
4 30900
15600
5 31700
15600
6 34000
14700
.
.
.
Explanatory
Response
.
.
.
variable
x variable
y
.
.
.
3
The Simple Linear Regression
Line
• Solving by hand: Calculate a number of
statistics
x  36, 011;
sx  6596.125
r  0.80517
y  14,841;
s y  547.74
where n = 100.
b1  r
sy
sx
 0.81517
547.74
 .06769
6596.125
b0  y  b1 x  14,841  (.06769)(36, 011)  17, 286.15
yˆ  b0  b1 x  17, 286.15  .06769 x
4
The Simple Linear Regression Line
Regression Statistics
Multiple R
0.805167979
R Square
0.648295475
Adjusted R
Square
0.644706653
Standard Error
326.4886258
Observations
100
yˆ  17, 248.73  .06686 x
ANOVA
df
Regression
Residual
Total
Intercept
Odometer
SS
19255607.37
10446292.63
29701900
MS
19255607.37
106594.8228
F
180.643
Coefficients
Standard Error
17248.72734
182.0925742
-0.06686089
0.004974639
t Stat
94.72504534
-13.44034928
P-value
3.57E-98
5.75E-24
1
98
99
Significance F
5.75078E-24
Lower 95%
Upper 95%
16887.37056
17610.084
-0.076732895 -0.0569889
5
Interpreting the Least Squares
Line
17248.73
Odometer Line Fit Plot
Price
16000
0
15000
14000
No data 13000
Odometer
yˆ  17, 248.73  .06686 x
The intercept is b0 = $17248.73.
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.0669
6
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.
1. The distribution of the e’s can be
described by a normal model
2. The mean of e is zero: E(e) = 0.
3. The standard deviation of e is se for all
values of x.
4. The errors associated with different
values of y are all independent.
7
The Normality of 
1. The distribution of the e’s can be
described by a normal model
2. The mean of e is zero: E(e) = 0.
3. The standard deviation of e is se for all
values of x.
E(y|x3)
The standard deviation remains constant,
m3
b0 + b1x3
E(y|x2)
b0 + b1x2
but the mean value changes with x
b0 + b1x1
From the first three assumptions
we have:
y is normally distributed with
mean
E(y) = b0 + b1x, and a constant
standard deviation se
m2
E(y|x1)
m1
x1
x2
x3
8
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.
9
Sum of Squares for Errors
SSE
– This is the sum of differences between
the observed y’s and the predicted y’s.
– It can serve as a measure of how well
the line fits the data. SSE is defined by
n
SSE   ( yi  yˆi ) 2 .
i 1
– A shortcut formula
SSE   yi2 b0  yi  b1  xi yi
10
Standard Error of Estimate
– The mean error is equal to zero.
– If the standard deviation e of the
residuals 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 e as a measure of
the suitability of using a linear model.
– An estimator of e is given by se
Standard Error of Estimate
SSE
s 
n2
11
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  10, 446, 293
SSE
10, 446, 293
s 

 326.49
n2
98
12
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.
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
13
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
b1  b1
t
sb1
where
s
sb1 
n  1 sx
The standard error of b1.
– If the error variable is normally
distributed, the statistic is Student t
distribution with d.f. = n-2.
14
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.
15
Testing the Slope, Example
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 )
• Solving by hand
H0: b1 = 0
HA: b1  0
• To compute “t” we need the values of b1 and sb1.
b1  .06686
sb1 
s
326.49

 .004975
n  1 sx
99 6596.125
b1  b1 .06686  0
t

 13.44
.
004975
sb1
• P-value = 2P(t98 > |-13.44|) ~ 0
16
Testing the Slope (Example)
• Using the computer
Odometer Price
37400
44800
45800
30900
45900
19100
40100
40200
14600
14100
Regression Statistics
14000 Multiple R
0.805167979
15600 R Square
0.648295475
Adjusted R
15600 Square
0.644706653
Standard
14700 Error
326.4886258
Observation
14500 s
100
15700
15100 ANOVA
14800
df
32400
43500
32700
34500
15200 Regression
14700 Residual
15600 Total
15600
37700
41400
24500
35800
48600
24200
14600
14600 Intercept
15700 Odometer
15000
14700
15400
31700
34000
1
98
99
H0: b1 = 0
HA: b1  0
Reject H0:b1=0. There is strong
evidence to infer that the odometer
reading affects the auction selling price.
SS
MS
F
19255607.37
10446292.63
29701900
19255607.4
106594.823
180.643
Coefficients
Standard Error
17248.72734
182.0925742
-0.066860885
0.004974639
t Stat
94.7250453
-13.4403493
P-value
3.57E-98
5.75E-24
Significance F
5.75078E-24
Lower 95%
Upper 95%
16887.37056 17610.08
-0.076732895 -0.05699
17
Confidence Interval for the
the Slope, Example
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 )
Confidence interval for the slope
b1  tn 2 sb1
95% confidence interval for b1
b1  .06686,
*
*
t100

t
2
98  1.9845
s
326.49
sb1 

 .004975
n  1 sx
99 6596.125
confidence interval:
.06686  1.9845(.004975)  .06686  .00987
 (.07673,  .05699)
18
Confidence Interval for the
Slope (Example)
• Using the computer
Odometer Price
37400
44800
45800
30900
45900
19100
40100
40200
14600
14100
Regression Statistics
14000 Multiple R
0.805167979
15600 R Square
0.648295475
Adjusted R
15600 Square
0.644706653
Standard
14700 Error
326.4886258
Observation
14500 s
100
15700
15100 ANOVA
14800
df
32400
43500
32700
34500
15200 Regression
14700 Residual
15600 Total
15600
37700
41400
24500
35800
48600
24200
14600
14600 Intercept
15700 Odometer
15000
14700
15400
31700
34000
1
98
99
95% confidence interval for the slope b1
SS
MS
F
19255607.37
10446292.63
29701900
19255607.4
106594.823
180.643
Coefficients
Standard Error
17248.72734
182.0925742
-0.066860885
0.004974639
t Stat
94.7250453
-13.4403493
P-value
3.57E-98
5.75E-24
Significance F
5.75078E-24
Lower 95%
Upper 95%
16887.37056 17610.08
-0.076732895 -0.05699
19
Coefficient of determination
Case I:
Case II:
ignore x: use y to predict y
n
errors:  (obs.  pred.) 2
i 1
n
  ( yi  y )
i 1
 TSS
use x: use yˆ  b0
 b1 x
n
errors:  (obs.  pred.) 2
i 1
n
2
2
ˆ
=  ( yi  yi )
i 1
 SSE
Reduction in prediction error when use x:
TSS-SSE = SSR
20
Coefficient of determination
Reduction in prediction error when use
x:TSS-SSE = SSR or TSS = SSR + SSE
The regression model
SSR
Overall variability in y
TSS
The error
SSE
Proportional reduction in prediction error when use x:
TSS  SSE
SSE
 1

TSS
TSS
2


(
x

x
)(
y

y
)
i
 i

  r 2
algebra =  i 1
 
2 2
sx s y
21
n
Coefficient of determination:
graphically
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
(TSS)
Variation explained by
the regression line
(ŷ1  y) 2  (ŷ 2  y) 2
x2
+ Unexplained variation (error)
 (y1  ŷ1 ) 2  (y 2  ŷ 2 ) 2
22
Coefficient of determination
• R2 (=r2 ) measures the proportion of
the variation in y that is explained by
the variation in x.
SSE TSS  SSE SSR
R  1


TSS
TSS
TSS
2
• r2 takes on any value between zero and one
since the correlation r satisfies -1r1).
r2 = 1: Perfect match between the line and the
data points.
r2 = 0: There are no linear relationship between
23
x and y.
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  (.80517) 2  .6483
24
Coefficient of Determination
– Using the computer
From the regression output we have
64.8% of the variation in the auction
selling price is explained by the
variation in odometer reading. The
rest (35.2%) remains unexplained by
this model.
Regression Statistics
Multiple R
0.805167979
R Square
0.648295475
Adjusted R
Square
0.644706653
Standard Error 326.4886258
Observations
100
ANOVA
df
Regression
Residual
Total
Intercept
Odometer
1
98
99
SS
19255607.37
10446292.63
29701900
MS
19255607.37
106594.8228
F
Significance F
180.643
5.75078E-24
Coefficients Standard Error
t Stat
P-value
17248.72734
182.0925742 94.72504534 3.57E-98
-0.06686089
0.004974639 -13.44034928 5.75E-24
25
Using the Regression Equation
• We can use the least squares line to
predict the values of y.
• To make a prediction we use
– Point prediction, and
– Interval prediction
26
Point Prediction
• Example
– Predict the selling price of a three-yearold Taurus with 40,000 miles on the
odometer.
A point prediction
yˆ  17248.73  .06686 x  17248.73  .066686(40, 000)  14,574
– It is predicted that a 40,000 miles car
would sell for $14,574.
– How close is this prediction to the real
price?
27
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 (price
prediction for a specific car with 40,000 miles on odometer)
– Confidence interval – estimates the average y for a given x
(estimate the average price of all cars with 40,000 miles on
odometer).
– The prediction interval
yˆ  t
2
s
sb21 ( x  x ) 2    s2
n
2
– The confidence interval
yˆ  t
2
2
s
sb21 ( x  x ) 2  
n
28
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
29
Interval Estimates,
Example
• Solution
– A 95% prediction interval provides the
price estimate for a single car:
yˆ  t
t.025,98
2
2
s
sb21 ( x  x ) 2    s2
n
326.492
14,574  1.9845 (.004975)  (40, 000  36, 011) 
 326.492  14,574  652
100
2
2
30
Interval Estimates,
Example
• Solution – continued
– A 95% confidence interval provides the
estimate of the mean price per car for
all Ford Taurus’s with 40,000 miles on
the odometer.
• The confidence interval (95%) =
yˆ  t
2
2
s
sb21 ( x  x ) 2  
n
326.492
14,574  1.9845 (.004975)  (40, 000  36, 011) 
 14,574  76
100
31
2
2
The effect of the given x on
the length of the interval
– As x moves away from x the interval
becomes longer. That is, the shortest
interval is found at x.
ŷ  b0  b1 x
yˆ  t
s2
SE (b1 )  ( x  x ) 
n
2
2
2
x
32
The effect of the given x on
the length of the interval
–– As
moves
away
x the becomes
interval
As xx moves
away
fromfrom
x the interval
becomes
That interval
is, theisshortest
longer. Thatlonger.
is, the shortest
found at x.
interval is found at x.
ŷ  b0  b1 x
yˆ ( x  x  1)
yˆ ( x  x  1)
yˆ  t
s2
SE (b1 )  ( x  x ) 
n
2
2
yˆ  t
2
s2
SE (b1 )(1) 
n
2
2
2
x 1 x 1
x
( x  1)  x  1 ( x  1)  x  1
33
The effect of the given x on the
length of the interval
–– As
from
x the
interval
As xxmoves
awayaway
from x the
interval
becomes
longer. That
 moves
is, the shortestlonger.
interval is That
found atis,
x. the shortest
becomes
interval is found at x.
ŷ  b0  b1 x
yˆ  t
s2
SE (b1 )  ( x  x ) 
n
2
2
ˆ  t
y
x 2
x
x2
( x  2)  x  2 ( x  2)  x  2
ˆ  t
y
2
2
2
s
SE 2 (b1 )(1) 2  
n
s2
SE (b1 )(2) 
n
2
2
2
34
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?
35
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.
36
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:
sri  s 1  hi where
1 ( xi  x ) 2
hi  
n (n  1) sx2
A Partial list of
Standard residuals
Standardized residual ‘i’ =
Residual ‘i’
Standard deviation
37
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
38
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^
++
+ ++
++
++
+
+
++
+
+
39
Homoscedasticity
• When the requirement of a constant
variance is not violated we have a condition
of homoscedasticity.
• Example - continued
Residuals
1000
500
0
13500
-500
14000
14500
15000
15500
16000
-1000
Predicted Price
40
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.
41
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.
42
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
43
An outlier
An influential observation
+ +
+
+ +
+ +
+ +
+++++++++++
… but, some outliers
may be very influential
+
+
+
+
+
+
+
The outlier causes a shift
in the regression line
44
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.
45