Professional Documents
Culture Documents
26 Regresi
26 Regresi
Chapter 17
1
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Curve Fitting
• Fit the best curve to a discrete data set and
obtain estimates for other data points
variance y
2
Sy i
or S
n 1 n 1
Sy
c.v. 100%
Coefficient of variation – y
quantifies the spread of data (similar to relative error)
3
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Linear Regression
• Fitting a straight line to a
set of paired observations: e Error
(x1, y1), (x2, y2),…,(xn, yn)
yi : measured value
e : error
yi = a0 + a1 xi + e Line equation
y = a0 + a1 x
e = yi - a0 - a1 xi
a1 : slope
a0 : intercept 4
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Choosing Criteria For a “Best Fit”
• Minimize the sum of the residual errors
for all available data?
n n Inadequate! Regression
e (y
i 1
i
i 1
i ao a1 xi ) (see )
line
ei
Inadequate!
i 1
y
i 1
i a0 a1 xi
(see
)
n n
Minimize error : S r e ( yi a0 a1 xi ) 2
2
i
i 1 i 1
S r
2 ( yi ao a1 xi ) 0 y a a xi 1 i 0
ao 0
S r
2 ( yi ao a1 xi ) xi 0 y x a x a x
i i 0 i
2
1 i 0
a1
Since a 0 na0
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Least-Squares Fit of a Straight Line
n n
Minimize error : S r e ( yi a0 a1 xi ) 2
2
i
i 1 i 1
na0 x a y i 1 i
x a i 0 x a y x 2
i 1 i i
n
x a y
i 0 i
a
xi y x 2
x i 1 i i
n xi yi xi yi Mean values
a1
n x xi
2 2
i
r2 : coefficient of determination St n
S r ( yi a0 a1 xi ) 2
i 1
• For a perfect fit Sr=0 and r = r2 = 1
signifies that the line explains 100 percent of the variability of the data.
• For r = r2 = 0 Sr=St the fit represents no improvement
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Linearization of Nonlinear Relationships
(a) Data that is ill-suited for linear Exponential Eq.
least-squares regression
(b) Indication that a parabola may be
more suitable
y e x
slope
intercept ln
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Linearization of Nonlinear Relationships
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Data to be fit to the power equation:
y 2 x 2
log y 2 log x log 2
x y log x log y
1 0.5 0 -0.301
2 1.7 0.301 0.226
3 3.4 0.477 0.531
4 5.7 0.602 0.756
5 8.4 0.699 0.924
y a0 a1 x a2 x 2
n n
Minimize error : S r e ( yi a0 a1 xi a2 xi2 ) 2
2
i
i 1 i 1
S r
2 ( yi ao a1 xi a2 xi2 ) 0 na0 xi a1 xi2 a2 yi
ao
S r
a1
2 xi ( yi ao a1 xi a2 xi2 ) 0 x a x a x a x y
i 0
2
i 1
3
i 2 i i
S r
2 xi2 ( yi ao a1 xi a2 xi2 ) 0
a2 x a x a x a x
2
i 0
3
i 1
4
i 2
2
i yi
13
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Polynomial Regression
• To fit the data to an mth order polynomial, we need to solve the following
system of linear equations ((m+1) equations with (m+1) unknowns)
n x i x a0 y i
m
i
xi x x a1 xi yi
2 m 1
i i
mm
i
x m
i
x m 1
xi am xi yi
m
Matrix Form
14
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
***here Multiple Linear Regression
• A useful extension of linear regression is the case where y is a linear function of
two or more independent variables. For example:
y = a o + a 1x 1 + a 2x 2 + e
• For this 2-dimensional case, the regression line becomes a plane as shown in
the figure below.
15
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Multiple Linear Regression
n n
Example (2 - vars) : Minimize error : S r e ( yi a0 a1 x1i a2 x2i ) 2
2
i
i 1 i 1
S r
2 ( yi ao a1 x1i a2 x2i ) 0 na0 x1i a1 x2i a2 yi
ao
S r
a1
2 x1i ( yi ao a1 x1i a2 x2i ) 0 x a x a x
1i 0
2
1i 1 x a2 x1i yi
1i 2 i
S r
2 x2i ( yi ao a1 x1i a2 x2i ) 0
a2 x a x 2i 0 1i x2 i a1 x a x
2
2i 2 2i yi
n
x 1i x a0 y i
2i
x1i x x x 1i 2 i a1 x1i yi
2
1i
x2 i x x x 2
x2i yi
2 i a2
1i 2 i
Which method would you use to solve this Linear System of Equations? 16
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Multiple Linear Regression
n
x 1i x 2i a0 y i
x1i x x x
1i 2 i a1 x1i yi
2
1i
Example 17.6 x2 i x x x 2
x2i yi
2 i a2
1i 2 i
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.