MAF3821 2024 Part1
MAF3821 2024 Part1
1/35
MAF3821 Mathematical Methods
Overview
1 LINEAR REGRESSION
General Definitions
Simple Linear Regression
Standard model
Assessing the fit
Correlation and Regression
2/35
MAF3821 Mathematical Methods
I.1.General Definitions
linear regression is concerned with describing the relationship
between a dependent variable and one or more independent or
explanatory variable. We will speak of
- Univariate regression if we have a single dependent variable
and also one independent or explanatory variable.
- Simple Linear Regression is the least squares regression with a
single explanatory variable. Example: fitting a straight line
through a set of points, in a way that minimizes the sum of
squared residuals. Some authors refer to simple linear
regression as bivariate regression to indicate that two variables
are dealt with a single independent variable ( predictor,
explanatory variable, covariate, risk factor, cofounder)and a
dependent variable.
- We speak of multiple linear regression for a single dependent
variable, and two or more explanatory variables. 3/35
MAF3821 Mathematical Methods
I.1.General Definitions
Y = βo + β1 X + ε
β0 is the intercept
β1 is the slope
ε denote random errors
4/35
MAF3821 Mathematical Methods
n
∂S X
= −2 (yi − β0 − β1 xi )
∂β0
i=1
n
∂S X
= −2 xi (yi − β0 − β1 xi )
∂β1
i=1
n
∂2S X
= −2 (−1) = 2n > 0
∂ 2 β0
i=1
n n
∂2S X X
= −2 xi (−xi ) = 2 xi2 > 0
∂ 2 β1
i=1 i=1
From the second derivative test for extreme values we will have
∂S ∂S
minima at ∂β 0
= 0 and ∂β 1
= 0.
We solve to find the minimizers βb0 and βb1 which are the values that
minimize the sum of squared deviations S(β0 , β1 )
6/35
MAF3821 Mathematical Methods
n
∂S X
= 0 ⇔−2 yi − βb0 − βb1 xi = 0
∂β0
i=1
n
X
⇔ yi − β0 − β1 xi = 0
b b
i=1
n
X n
X
⇔ yi = βb0 + βb1 xi
i=1 i=1
n
X n
X
⇔ yi = nβb0 + βb1 xi
i=1 i=1
Likewise
7/35
MAF3821 Mathematical Methods
n
∂S X
= 0 ⇔−2 xi yi − βb0 − βb1 xi = 0
∂β1
i=1
n
X
⇔ xi yi − βb0 xi − βb1 xi2 = 0
i=1
Xn n
X n
X
⇔ xi yi = βb0 xi + βb1 xi2
i=1 i=1 i=1
8/35
MAF3821 Mathematical Methods
which is equivalent to
βb0 = ȳ − βb1 x̄
Pn
i=1 (xi − x̄) (yi − ȳ )
β1 =
b Pn 2
i=1 (xi − x̄)
9/35
MAF3821 Mathematical Methods
Standard model
Standard model
yi = β0 + β1 xi + ei , i = 1, . . . , n
Assumptions
ei ∼ are normally distributed
E (ei ) = 0 for all i
Var (ei ) = σ 2 for all i ( homoscedasticity ) ≡ Var (yi ) = σ 2 for all i
cov (ei , ej ) = 0 for all i ̸= j ≡ cov (yi , yj ) = 0 for all i ̸= j
xi are assumed to be fixed is non stochastic constant
10/35
MAF3821 Mathematical Methods
Standard model
Theorem
Under the assumptions of the standard statistical model, the least
squares estimates are unbiased:
E (βbj ) = βj for j = 0, 1.
E (yi ) = β0 + β1 xi
11/35
MAF3821 Mathematical Methods
Standard model
nβ0 ni=1xi2 +β1( ni=1xi ) ni=1xi2 −β0( ni=1xi )2−β1( ni=1xi ) ni=1 xi2
P P P P P P
=
n ni=1 xi2 − ( ni=1 xi )2
P P
P
β0 n ni=1 xi2 −( ni=1 xi )2
P
=
n ni=1 xi2 −( ni=1 xi )2
P P
= β0
12/35
MAF3821 Mathematical Methods
Standard model
Theorem
Under the assumptions of the model
Pn
σ2 2
i=1 xi
Var (βb0 ) = Pn n 2
2
P
n i=1 xi −( i=1 xi )
nσ 2
Var (βb1 ) = Pn Pn 2
2
n i=1 xi −( i=1 xi )
−σ 2 ni=1 xi
P
cov (βb0 , βb1 ) =
n ni=1 xi2 −( ni=1 xi )2
P P
Proof
Pn Pn
i=1 (xi − x̄)(yi − ȳ ) (xi − x̄)yi
βb1 = Pn 2
= Pi=1
n 2
i=1 (xi − x̄) i=1 (xi − x̄)
σ2
we then have Var (βb1 ) = Pn 2
i=1 (xi − x̄)
13/35
MAF3821 Mathematical Methods
14/35
MAF3821 Mathematical Methods
16/35
MAF3821 Mathematical Methods
17/35
MAF3821 Mathematical Methods
βb0 = ȳ − βb1 x̄
Pn
i=1 (xi − x̄) (yi − ȳ )
β1 =
b Pn 2
.
i=1 (xi − x̄)
We can see that r and βb1 will always be of the same sign. A value
of r near or equal to 0 implies little or no relationship between y
and x. We have that −1 ≤ r ≤ 1. rxy = 1 means a perfect
positive correlation. 0 < rxy < 1 positive correlation; rxy = 0 no
correlation; −1 ≤ rxy ≤ 0 negative correlation
y = β0 + β1 x1 + . . . + βp−1 xp−1 + ε
19/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
Example
Let us consider fitting the straight line model y = β0 + β1 x + ε to
points (yi , xi ) where i = 1, 2, . . . , n in this case
21/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
Example
y1 1 x1 ε1
y2 1 x2 ε2
β
Y = . ; β = 0 ; X = . . and ε = . then
.. β1 .. .. ..
yn 1 xn εn
y1 1 x1 y1 − β0 − β1 x1
y2 1 x2 y2 − β0 − β2 x2
β
Y − X β = . − . . × 0 = .
. . . β1 ..
. . . .
yn 1 xn yn − β0 − βn xn
22/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
Example
In general for the model
Theorem
Suppose the linear model
y = β0 + β1 x1 + β2 x2 + . . . + βp−1 xp−1 + ε
X ′ X βb = X ′ Y .
24/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
25/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
n
∂S(β) X
=2 (yi − β0 − β1 xi1 − β2 xi2 − . . . − βp−1 xip−1 )(−1)=0
∂β0
i=1
n
∂S(β) X
=2 (yi − β0 − β1 xi1 − β2 xi2 − . . . − βp−1 xip−1 )(−xi1 )=0
∂β1
i=1
n
∂S(β) X
=2 (yi − β0 − β1 xi1 − β2 xi2 − . . . − βp−1 xip−1 )(−xi2 )=0
∂β2
i=1
..
.
n
∂S(β) X
=2 (yi − β0 − β1 xi1 − β2 xi2 − . . . − βp−1 xip−1 )(−xip-1 )=0
∂βp-1
i=1
26/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
Proof.
..
.
n
X n
X Xn n
X n
X
2
βb0 xip-1 + βb1 xi1 xip-1 + β2 xi2 xip-1+. . .+βp-1 xip-1= xip-1 yi
b b
i=1 i=1 i=1 i=1 i=1
which could be also written as
n
X Xn X n n
X n
X
β0
b xik + β1 xi1 xik + β2 xi2 xik+. . .+βp-1 xip-1 xik = xik yi
b b b
i=1 i=1 i=1 i=1 i=1
k = 0, 1, 2, . . . , p-1; and in matrix form
X ′ X βb = X ′ Y .
28/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
The General Multiple Regression Model
29/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
Existence Condition Solution of Normal Equations
Lemma
(X ′ X ) is non-singular, if and only if the rank of X is p.
Proof.
Suppose X ′ X is singular.
There exists a non zero vector u such that
X ′ Xu = 0
u ′ X ′ Xu = u ′ 0 = 0
(Xu)′ (Xu) = 0. So ( Xu=0 ) the columns of X are linearly
dependent and the rank of X is less than p.
30/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
Existence Condition Solution of Normal Equations
Proof.
...
Suppose that the rank of X is less than p so that there exists a
non zero vector u, Xu = 0.
Then X ′ Xu = 0 and therefore X ′ X is singular.
31/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
Existence Condition Solution of Normal Equations
Example
Returning to fitting
a straight line to the points (yi , xi ), i = 1, 2, 3.
1 x1
Then X = 1 x2
1 x3
If x1 = x2 = x3 ,the matrix is singular since the two columns are
proportional to each other. In this case we would be trying to fit a
line to a single point.
(Check that X ′ X is singular calculate it in this case ).
With n pair of observations:
1 x1 Pn
1 1 . . . 1 1 x n i=1 xi
2
X ′X = .. .. = P
. . n Pn 2
x1 x2 . . . xn i=1 xi i=1 xi
1 xn
32/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
Existence Condition Solution of Normal Equations
Example
Pn 2
Pn
i=1 xi − i=1 xi
(X ′ X )−1 = Pn
1 2
2−
( ni=1 xi )
P
n x
i=1 i
Pn
− i=1 xi n
y1 Pn
y
. . . 1 y2 i=1 i
1 1
X ′Y = .. = P Thus
x1 x2 . . . xn . n
x y
i=1 i i
yn
" #
b = β0 = X ′ X −1 X ′ Y
b
β
β1
b
Pn 2 Pn Pn
1 i=1xi − i=1xi i=1 y i
= Pn Pn 2 −
P n Pn
i=1xi n i=1 xi yi
2
n i=1 xi −( i=1 xi )
33/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
Existence Condition Solution of Normal Equations
Example
...
Pn 2
Pn Pn Pn
i=1xi i=1 yi − i=1xi i=1 xi yi
1
= Pn
n i=1 xi2 − ( ni=1 xi )2
P Pn Pn Pn
− i=1xi i=1 yi + n i=1 xi yi
Pn 2 Pn Pn Pn
x
i=1 i y
i=1 i − x
i=1 i i=1 i yi
x
2
n i=1 xi2 −( ni=1 xi ) βb0
Pn P
= =
P n P n P n
i=1 xi yi − i=1xi
n
i=1 yi
b
Pn Pn 2
β1
2
n i=1 xi −( i=1 xi )
34/35
MAF3821 Mathematical Methods
Matrix Approach to Linear Least Square
Existence Condition Solution of Normal Equations
Example
...
Thus
Pn 2
Pn Pn
Pn
i=1xi i=1 yi −
i=1xi i=1 xi yi
βb0 = Pn 2 Pn 2
− ( i=1 xi )
n i=1 xi
Pn Pn Pn
n i=1 xi yi − i=1xi i=1 yi
βb1 =
n i=1 xi − ( i=1 xi )2
Pn 2 Pn
SSxy
=
SSxx
35/35