Linear Regression Course
Linear Regression Course
e = y −ax−b
Thus, the residual is the discrepancy between the true value of y and the
approximate value, a x +b , predicted by the linear equation.
Now, realizing that σ𝑛𝑖=1 𝑏 = n b, we can express the equations as a set of two simultaneous
linear equations with two unknowns (a and b):
y = ax +nb
n n
i i (3)
i=1 i=1
y x = ax +bx
n n n
2
i i i i
i=1 i=1 i=1
Solution:
x y 𝒙𝟐 xy
10 25 100 250
20 70 400 1400
5135 = 360 a + 8 b
Y = nB+ax
n n
i i (4)
i=1 i=1
42.9124 = 7B+8.45 a
49.0951=8.45B + 10.5625 a
Y = nB+aX
n n
i i (5)
i=1 i=1
X 1 2 3 4 5
y 0.5 1.7 3.4 5.7 8.4
x y X=𝒍𝒐𝒈𝟏𝟎 x Y=𝒍𝒐𝒈𝟏𝟎 𝐲 𝑿𝟐 XY
1 0.5 0 -0.3010 0 0
2 1.7 0.3010 0.2304 0.0906 0.0694
𝑎𝑥
3] Growth rate model y=
𝑏+𝑥
1 𝑏+𝑥 𝑏 1 1
Then = = + → 𝑌 =𝐴𝑋+𝐵
𝑦 𝑎𝑥 𝑎 𝑥 𝑎
1 1 𝑏 1
Where Y= , X= , A= , and B =
𝑦 𝑥 𝑎 𝑎
Example: Fit a growth rate model for the following
X 2.5 3.5 5 6 7.5 10
y 5 3.4 2 1.6 1.2 0.8
Solution: Substituting from the value of the blow table in Eq.(5) we have
3.7025 = 6B + 1.2857 A
0.7851 𝑥
Then y=
−2.4062+𝑥
x y X=
𝟏
Y=
𝟏 𝑿𝟐 XY
𝒙 𝒚
2.5 5 0.4000 0.2000 0.1600 0.0800
1
2] x y = ax + b → 𝑦=𝑎+𝑏 → 𝑦 =𝑎+𝑏𝑋
𝑥
1 1
3] y = → =ax+b → 𝑌 = 𝑎𝑥 + 𝑏
𝑎𝑥+𝑏 𝑦
𝑎 𝑏 1 𝑏
4] x y = a x + b y → 1= + → 1=aY+bX→ 𝑌 = - 𝑋→ 𝑌 = 𝐵 + 𝐴𝑋
𝑦 𝑥 𝑎 𝑎
5] y=a log x +b → 𝑦 = 𝑎𝑋 + 𝑏
Exercises:
1] Use the least square regression to fit : (a) a straight line ,(b)a power (exponential)
equation, ( c) growth rate equation , and (d) a parabola for the following data
X 1 2 3 4 5 6
1-
y 3.6 4.7 5.5 7.5 8.7 9.9
x 1 2 2.5 4 6 8 8.5
2-
y 0.4 0.7 0.8 1 1.2 1.3 1.4
3] Use the least square regression to fit a curve on the form 𝑦 = 𝑎 + 𝑏/𝑥 3 suitable for this data
X 1 2 3 4 5 6
y 66 22 14 11 9.4 8.6
4] Use the relation x y = ax + b to find the best value for a and b to fit the following data
In the first section, a procedure was developed to derive the equation of a straight line using the
least-squares criterion. Some data, although exhibiting a marked pattern such as seen in
This figure, are poorly represented by a straight line. For these cases, a curve would be better
suited to fit the data. As discussed in the first section, one method to accomplish this objective
is to use transformations. Another alternative is to fit polynomials to the data using polynomial
regression.
The least-squares procedure can be readily extended to fit the data to a higher-order
polynomial. For example, suppose that we fit a second-order polynomial or quadratic
y = a0 +a1x +a2x2 +e
For this case the sum of the squares of the residuals is
Example: Fit a second-order polynomial to the data in the first two column in the
following table
Solution:
x y 𝒙𝟐 𝒙𝟑 𝒙𝟒 Xy 𝒙𝟐 y
0 2.1 0 0 0 0 0
1 7.7 1 1 1 7.7000 7.7
x 1 2 2.5 4 6 8 8.5
(1)
y 0.4 0.7 0.8 1 1.2 1.3 1.4
X 1 2 3 4 5 6
x 0 2 4 6 8 10