Chapter 27 Inference for Simple Linear Regression

download report

Transcript Chapter 27 Inference for Simple Linear Regression

Chapter 27 Inference for
Simple Linear Regression
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 resposne variable (y) from
the value of explanatory variables (x1, x2,…xk.).
– Analyze the specific relationship between the
explanatory variable and the dependent variable.
2
The Model
The model has a deterministic and a probabilistic component
House
Cost
Most lots sell
for $25,000
House size
3
The Model
However, house costs vary even among same size
houses!
Since cost behave unpredictably,
House
Cost
we add a random component.
Most lots sell
for $25,000
House size
4
The Model
• The first order linear model
y  b0  b1x  e
y = response variable
x = explanatory variable
b0 = y-intercept
b1 = slope of the line
e = error variable
y
b0 and b1 are unknown population
parameters, therefore are estimated
from the data.
Rise
b0
b1 = Rise/Run
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
Question: What should be
considered a good line?
w
w
w
w
w
w
w
w
w
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
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
4
3
2.5
2
Let us compare two lines
The second line is horizontal
(2,4)
w
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
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
n
sy 
The least squares prediction equation
that estimates the mean value of y for a
particular value of x is:
(y
i 1
i
ŷ  b0  b1 x
 y )2
n 1
n
sx 
 (x  x )
i 1
2
i
n 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
Price
1 37400
14600
2 44800
14100
3 45800
14000
4 30900
15600
5 31700
15600
6 34000
14700
.
.
.
Independent
Dependent
.
.
.
variable
x variable
y
.
.
.
10
The Simple Linear Regression Line
• Solution
– Solving by hand: Calculate a number of statistics
x  36, 011;
s x  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
11
The Simple Linear Regression Line
• Solution – continued
– Using the computer
1. Scatterplot
2. Trend function
3. Data tab > Data Analysis > Regression
12
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
13
Interpreting the Linear Regression Equation
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
14
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.
–
–
–
–
The probability distribution of e is normal.
The mean of e is zero: E(e) = 0.
The standard deviation of e is se for all values of x.
The set of errors associated with different values of y are
all independent.
15
The Normality of e
E(y|x3)
The standard deviation remains constant,
m3
b0 + b1x3
E(y|x2)
b0 + b1x2
m2
but the mean value changes with x
b0 + b1x1
E(y|x1)
m1
From the first three assumptions we have:
x1
y is normally distributed with mean
E(y) = b0 + b1x, and a constant standard
deviation se
x2
x3
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
n
SSE 

( y i  ŷ i ) 2 .
i 1
– A shortcut formula
SSE   yi2 b0  yi  b1  xi yi
18
Standard Error of Estimate
– The mean error is equal to zero.
– If se 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 se as a measure of the
suitability of using a linear model.
– An estimator of se is given by se
S tan dard Error of Estimate
se 
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  10, 446, 293
se 
SSE
10, 446, 293

 326.49
n2
98
It is hard to assess the model based
on se even when compared with the
mean value of y.
20
se  326.49 y  14,841
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.
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
21
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
s b1
The standard error of b1.
where
se
sb1 
n  1 sx
– 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 b1 and sb1.
b1  .06686
se
326.49
sb1 

 .004975
n  1 sx
99 6596.125
b1  b1 .06686  0
t

 13.44
.
004975
sb1
– The rejection region is t > t.025 or t < -t.025 with n = n-2 = 98,
t.025 = 1.9845
24
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
There is overwhelming 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
25
Coefficient of determination
Case I:
Case II:
ignore x: use y to predict y
n
errors:  (obs.  pred.) 2
i 1
n
  ( yi  y ) 2
i 1
 TSS
use x: use yˆ  b0
 b1 x
n
errors:  (obs.  pred.) 2
i 1
n
=  ( yi  yˆi ) 2
i 1
 SSE
Reduction in prediction error when use x:
TSS-SSE = SSR
26
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


  ( xi  x )( yi  y ) 
2
i 1


algebra =
 r 
2 2
sx s y
n
27
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)
x2
Variation explained by the + Unexplained variation (error)
regression line
(ŷ1  y) 2  (ŷ 2  y) 2
 (y1  ŷ1 ) 2  (y 2  ŷ 2 ) 2
28
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 (-1r
1).
r2 = 1: Perfect match between the line and the data points.
r2 = 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  (.80517)2  .6483
30
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
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.
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?
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
yˆ  ta
2
s
SE 2 (b1 )( xn  x ) 2  e  se2
n
2
– The confidence interval
yˆ  ta
2
2
s
SE 2 (b1 )( xn  x ) 2  e
n
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:
yˆ  ta
2
s
SE 2 (b1 )( xn  x ) 2  e  se2
n
2
t.025,98
326.492
14,574  1.9845 (.004975)  (40, 000  36, 011) 
 326.492  14,574  652
100
2
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ˆ  ta
2
2
s
SE 2 (b1 )( xn  x ) 2  e
n
326.492
14,574  1.9845 (.004975)  (40, 000  36, 011) 
 14,574  76
100
2
2
37
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 xn
yˆ  ta
se2
SE (b1 )  ( xn  x ) 
n
2
2
2
x
38
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 xn
yˆ ( xn  x  1)
yˆ ( xn  x  1)
yˆ  ta
se2
SE (b1 )  ( xn  x ) 
n
2
2
yˆ  ta
2
se2
SE (b1 )(1) 
n
2
2
2
x 1 x 1
x
( x  1)  x  1 ( x  1)  x  1
39
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 xn
yˆ  ta
se2
SE (b1 )  ( xn  x ) 
n
2
2
ˆ  ta
y
x 2
x
x2
( x  2)  x  2 ( x  2)  x  2
ˆ  ta
y
2
se2
SE (b1 )(1) 
n
2
2
se2
SE (b1 )(2) 
n
2
2
2
2
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
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:
A Partial list of
Standard residuals
s ri  s e 1  hi where Standardized residual ‘i’ =
Residual ‘i’
1 ( x i  x)2
hi  
Standard deviation
2
n (n  1)s x
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
+ + +
+
+
+
+
+
+
+
+
+
++ +
+
+ +
+
+ +
+ +
+
+ +
+
+
+
The spread increases with ^y
y^
++
+ ++
++
++
+
+
++
+
+
45
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
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
+
+
+
+
+
+ +
+
+
+
++
+
+
+
Time
Note the runs of positive residuals,
replaced by runs of negative residuals
+
+
+
0 +
+
+
+
Time
+
+
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
+++++++++++
… but, some outliers
may be very influential
+
+
+
+
+
+
+
The outlier causes a shift
in the regression line
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