Example - NCSU Statistics

Download Report

Transcript Example - NCSU Statistics

Chapter 25 Inference for
Simple Linear Regression
Simple Linear Regression
1. review of least squares
procedure from chapter 7
2. inference for least squares lines
1
1. Review of Least Squares Procedure,
Chapter 7
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
• 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 response 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
The Least Squares (Regression) Line
A good line is one that minimizes
the sum of squared differences between the
points and the line.
6
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
population intercept b 0
n 1
n
sx 
 (x  x )
i 1
i
n 1
b0 estimates the unknown value of the
2
b1 estimates the unknown value of the
population slope b1
7
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
The Least Squares 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
.
.
.
8
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
The Least Squares Regression Line
• Solution
– 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
9
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
The Least Squares 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
10
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
17248.73
Interpreting the Least Squares
Regression Line
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
11
Random Error Component e:
Assumptions for Inference y  b0  b1x  e
• The random error e is a critical part of the regression model.
• To do statistical inference, 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 SD(e) of e, denoted se, is the
same for all values of x.
4. The set of errors associated with different values of y
are all independent.
12
The Normality of e
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 se remains constant,
m3
b0 + b1x3
E(y|x2)
b0 + b1x2
m2
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
E(y|x1)
m1
x1
x2
x3
13
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
Assessing the Model y  b0  b1x  e
1. Hypothesis test for the slope
H0: b1 = 0
HA: b1  0 (or < 0,or > 0)
2. Check the value of r2
3. Examine the residuals yi  yˆi , i  1, , n
The above methods used to assess the model use
the value of the Sum of Squares of the Errors,
denoted SSE.
14
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn )
SSE: Sum of Squares of the Errors
– This is the sum of the squared differences between
the observed y’s and the predicted y’s given by the
regression line. ( yi  yˆi )2 where yˆi  b0  b1 xi
– 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
15
y  b0  b1x  e
Standard Error of Estimate
– E(e) = 0. The mean error is equal to zero.
– SD(e) is denoted by se. If se is small the errors tend
to be close to zero (the mean error), and the model
describes 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
Standard Error of Estimate
SSE
se 
n2
16
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
se 

 326.49
n2
98
It is hard to assess the model based
on se even when compared with the
mean value of y.
17
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
18
y  b0  b1x  e
Testing the Slope
• We can make an inference about b1 from b1 by
testing
H0: b1 = 0
HA: b1 = 0 (or < 0,or > 0)
– The test statistic is
b1  b1
t
s b1
where
sb1 
se
n  1 sx
The standard error of b1.
– If the error variable e is normally distributed, the statistic
19
is Student t distribution with d.f. = n-2.
y  b0  b1x  e
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.
20
Testing the Slope, Example
Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 )
• 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
P-value = 2P(t98 > |-13.44|) ~ 0
21
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
22
Coefficient of determination r2
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
23
Coefficient of determination r2
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
24
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
25
Coefficient of determination r2
• 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.
26
Coefficient of determination r2,
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
27
Coefficient of determination r2
– 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
28
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
29
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?
30
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
SE 2 (b1 )( x  x ) 2  e  se2
n
2
– The confidence interval
yˆ  t
2
2
s
SE 2 (b1 )( x  x ) 2  e
n
31
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
32
Interval Estimates,
Example
• Solution
– A prediction interval provides the price estimate for a
single car:
yˆ  t
2
s
SE 2 (b1 )( x  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
33
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
2
2
s
SE 2 (b1 )( x  x ) 2  e
n
326.492
14,574  1.9845 (.004975)  (40, 000  36, 011) 
 14,574  76
100
2
2
34
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
se2
SE (b1 )  ( x  x ) 
n
2
2
2
x
35
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ˆ ( x  x  1)
yˆ ( x  x  1)
yˆ  t
se2
SE (b1 )  ( x  x ) 
n
2
2
yˆ  t
2
se2
SE (b1 )(1) 
n
2
2
2
x 1 x 1
x
( x  1)  x  1 ( x  1)  x  1
36
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
se2
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
se2
SE (b1 )(1) 
n
2
2
se2
SE (b1 )(2) 
n
2
2
2
2
37
Regression Diagnostics - I
• The three conditions required for the validity of
the regression analysis are:
– the error variable is normally distributed.
– SD(e) is constant for all values of x.
– The errors are independent of each other.
• How can we diagnose violations of these
conditions?
38
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.
39
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
40
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
41
SD(e) the Same for all x?
Heteroscedasticity
• When the requirement that SD(e) is the same for all x is violated,
we have a condition called heteroscedasticity.
• Diagnose heteroscedasticity by plotting the residual against the
predicted y.
+
^y
++
Residual
+ + +
+
+
+
+
+
+
+
+
+
++ +
+
+ +
+
+ +
+ +
+
+ +
+
+
+
The spread increases with ^y
y^
++
+ ++
++
++
+
+
++
+
+
42
Homoscedasticity
• When the requirement that SD(e) is the same for all x 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
43
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.
44
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.
45
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
46
An outlier
+ +
+
+ +
+ +
+ +
An influential observation
+++++++++++
… but, some outliers
may be very influential
+
+
+
+
+
+
+
The outlier causes a shift
in the regression line
47
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.
48