Lecture Note 3 - Introduction To Vector and Matrix Differentiation
Lecture Note 3 - Introduction To Vector and Matrix Differentiation
I
n this note we expand on Verbeek (2004, Appendix A.7) on matrix differentiation.
We first present the conventions for derivatives of scalar and vector functions;
then we present the derivatives of a number of special functions particularly useful
in econometrics, and, finally, we apply the ideas to derive the ordinary least squares
(OLS) estimator in a linear regression model. I should be emphasized that this note
is cursory reading; the particular results needed in this course are indicated with a
(∗).
Outline
§1 Conventions for Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
§2 Conventions for Vector Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
§3 Some Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
§4 The Linear Regression Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1
1 Conventions for Scalar Functions
Let = ( 1 )0 be a ×1 vector and let () = ( 1 ) be a real-valued function
that depends on , i.e. (·) : R 7−→ R maps the vector into a single number, ().
Then the derivative of (·) with respect to is defined as
⎛ () ⎞
1
() ⎜ .. ⎟
=⎜
⎝ . ⎟
⎠ (1)
()
This is a × 1 column vector with typical elements given by the partial derivative () .
Sometimes this vector is referred to as the gradient. It is useful to remember that the
derivative of a scalar function with respect to a column vector gives a column vector as
the result1 .
Similarly, the derivative of a scalar function with respect to a row vector yields the
1 × row vector
() ³ () ()
´
= · · ·
0 1
where each row, = 1 2 , contains the derivative of the scalar function (·) with
respect to the elements in . The result is therefore a × matrix of derivatives with
typical element ( ) given by
()
. If the vector function is defined as a row vector, it
is natural to take the derivative with respect to the column vector, .
We can note that it holds in general that
µ ¶
(()0 ) () 0
= , (3)
0
1 ()
Note that Wooldridge (2006, p. 815) does not follow this convention, and lets
be a row vector.
2
which in the case above is a × matrix.
Applying the conventions in (1) and (2) we can define the Hessian matrix of second
derivatives of a scalar function () as
⎛ 2 () 2 ()
⎞
· · ·
2 () 2 () ⎜⎜
1
..
1
..
1
..
⎟
⎟
0 = 0 = ⎝ . . . ⎠
2 () 2 ()
· · ·
1
2
()
which is a × matrix with typical elements ( ) given by the second derivative .
Note that it does not matter if we first take the derivative with respect to the column or
the row.
() = 0 = 1 1 + 2 2 + +
()
= (6∗)
0
To see this, write the function as
⎛ ⎞
11 1 + 12 2 + + 1
⎜ .. ⎟
() = = ⎜
⎝ . ⎟
⎠
1 1 + 2 2 + +
3
and find the derivative
⎛ ( ++ ⎞ ⎛ ⎞
11 1 1 ) (11 1 ++1 )
1 ··· 11 · · · 1
() ⎜ .. .. .. ⎟ ⎜ . .. .. ⎟
=⎜
⎝ . . . ⎟ = ⎜ ..
⎠ ⎝ . . ⎟
⎠ =
0
(1 1 ++ ) (1 1 ++ )
1 ··· 1 · · ·
4
4 The Linear Regression Model
To illustrate the use of matrix differentiation consider the linear regression model in matrix
notation,
= + ,
where is a × 1 vector of stacked left-hand-side variables, is a × matrix of
explanatory variables, is a × 1 vector of parameters to be estimated, and is a × 1
vector of error terms. Here is the number of explanatory variables and is the number
of observations.
One way to motivate the ordinary least squares (OLS) principle is to choose the esti-
b as the value of that minimizes the sum of squared residuals, i.e.
mator, ,
X
b = arg min
2 = arg min 0
=1
0 = ( − )0 ( − )
¡ ¢
= 0 − 0 0 ( − )
= 0 − 0 − 0 0 + 0 0
= 0 − 2 0 + 0 0
where the last line uses the fact that 0 and 0 0 are identical scalar variables.
Note that 0 is a scalar function and taking the first derivative with respect to yields
the × 1 vector
¡ ¢
(0 ) 0 − 2 0 + 0 0
= = −2 0 + 2 0
where we have used the results in (4∗) and (8∗) for 0 symmetric. Solving the
equations,
(0 ) b = 0
= −2 0 + 2 0
yields the OLS estimator
¡ ¢
b = 0 −1 0
provided that 0 is non-singular.
To make sure that b is a minimum of 0 and not a maximum, we should formally
ensure that the second derivative is positive definite. The × Hessian matrix of second
derivatives is given by
2 (0 ) (−2 0 + 2 0 )
= = 2 0
0 0
which is a positive definite matrix by construction.
5
References
Verbeek, M. (2004): A Guide to Modern Economtrics. John Wiley & Sons, 2nd edn.