simple_lin_regress_inference

Download Report

Transcript simple_lin_regress_inference

Simple Linear Regression
Least squares procedure
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 dependent variable (y) from
the value of independent variables (x1, x2,…xk.).
– Analyze the specific relationships between the
independent variables and the dependent variable.
2
The Model (Example)
The model has a deterministic and a probabilistic components
House
Cost
Most lots sell
for $25,000
House size
3
The Model
However, house cost 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 = dependent variable
x = independent 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
Alternate formula for the slope b1
To calculate the estimates of the slope and
intercept of the least squares line , use the
formulas:
b1 
SS xy
SS xx
b0  y  b1 x
SS xy  
x   y 


xy 
i
i
i
SS xx   xi2 
n
The regression equation that estimates
the equation of the first order linear model
is:
i
n
  xi 
sy
b1  r
sx
2
 (n  1) sx2
ŷ  b0  b1 x
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 37388
14636
2 44758
14122
3 45833
14016
4 30862
15590
5 31705
15568
6 34010
14718
.
.
.
Independent
Dependent
.
. x variable
. y
variable
.
.
.
10
The Simple Linear Regression Line
• Solution
– Solving by hand: Calculate a number
of statistics
2
x  36,009 .45;
SS xx   xi
2
x



i
n
y  14,822 .823; SS xy   ( xi yi )  
 43,528, 690
xi  yi
n
 2, 712,511
where n = 100.
b1 
SS xy
(n  1) sx2

2, 712,511
 .06232
43,528, 690
b0  y  b1 x  14,822.82  (.06232)(36, 009.45)  17, 067
ŷ  b0  b1x  17,067  .0623 x
11
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  .0623 x
ANOVA
df
Regression
Residual
Total
SS
MS
1 16734111 16734111
98 9005450
91892
99 25739561
CoefficientsStandard Error t Stat
Intercept
17067
169
100.97
Odometer
-0.0623
0.0046
-13.49
F
Significance F
182.11
0.0000
P-value
0.0000
0.0000
12
Odometer Line Fit Plot
16000
Price
17067
Interpreting the Linear Regression Equation
0
15000
14000
No data 13000
Odometer
yˆ  17,067  .0623 x
The intercept is b0 = $17067.
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.0623
13
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.
14
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
15
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.
16
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
17
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
SSE
se 
n2
18
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  9, 005, 450
SSE
9, 005, 450
se 

 303.13
n2
98
It is hard to assess the model based
on se even when compared with the
mean value of y.
s e  303.1 y  14,823
19
“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 convention
20
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
21
Point Prediction
• Example
– Predict the selling price of a three-year-old Taurus
with 40,000 miles on the odometer.
A point prediction
ŷ  17067  .0623 x  17067  .0623(40,000)  14,575
– It is predicted that a 40,000 miles car would sell for
$14,575.
– How close is this prediction to the real price?
22
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ˆ  t 2 se 1 
( xg  x ) 2
1

n  ( xi  x ) 2
– The confidence interval
yˆ  t 2 se
1

n
( xg  x ) 2
 (x
i
 x)
23
2
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
24
Interval Estimates,
Example
• Solution
– A prediction interval provides the price estimate for a
single car:
yˆ  t 2 se
t.025,98
( xg  x ) 2
1
1 
n  ( xi  x )2
Approximately
1 (40,000  36,009) 2
[17,067  .0623(40000)]  1.984(303.1) 1 

 14,575  605
100
4,309,340,310
25
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%) = ŷ  t  2 s e
1

n
( x g  x)2

( x i  x)2
1
(40, 000  36, 009) 2
[17, 067  .0623(40000)]  1.984(303.1)

 14,575  70
100
4,309,340,310
26
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.
27
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
28
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^
++
+ ++
++
++
+
+
++
+
+
29
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
30
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.
31
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.
32
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
33
An outlier
+ +
+
+ +
+ +
+ +
An influential observation
+++++++++++
… but, some outliers
may be very influential
+
+
+
+
+
+
+
The outlier causes a shift
in the regression line
34
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.
35