1 The Idea
1 The Idea
1 The Idea
The idea is to find a line of best fit. Consider the following regression function
that is linear in parameters (and to keep things simple, also linear in the
variable)
Yi = b0 + b1 Xi + ei (1)
The idea behind the method of least squares is to find the parameters b0
and b1 that minimize the sum of squared residuals (SSR).
Three questions:
3 Solution Concept
What we have here is a 3-D surface called SSE that is shaped like a bowl.
Our goal is to find the pair (b0 , b1 ) that corresponds to the lowest point in
this bowl. An intuitive way to do this would be to construct a numerical
algorithm that starts at any point in the surface and keeps moving along it
until the minimum is found.
1
However, the linearity in the parameters of the linear regression function
allows us to solve this problem analytically using basic calculus. The ana-
lytical idea is to find the point where the slopes in both directions, b0 , b1 are
zero, and to ensure that this point is a global minimum.
These two first order conditions are simplified as follows, and called the
normal equations:
n
X
(Yi b0 b1 Xi ) = 0 (5)
i=1
n
X
(Yi b0 b1 Xi )Xi = 0 (6)
i=1
n(Y b0 b1 X) = 0 (9)
n n
Xi2 = 0
X X
Xi Yi b0 nX b1 (10)
i=1 i=1
2
From the first FOC, we get
b0 = Y b1 X (11)
Solving for b1 ,
Pn
Xi Yi nXY
b1 i=1
= P n 2 (13)
i=1 Xi2 nX
With a bit of algebraic manipulation, we can write this in a more elegant
form. To do this, lets first focus on the numerator, and add and subtract
nXY to it, and manipulate the resulting expression as follows;
n
X
Xi Yi nXY + nXY nXY (14)
i=1
n
X n
X n
X
Xi Yi + nXY X Yi Y Xi (15)
i=1 i=1 i=1
n
X n
X n
X n
X
Xi Yi + XY XYi Y Xi (16)
i=1 i=1 i=1 i=1
n
X
(Xi Yi XYi Y Xi + XY ) (17)
i=1
n
X
(Xi X)(Yi Y ) (18)
i=1
2
Similarly, for the denominator, add and subtract nX
n
2 2 2
Xi2 nX + nX nX
X
(19)
i=1
n n n n
2
Xi2 +
X X X X
X Xi X Xi X (20)
i=1 i=1 i=1 i=1
3
n
2
(Xi2 + X 2Xi X)
X
(21)
i=1
n
(Xi X)2
X
(22)
i=1
Therefore,
Pn
i=1 (Xi X)(Yi Y)
b1 = Pn 2
(23)
i=1 (Xi X)
2. The sum of the OLS residuals is always zero: see first FOC
4
n
2 SSR
Xi2 > 0
X
= 2 (26)
b21 i=1
Yi Y = Yi Y + ei (28)
(Yi Y )2 = (Yi Y + ei )2
X X
(29)
Because the last three terms are all zero, this expression reduces to,
5
SST = SSE + SSR (30)
SSE
R2 = (31)
SST