Lec 8 (Regression)
Lec 8 (Regression)
Lecture 08
7/17/2023 Md. Golam Moazzam, Dept. of CSE, JU 1
Regression
❑ Regression
– There are various methods of curve fitting for data points of well-defined
functions.
– There are also various methods of curve fitting for experimental data.
❑ Why is it necessary?
– In many applications, it often becomes necessary to establish a mathematical relationship
between experimental values. This relationship may be used for either testing existing
mathematical models or establishing new ones.
– The mathematical equation can also be used to predict or forecast values of the
dependent variable.
– The process of establishing such relationships in the form of a mathematical equation is
known as regression analysis or curve fitting.
– Suppose the values of y for the different values of x are given. If we want to know the
effect of x on y, then we may write a functional relationship
y = f(x)
– The variable y is called the dependent variable and x the independent variable. The
relationship may be either linear or nonlinear.
7/17/2023 Md. Golam Moazzam, Dept. of CSE, JU 2
Regression
❑ Least Squares Regression
– Least square regression technique is used to fit the data under the following
situations:
• Relationship is linear.
• Relationship is transcendental.
• Relationship is polynomial.
• Relationship involves two or more independent variables.
– First two strategies do not yield a unique line for a given set of data.
– The third strategy overcomes this problem and guarantees a unique line.
– The technique of minimizing the sum of squares of errors is known as least
squares regression.
n
= ( y i − a − bxi )
2
i =1
Q Q
=0 and =0
a b
y i − na − b xi = 0
a=
y i
−
b xi
= y − bx
n n
Q n
xi y i − a xi − b xi2 = 0
y i b xi
xi y i − − xi − b xi2 = 0
n n
n xi y i − ( y i − b xi ) xi − nb xi2 = 0
b n xi2 − ( xi ) = n xi y i − xi y i
2
n xi y i − xi y i
b =
n xi2 − ( xi )
2
i i i , xi yi
x , y , x 2
Solution:
The various summations are given as follows:
xi yi xi2 xiyi
1 3 1 3
2 4 4 8
3 5 9 15
4 6 16 24
5 8 25 40
∑ 15 26 55 90
Solution:
Calculation for b and a: 8
7
5 90 − 15 26 6
b= = 1.20 y = 1.6 + 1.2x
5 55 − 15 2 y 5
4
26 15
a= − 1.20 = 1.60
3
2
5 6
1
The regression line along with the data is shown in Fig. above.
x
Fig. Data would fit a nonlinear curve better than a linear one.
n ln xi ln yi − ln xi ln yi
b= y = a + bx
n (ln xi ) − ( ln xi )
2 2
n xi yi − xi yi
b=
n xi2 − ( xi )
2
ln a = R =
1
( ln yi − b ln xi )
y b xi
n
a= i
− = y − bx
n n
So, a = eR
ln y = ln a + b ln x
n ln xi ln yi − ln xi ln yi
b=
n (ln xi ) − ( ln xi )
2 2
ln a = R =
1
( ln yi − b ln xi )
n
n ln xi ln yi − ln xi ln yi
b= ln a = R =
1
( ln yi − b ln xi )
n (ln xi ) − ( ln xi )
2 2
n
x2
Actual equation is y =
2
The discrepancy is due to round-off errors.