Matrix Algebra for Random Vectors
Matrix Algebra for Random Vectors
Hanoi, 2022
Content
3
Applied Multivariate Statistical Analysis
5.1 Revision
c1 x + c2 y = 0
c1 x 1 + c2 x 2 + · · · + ck x k = 0
Linear dependence implies that at least one vector in the set can be written as a
linear combination of the other vectors. Vectors of the same dimension that are not
linearly dependent are said to be linearly independent.
(x′ y) (x′ y) 1
Projection of x on y = y′ y
y = Ly Ly
y,
|x′ y| x′ y
Length of protection = = Lx = Lx | cos(θ)|,
Ly Lx Ly
Another special class of square matrices with which we shall become familiar are
the orthogonal matrices, characterized by
QQ′ = Q′ Q = I or Q′ = Q−1
The name derives from the property that if Q has i th row q′i , then QQ′ = I implies
that q′i qi = 1 and q′i qj = 0 for i ̸= j, so the rows have unit length and are mutually
perpendicular (orthogonal). According to the condition Q′ Q = I, the columns have
the same property.
We conclude our brief introduction to the elements of matrix algebra by intro-
ducing a concept fundamental to multivariate statistical analysis. A square matrix
A is said to have an eigenvalue λ, with corresponding eigenvector x ̸= 0, if
Ax = λx
The study of the variation and interrelationships in multivariate data is often based
upon distances and the assumption that the data are multivariate normally dis-
tributed. Squared distances (see Chapter 1) and the multivariate normal density
can be expressed in terms of matrix products called quadratic forms (see Chapter
4). Consequently, it should not be surprising that quadratic forms play a central
role in multivariate analysis. In this section, we consider quadratic forms that are
always nonnegative and the associated positive definite matrices.
Results involving quadratic forms and symmetric matrices are, in many cases, a
direct consequence of an expansion for symmetric matrices known as the spectral
decomposition. The spectral decomposition of a k × k symmetric matrix A is given
by 1 where λ1 , λ2 , . . . , λk are the eigenvalues of A and e1 , e2 , . . . , ek are the associated
normalized eigenvectors. (See also Result 2A.14 in Supplement 2A). Thus, e′i ei = 1
for i = 1, 2, . . . , k, and e′i ej = 0 for i ̸= j.
2 −2 10
The eigenvalues obtained from the characteristic equation |A − λI| = 0 are λ1 =
9, λ2 = 9, and λ3 = 18 (Definition 2A.30). The corresponding eigenvectors e1 , e2 ,
and e3 are the (normalized) solutions of the equations Aei = λi ei for i = 1, 2, 3.
Thus, Ae1 = λe1 gives
13 −4 2 e11 e11
−4 13 −2 e21 = 9 e21
2 −2 10 e31 e31
or
13e11 − 4e21 + 2e31 = 9e11
−4e11 + 13e21 − 2e31 = 9e21
2e11 − 2e21 + 10e31 = 9e31
or
1
√
13 −4 2 2
1 √1 1
−4 13 −2 = 9
√ √ 0
2
2 2
2 −2 10
0
1
2
√
18 3
−1 −1 −4
√1 2 2 2 1
+9
√ √ √ + 18 − 3 −3
18 18 18 18 3 3
−4 1
√
18 3
The spectral decomposition is an important analytical tool. With it, we are very
easily able to demonstrate certain statistical results. The first of these is a matrix
explanation of distance, which we now develop.
Because x′ Ax has only squared terms x2i and product terms xi xk , it is called a
quadratic form. When a k × k symmetric matrix A is such that
0 ≤ x′ Ax
for all x′ = [x1 , x2 , . . . , xk ], both the matrix A and the quadratic form are said to be
nonnegative definite. If equality holds in (2-17) only for the vector x′ = [0, 0, . . . , 0],
then A or the quadratic form is said to be positive definite. In other words, A is
positive definite if
0 < x′ Ax
for all vectors x ̸= 0
Using the spectral decomposition, we can easily show that a k × k symmetric
matrix A is a positive definite matrix if and only if every eigenvalue of A is positive.
(See Exercise 2.17.) A is a nonnegative definite matrix if and only if all of its
eigenvalues are greater than or equal to zero.
Assume for the moment that the p elements x1 , x2 , . . . , xp of a vector x are
realizations of p random variables X1 , X2 , . . . , Xp . As we pointed out in Chapter 1,
we can regard these elements as the coordinates of a point in p-dimensional space,
and the "distance" of the point [x1 , x2 , . . . , xp ] to the origin can, and in this case
should, be interpreted in terms of standard deviation units. In this way, we can
account for the inherent uncertainty (variability) in the observations. Points with
the same associated "uncertainty" are regarded as being at the same distance from
the origin. If we use the distance formula introduced in Chapter 1 [see Equation
(1-22)], the distance from the origin satisfies the general formula
If we use the distance formula introduced in Chapter 1 [see Equation (1 − 22) ],
the distance from the origin satisfies the general formula
provided that (distance) 2 > 0 for all [x1 , x2 , . . . , xp ] ̸= [0, 0, . . . , 0]. Setting aij = aji ,
i ̸= j, i = 1, 2, . . . , p, j = 1, 2, . . . , p, we have
a11 a12 · · · a1p x1
a21 a22 · · · a2p x2
2
0 < ( distance ) = [x1 , x2 , . . . , xp ] .. .. . . ..
..
. . . . .
ap1 ap2 · · · app xp
or
0 < ( distance )2 = x′ Ax for x ̸= 0
From (2-19), we see that the p × p symmetric matrix A is positive definite. In sum,
distance is determined from a positive definite quadratic form x′ Ax. Conversely, a
positive definite quadratic form can be interpreted as a squared distance.
Comment. Let the square of the distance from the point x′ = [x1 , x2 , . . . , xp ]
to the origin be given by x′ Ax, where A is a p × p symmetric positive definite
matrix. Then the square of the distance from x to an arbitrary fixed point µ′ =
[µ1 , µ2 , . . . , µp ] is given by the general expression (x − µ)′ A(x − µ).
Expressing distance as the square root of a positive definite quadratic form allows
us to give a geometrical interpretation based on the eigenvalues and eigenvectors of
the matrix A. For example, suppose p = 2. Then the points x′ = [x1 , x2 ] of constant
distance c from the origin satisfy
√
If p > 2, the points x′ = [x1 , x2 , . . . , xp ] a constant distance c = x′ Ax from
the origin lie on hyperellipsoids c2 = λ1 (x′ e1 )2 + · · · + λp (x′ ep )2 , whose axes are
√
given by the eigenvectors of A. The half-length in the direction ei is equal to c/ λi ,
i = 1, 2, . . . , p, where λ1 , λ2 , . . . , λp are the eigenvalues of A.
A SQUARE-ROOT MATRIX
A = ki=1 λi ei e′i . Let the normalized eigenvectors be the columns of another matrix
P
P = [e1 , e2 , . . . , ek ]. Then
k
X
A = λi ei e′i = PP
(k×k) (k×1)(1×k)(k×k)(k×k)(k×k) (P P
i=1
2. A1/2 A1/2 = A.
−1 Pk
3. A1/2 = i=1 √1λi ei e′i = PΛ−1/2 P′ , where Λ−1/2 is a diagonal matrix with
√
1/ λi as the i th diagonal element.
−1
4. A1/2 A−1/2 = A−1/2 A1/2 = I, and A−1/2 A−1/2 = A−1 , where A−1/2 = A1/2 .
Then the expected value of X, denoted by E(X), is the n × p matrix of numbers (if
they exist)
E (X11 ) E (X12 ) · · · E (X1p )
E (X21 ) E (X22 ) · · · E (X2p )
E(X) = .. .. .. ..
. . . .
E (Xn1 ) E (Xn2 ) · · · E (Xnp )
where, for each element of the matrix, 2
R ∞
x f (xij ) dxij
−∞ ij ij
if Xij is a continuous random variable with
probability density function f (x )
ij ij
E (Xij ) = P
all xij xij pij (xij ) if Xij is a discrete random variable with
probability function pij (xij )
R∞ if Xi is a continuous random variable with probability
xi fi (xi ) dxi
−∞
density function fi (xi )
µi = P
all xi xi pi (xi ) if Xi is a discrete random variable with probability
function pi (xi )
∞ (xi − µi )2 fi (xi ) dxi
R if Xi is a continuous random variable
−∞
σi2 = with probability density function fi (xi )
2
P
all xi (xi − µi ) pi (xi ) if Xi is a discrete random variable
It will be convenient in later sections to denote the marginal variances by σii rather
than the more traditional σi2 , and consequently, we shall adopt this notation.
for all pairs of values xi , xk , then Xi and Xk are said to be statistically indepen-
dent. When Xi and Xk are continuous random variables with joint density fik (xi , xk )
and marginal densities fi (xi ) and fk (xk ), the independence condition becomes
for all pairs (xi , xk ) The p continuous random variables X1 , X2 , . . . , Xp are mutually
statistically independent if their joint density can be factored as
The converse of (2-29) is not true in general; there are situations where Cov (Xi , Xk ) =
0, but Xi and Xk are not independent. (See [2].)
The means and covariances of the p × 1 random vector X can be set out as
matrices. The expected value of each element is contained in the vector of means
µ = E(X), and the p variances σii and the p(p − 1)/2 distinct covariances σik (i < k)
are contained in the symmetric variance-covariance matrix Σ = E(X − µ)(X − µ)′ .
Specifically,
E (X1 ) µ1
E (X2 ) µ2
E(X) = .. = .. = µ
. .
E (Xp ) µp
σ11 σ12 · · · σ1p
σ21 σ22 · · · σ2p
Σ = Cov(X) = .. .. .. .
. . . ..
σp1 σp2 · · · σpp
We note that the computation of means, variances, and covariances for discrete
random variables involves summation (as in Examples 2.12 and 2.13), while analo-
gous computations for continuous random variables involve integration.
Because σik = E (Xi − µi ) (Xk − µk ) = σki , it is convenient to write the matrix
appearing in (2-31) as
σ11 σ12 · · · σ1p
σ12 σ22 · · · σ2p
′
Σ = E(X − µ)(X − µ) = . .. . . ..
. . . . .
σ1p σ2p · · · σpp
We shall refer to µ and Σ as the population mean (vector) and population variance-
covariance (matrix), respectively.
The multivariate normal distribution is completely specified once the mean vector
µ and variance-covariance matrix Σ are given (see Chapter 4), so it is not surprising
that these quantities play an important role in many multivariate procedures.
It is frequently informative to separate the information contained in variances
σii from that contained in measures of association and, in particular, the measure
V1/2 ρV1/2 = Σ
and
−1 −1
ρ = V1/2 Σ V1/2
That is, Σ can be obtained from V1/2 and ρ, whereas ρ can be obtained from Σ.
Moreover, the expression of these relationships in terms of matrix operations allows
the calculations to be conveniently implemented on a computer.
Partitioning the Covariance Matrix Often, the characteristics measured on in-
dividual trials will fall naturally into two or more groups. As examples, consider
we can write
X1
..
.
µ1 µq
Xq
..
" (1) #
µq+1
p − qu = . = µ
X= ······
and µ = E(X) = ..
(1)
X
.
µ(2)
Xq+1
..
X(2) µp
.
Xp
and consequently,
" #
′ q Σq11 Σp−q
12
Σ(p×1 = E(X − µ)(X − µ) = p−q
(p×p) Σ21 Σ22
σ11 ··· σ1q σ1,q+1 ··· σ1p
.. .. .. .. .. ..
.
. . . . .
σ
q1 · · · σqq σq,q+1 · · · σqp
=
σq+1,1 · · · σq+1,q σq+1,q+1 · · · σq+1,p
.. .. .. .. .. ..
. . . . . .
σp1 · · · σpq σp,q+1 · · · σpp
Note that Σ12 = Σ′21 . The covariance matrix of X(1) is Σ11 , that of X(2) is Σ22 ,
and that of elements from X(1) and X(2) is Σ12 (or Σ21 ).
If we let " #
σ11 σ12
Σ=
σ12 σ22
be the variance-covariance matrix of X, Equation (2-41) becomes
mean = E (c′ X) = c′ µ
variance = Var (c′ X) = c′ Σc
where µX and ΣX are the mean vector and variance-covariance matrix of X, respec-
tively. (See Exercise 2.28 for the computation of the off-diagonal terms in CΣX C′ .)
Partitioning the Sample Mean Vector and Covariance Matrix Many of the ma-
trix results in this section have been expressed in terms of population means and
variances (covariances). The results in (2-36), (2-37), (2-38), and (2-40) also hold if
the population quantities are replaced by their appropriately defined sample coun-
terparts.
Let x′ = [x̄1 , x̄2 , . . . , x̄p ] be the vector of sample averages constructed from n
observations on p variables X1 , X2 , . . . , Xp , and let
s11 · · · s1p
. .
Sn = .. . . . ..
s1p · · · spp
Pn
(xj1 − x̄1 )2
1 1
Pn
n j=1 ··· n
(xj1 − x̄1 ) (xjp − x̄p )
j=1
.. .. ..
= .
. .
1
Pn 1
Pn 2
n j=1 (xj1 − x̄1 ) (xjp − x̄p ) · · · n j=1 (xjp − x̄p )
and
s11 ··· s1q s1,q+1 ··· s1p
.. ... .. .. ... ..
. . . .
sq1 · · · sqq sq,q+1 · · · sqp
Sn =
(p×p) . . . sq+1,1 · · · sq+1,q sq+1,q+1 · · · sq+1,p
.. ... .. .. ... ..
. . . .
sp1 · · · spq sp,q+1 · · · spp
" #
Sq11 S12
= qp−q
. . . S21 S22
where x(1) and x(2) are the sample mean vectors constructed from observations
x(1) = [x1 , . . . , xq ]′ and x(2) = [xq+1 , . . . , xp ]′ , respectively; S11 is the sample covari-
ance matrix computed from observations x(1) ; S22 is the sample covariance matrix
computed from observations x(2) ; and S12 = S′21 is the sample covariance matrix for
elements of x(1) and elements of x(2) .
The ideas that lead to the spectral decomposition can be extended to provide a
decomposition for a rectangular, rather than a square, matrix. If A is a rectangular
matrix, then the vectors in the expansion of A are the eigenvectors of the square
matrices AA′ and A′ A.
AA′ ui = λ2i ui
with λ21 , λ22 , . . . , λ2r > 0 = λ2r+1 , λ2r+2 , . . . , λ2m (for m > k ). Then vi = λ−1 ′
i A ui .
Alternatively, the vi are the eigenvectors of A′ A with the same nonzero eigenvalues
λ2i .
The matrix expansion for the singular-value decomposition written in terms of
the full dimensional matrices U, V, Λ is
A = U
(m×k) (m×m)(m×k)(k×k)(V′
A is " #
3 1 1
A=
−1 3 1
" # " #
√ √1 h i √ √1 h
−1
i
= 12 2 √1 √2 √1 + 10 2 √2 √ 0
√1 6 6 6 −1
√ 5 5
2 2
The equality may be checked by carrying out the operations on the right-hand
side. The singular-value decomposition is closely connected to a result concerning
the approximation of a rectangular matrix by a lower-dimensional matrix, due to
Eckart and Young ([3]). If a m × k matrix A is approximated by B, having the same
dimension but lower rank, the sum of squared differences
m X
X k
(aij − bij )2 = tr [(A − B)(A − B)′ ]
i=1 j=1
over all m × k matrices B having rank no greater than s. The minimum value, or
error of approximation, is ki=s+1 λ2i .
P
To establish this result, we use UU′ = Im and VV′ = Ik to write the sum of
squares as
where C = U′ BV. Clearly, the minimum occurs when cij = 0 for i ̸= j and cii = λi
for the s largest singular values. The other cii = 0. That is, UBV′ = Λs or B =
Ps ′
i=1 λi ui vi .
over all m × k matrices B having rank no greater than s. The minimum value, or
error of approximation, is ki=s+1 λ2i .
P
To establish this result, we use UU′ = Im and VV′ = Ik to write the sum of
squares as
where C = U′ BV. Clearly, the minimum occurs when cij = 0 for i ̸= j and cii = λi
for the s largest singular values. The other cii = 0. That is, UBV′ = Λs or B =
Ps ′
i=1 λi ui vi .
import numpy as np
import [Link] as la
[ 0, 1, 1]])
B = [Link]([[2,0,-1], [-1,0,-1], [1,1,1]])
B
matrix([[ 2, 0, -1],
[-1, 0, -1],
[ 1, 1, 1]])
#Addition
A + B
matrix([[ 3, 2, -2],
[ 1, 0, 0],
[ 1, 2, 2]])
#Subtraction
A - B
matrix([[-1, 2, 0],
[ 3, 0, 2],
[-1, 0, 0]])
#Multiplication by a scalar
5*A
matrix([[ 5, 10, -5],
[10, 0, 5],
[ 0, 5, 5]])
#Determinant of a matrix
[Link](A)
-6.999999999999999
#Rank of a matrix
la.matrix_rank(A)
3
#Power of a matrix
la.matrix_power(A, 5)
matrix([[ 47, 53, -18],
[ 70, 29, 1],
[ 34, 35, -4]])
[Link](M)
(array([10., 8.]),
matrix([[ 0.70710678, -0.70710678],
[ 0.70710678, 0.70710678]]))
#Trace of a matrix
[Link](M)
18
b = [Link]([2, 5])
[Link]
Parameters
----------
a : (..., M, N) array_like
A real or complex array with ‘‘[Link] >= 2‘‘.
full_matrices : bool, optional
If True (default), ‘u‘ and ‘vh‘ have the shapes ‘‘(..., M, M)‘‘ and
‘‘(..., N, N)‘‘, respectively. Otherwise, the shapes are
‘‘(..., M, K)‘‘ and ‘‘(..., K, N)‘‘, respectively, where
‘‘K = min(M, N)‘‘.
compute_uv : bool, optional
Whether or not to compute ‘u‘ and ‘vh‘ in addition to ‘s‘. True
by default.
hermitian : bool, optional
Returns
-------
u : { (..., M, M), (..., M, K) } array
Unitary array(s). The first ‘‘[Link] - 2‘‘ dimensions have the same
size as those of the input ‘a‘. The size of the last two dimensions
depends on the value of ‘full_matrices‘. Only returned when
‘compute_uv‘ is True.
s : (..., K) array
Vector(s) with the singular values, within each vector sorted in
descending order. The first ‘‘[Link] - 2‘‘ dimensions have the same
size as those of the input ‘a‘.
vh : { (..., N, N), (..., K, N) } array
Unitary array(s). The first ‘‘[Link] - 2‘‘ dimensions have the same
size as those of the input ‘a‘. The size of the last two dimensions
depends on the value of ‘full_matrices‘. Only returned when
‘compute_uv‘ is True.
5.3 Exercises
Problem 4. Give the definition for eigenvalues and eigenvector of a square matrix
A.
Problem 5. What is a positive definite matrix? How can we check weather a matrix
is positive definite?
Problem 7. Write the formular for the means, covariances, correlation matrix of a
random vector X.
Problem 8. State the theorem of The spectral decomposition and Singular value
decomposition.
Problem 9. State the mean vector and covariance matrix for linear combinations
of random variables.
h i h i
′ ′
Problem 10. Let x = 5, 1, 3 and y = −1, 3, 1 .
b. Find (i) the length of x, (ii) the angle between x and y, and (iii) the projection
of y on x.
a. 5A
b. BA
c. A′ B′
d. C′ B
e. Is AB defined?
a. (A′ )′ = A
′
b. (C′ )−1 = (C−1 )
c. (AB)′ = B′ A′
Problem 13. When A−1 and B−1 exist, prove each of the following.
′
a. (A′ )−1 = (A−1 )
is an orthogonal matrix.
a. Is A symmetric?
e. Find A−1 .
b. Find A−1 .
d. Write the spectral decomposition of A−1 , and compare it with that of A from
a.
These matrices are identical except for a small difference in the (2, 2) position.
Moreover, the columns of A (and B ) are nearly linearly dependent. Show that
.
A−1 = (−3)B−1 . Consequently, small changes-perhaps caused by rounding, can
give substantially different inverses.
Problem 18. Show that the determinant of the p × p diagonal matrix A = {aij }
with aij = 0, i ̸= j, is given by the product of the diagonal elements; thus, |A| =
a11 a22 · · · app .
Problem 19. Show that the determinant of a square symmetric p × p matrix A can
be expressed as the product of its eigenvalues λ1 , λ2 , . . . , λp ; that is, |A| = pi=1 λi .
Q
Problem 25. Consider the sets of points (x1 , x2 ) whose "distances" from the origin
are given by
√
c2 = 4x21 + 3x22 − 2 2x1 x2
for c2 = 1 and for c2 = 4. Determine the major and minor axes of the ellipses
of constant distances and their associated lengths. Sketch the ellipses of constant
distances and comment on their positions. What will happen as c2 increases?
P √
Problem 26. Let A1/2 = m i=1 λi ei e′i = PΛ1/2 P′ , where PPP′ = P′ P = I. (The
(m×m)
λi ’s and the ei ’s are the eigenvalues and associated normalized eigenvectors of the
matrix A.) Show the following properties (1)-(4) of the square-root matrix.
′
1. A1/2 = A1/2 (that is, A1/2 is symmetric).
2. A1/2 A1/2 = A.
−1 Pk
3. A1/2 = i=1 √1λi ei e′i = PΛ−1/2 P′ , where Λ−1/2 is a diagonal matrix with
√
1/ λi as the i th diagonal element.
−1
4. A1/2 A−1/2 = A−1/2 A1/2 = I, and A−1/2 A−1/2 = A−1 , where A−1/2 = A1/2 .
Problem 27. Determine the square-root matrix A1/2 , using the matrix A in Exer-
cise 11. Also, determine A−1/2 , and show that A1/2 A−1/2 = A−1/2 A1/2 = I.
2 2
b. Calculate AA′ and obtain its eigenvalues and eigenvectors. Check that the
nonzero eigenvalues are the same as those in part (a).
b. Calculate A′ A and obtain its eigenvalues and eigenvectors. Check that the
nonzero eigenvalues are the same as those in part a.
0 0 1
Find
a. Σ−1
4 1 9
c. Find ρ13 .
Problem 33. Derive expressions for the mean and variances of the following linear
combinations in terms of the means and covariances of the random variables X1 , X2 ,
and X3 .
a. X1 − 2X2
b. −X1 + 3X2
c. X1 + X2 + X3
d. X1 + 2X2 − X3
Problem 34. Show that Cov (c11 X1 + c12 X2 + · · · + c1p Xp , c21 X1 + c22 X2 + · · · + c2p Xp ) =
c′1 Σx c2 where c′1 = [c11 , c12 , . . . , c1p ] and c′2 = [c21 , c22 , . . . , c2p ]. This verifies the off-
diagonal elements CΣX C′ in (2-45) or diagonal elements if c1 = c2
where
" # X3
X1
X(1) = and X(2) = X4
X2
X5
Let Σ be the covariance matrix of X with general element σik . Partition Σ into the
covariance matrices of X(1) and X(2) and the covariance matrix of an element of X(1)
and an element of X(2)
Problem 36. You are given the random vector X′ = [X1 , X2 , X3 , X4 ] with mean
vector µ′X = [4, 3, 2, 1] and variance-covariance matrix
3 0 2 2
0 1 1 0
ΣX =
2 1 9 −2
2 0 −2 4
Partition X as
X1
(1)
X2 X
X=
... = ...
(2)
X3 X
X4
Let " #
h i 1 −2
A= 1 2 and B =
2 −1
and consider the linear combinations AX(1) and BX(2) . Find
a. E X(1)
b. E AX(1)
c. Cov X(1)
d. Cov AX(1)
e. E X(2)
f. E BX(2)
g. Cov X(2)
h. Cov BX(2)
i. Cov X(1) , X(2)
h. Cov AX(1) , BX(2)