Linear Regression Exampl;e
Linear Regression Exampl;e
e3
e1
e2
• + )+
• + )+
•.
• + )+
• = - + )
• Y = Xa + e,
• X = nX2
• Y = nX1
Xi (Week) Yi (Prod Sales)
• A= 2X1
1 1
• e = nX1 2 3
3 4
4 8
𝑋 =[ 1 23 4 ] ,𝑌 =[ 1 3 4 8 ]
𝑡 𝑡
( ) ()
1 1 1
𝑋= 1
2 Find linear regression𝑌equation
=
3 for the following
1 3 two sets of data: 4
1 4 8
a= ( ሺ (𝑿𝒕 𝑿ሻ −𝟏 𝑿𝒕) 𝒀
After Calculating a,
a0 = Intercept = -1.5000
a1 = Slope = 2.2000
>> X'*X >> inv(X'*X)*X'
ans = ans =
4 10 1.0000 0.5000 0 -
0.5000
10 30
-0.3000 -0.1000 0.1000
>> inv(X'*X) 0.3000
ans =
1.5000 -0.5000 >> (inv(X'*X)*X')*Y
ans =
-0.5000 0.2000
-1.5000
After calculating a, 2.2000
a0 = Intercept = -1.5000
a1 = Slope = 2.2000
Y= -1.5 + 2.2X
xi yi
=
SStot =
1 to inf
Multiple Linear Regression
• Y= f(x1,x2)
= + + + …. + + ϵ
Where (, ……., ) are independent variables
Y is dependent
(, …… – Coef of regression coefficient
x1 x2 yi
1 4 1
2 5 6
3 8 8
4 2 12
X=
1 1 4
1 2 5 >> a= (inv(X'*X)*X')*Y
1 3 8
1 4 2 a=