Bold lowercase letters are column vectors, bold capitals are matrices or random vectors, a prime means transpose and everything is real. The determinant of A is written ∣A∣ and 1 is a vector of ones. The covariance matrix of a random vector X is Σ, and for observations x1,…,xn with mean xˉ the sample covariance matrix is
xy′ is the n×n matrix with xiyj in row i and column j
Projection
The projection of x on a nonzero vector y is
projyx=y′yx′yy
Its length is ∣x′y∣/∥y∥=∥x∥∣cosθ∣, and what is left over, x−projyx, is orthogonal to y.
Projecting a column of data y on 1 gives yˉ1 and leaves the deviation vector d=y−yˉ1. Its squared length d′d=∑j(yj−yˉ)2 is n−1 times the sample variance, and the sample correlation of two variables is the cosine of the angle between their deviation vectors.
Cauchy-Schwarz inequality
(x′y)2≤(x′x)(y′y)
Equality holds exactly when one vector is a multiple of the other. This is why −1≤cosθ≤1, and so why correlations lie between −1 and 1. The extended version puts a positive definite matrix in the middle.
Linear independence
Vectors x1,…,xk are linearly independent when c1x1+⋯+ckxk=0 only for c1=⋯=ck=0. Otherwise they are dependent, and at least one of them is a linear combination of the others.
More than n vectors in Rn are always dependent.
Nonzero vectors that are mutually orthogonal are independent.
The columns of a matrix A are independent exactly when Ac=0 only for c=0.
Matrices
Products and special matrices
If A is m×k and B is k×n, then AB is m×n, and its entry in row i and column j is
ℓ=1∑kaiℓbℓj.
Order matters, and AB=BA in general, even when both products exist.
The identity I has ones on the diagonal and zeros elsewhere, and IA=AI=A.
A diagonal matrix diag(d1,…,dn) has zeros everywhere off the diagonal.
A symmetric matrix has A′=A, so aij=aji. The matrices Σ,S and every correlation matrix are symmetric, and so are X′X and XX′ for any matrix X, and CAC′ whenever A is symmetric.
Transpose and inverse
A square matrix A is invertible, or nonsingular, when some matrix A−1 has AA−1=A−1A=I. The inverse rules below are for square matrices of the same size that are invertible, and a number c=0.
Rule
Transpose and inverse
Twice
(A′)′=A and (A−1)−1=A
Product
(AB)′=B′A′ and (AB)−1=B−1A−1
Three factors
(ABC)′=C′B′A′ and (ABC)−1=C−1B−1A−1
Scalar
(cA)′=cA′ and (cA)−1=c−1A−1
Sum
(A+B)′=A′+B′, but (A+B)−1 has no simple formula
Both at once
(A′)−1=(A−1)′
Diagonal
diag(d1,…,dn)−1=diag(1/d1,…,1/dn) when every di=0
In products the order reverses. A number is its own transpose, so x′Ay=y′A′x. The inverse of a symmetric matrix is symmetric, and for invertible A the system Ax=b has exactly one solution, x=A−1b. For a 2×2 matrix with ad−bc=0,
[acbd]−1=ad−bc1[d−c−ba]
Orthogonal matrices
A square matrix Q is orthogonal when Q′Q=QQ′=I, so Q−1=Q′. Its columns have length 1 and are mutually orthogonal, and so are its rows. It keeps lengths and angles, since (Qx)′(Qy)=x′y, so geometrically it is a rotation, possibly combined with a reflection, and ∣Q∣=±1.
Principal components use an orthogonal matrix whose columns are the eigenvectors of Σ, so the components are the original variables seen along rotated axes.
Determinant, trace and rank
Determinant
For a 2×2 matrix
acbd=ad−bc
For larger matrices, expanding along any row i gives
∣A∣=j=1∑n(−1)i+jaij∣Mij∣,
where Mij is A with row i and column j deleted. Columns work the same way.
For n×n matrices A and B and a number c,
Rule
Formula
Transpose
∣A′∣=∣A∣
Product
∣AB∣=∣A∣∣B∣
Scalar multiple
∣cA∣=cn∣A∣
Inverse
∣A−1∣=1/∣A∣ when A is invertible
Diagonal or triangular
The product of the diagonal entries
Invertibility
A is invertible exactly when ∣A∣=0
Watch for two traps. The scalar rule has cn, not c, because each of the n rows is multiplied by c. And ∣A+B∣ is not ∣A∣+∣B∣ in general.
Geometrically, ∣A∣ is the factor by which A scales volume, with a sign for orientation. A zero determinant means some direction gets squashed flat.
Trace
The trace of a square matrix is the sum of its diagonal entries, tr(A)=a11+a22+⋯+ann.
Rule
Formula
Linear
tr(A+B)=tr(A)+tr(B) and tr(cA)=ctr(A)
Transpose
tr(A′)=tr(A)
Swap
tr(AB)=tr(BA) for A of size m×n and B of size n×m
Cyclic
tr(ABC)=tr(BCA)=tr(CAB)
Sum of squares
tr(A′A)=∑i∑jaij2
Change of basis
tr(B−1AB)=tr(A), so tr(P′AP)=tr(A) for orthogonal P
The cyclic rule only lets you move a factor from one end of the product to the other. In general tr(ABC) and tr(ACB) differ, and tr(AB) is not tr(A)tr(B).
A trick that comes up again and again is writing a quadratic form, which is a single number, as a trace.
x′Ax=tr(x′Ax)=tr(Axx′)
The first step holds because a 1×1 matrix is its own trace, and the second is the cyclic rule. It collapses a sum of quadratic forms into one trace, for example
j=1∑n(xj−xˉ)′A(xj−xˉ)=(n−1)tr(AS).
Rank
The rank of a matrix is the largest number of linearly independent columns it has, which always equals the largest number of linearly independent rows. For an m×n matrix A the rank is at most min(m,n), and
rank(A′)=rank(A′A)=rank(AA′)=rank(A).
Whenever the product AB is defined,
rank(AB)≤min(rank(A),rank(B)).
Multiplying by an invertible matrix leaves the rank unchanged, and for nonzero vectors the outer product xy′ has rank 1.
For a square n×n matrix A these all say the same thing. The matrix A is invertible, ∣A∣=0,rank(A)=n (full rank), the columns are linearly independent, Ax=0 only for x=0, and no eigenvalue is 0.
A sample covariance matrix built from n observations has rank at most n−1, because the deviations xj−xˉ add up to 0. So with p variables, S is singular whenever n≤p.
Eigenvalues
Definition
A number λ is an eigenvalue of a square matrix A, with eigenvector x, when
Ax=λx,x=0
So A only stretches x by the factor λ and keeps it on the same line. Any nonzero multiple of an eigenvector is again an eigenvector, so it is common to scale to length 1 and write e=x/∥x∥. The sign is still a free choice, which is why two programs can report eigenvectors with opposite signs.
Characteristic equation
The eigenvalues are the solutions of
∣A−λI∣=0
For an n×n matrix this is a polynomial equation of degree n, so there are n eigenvalues counting repeats. Some may be complex numbers when A is not symmetric. For each eigenvalue, the eigenvectors are the nonzero solutions of (A−λI)x=0. For a 2×2 matrix the equation is
λ2−tr(A)λ+∣A∣=0
Useful facts
For any n×n matrix A with eigenvalues λ1,…,λn, repeats and complex values included,
Fact
Formula
Sum
λ1+λ2+⋯+λn=tr(A)
Product
λ1λ2⋯λn=∣A∣
Invertible
Exactly when no λi is 0
Inverse
For invertible A,A−1 has eigenvalues 1/λi with the same eigenvectors
Powers
Ak has eigenvalues λik with the same eigenvectors, k=1,2,…
Shift
A+cI has eigenvalues λi+c with the same eigenvectors
Diagonal or triangular
The eigenvalues are the diagonal entries
Products
CD and DC have the same nonzero eigenvalues, for C of size m×n and D of size n×m
The last row is why W−1B in MANOVA, with W positive definite and B symmetric, has the same eigenvalues as the symmetric matrix W−1/2BW−1/2 from functions of a matrix, so they are real.
Symmetric matrices
When A is symmetric, as every covariance matrix is, the picture is much cleaner.
Every eigenvalue is real.
Eigenvectors for different eigenvalues are orthogonal.
There is always a full set of n orthonormal eigenvectors, meaning length 1 and mutually orthogonal, even when eigenvalues repeat. With a repeated eigenvalue they are not unique, since any orthonormal basis of the space spanned by that eigenvalue’s eigenvectors works.
The rank is the number of nonzero eigenvalues, counted with multiplicity.
The orthogonality takes one line. If Aei=λiei and Aej=λjej, then
λiej′ei=ej′Aei=(Aej)′ei=λjej′ei
using A′=A in the middle, so ej′ei=0 whenever λi=λj.
Worked example
Take
A=[5222]
Here tr(A)=7 and ∣A∣=10−4=6, so the characteristic equation is
λ2−7λ+6=(λ−6)(λ−1)=0
and the eigenvalues are λ1=6 and λ2=1.
For λ1=6. The system (A−6I)x=0 is
[−122−4][x1x2]=[00]
Both rows say x1=2x2, so x=(2,1)′ works and e1=51(2,1)′.
For λ2=1. Now (A−I)x=0 has rows 4x1+2x2=0 and 2x1+x2=0. Both say x2=−2x1, so x=(1,−2)′ works and e2=51(1,−2)′.
Checks.
Check
Result
A(2,1)′
(10+2,4+2)′=(12,6)′=6(2,1)′
A(1,−2)′
(5−4,2−4)′=(1,−2)′=1(1,−2)′
e1′e2
51(2−2)=0
Sum of eigenvalues
6+1=7=tr(A)
Product of eigenvalues
6×1=6=∣A∣
The example continues in the next section.
Spectral decomposition
The decomposition
Every symmetric p×p matrix A can be written as
A=PΛP′=i=1∑pλieiei′
where λ1,…,λp are its eigenvalues, e1,…,ep are matching orthonormal eigenvectors, P=[e1⋯ep] has them as columns and Λ=diag(λ1,…,λp). Since P is orthogonal, the same fact reads P′AP=Λ.
The sum builds A from p rank one pieces, one per eigenvector, each weighted by its eigenvalue.
Functions of a matrix
Apply the function to the eigenvalues and keep the eigenvectors.
Matrix
Formula
Needs
A−1
PΛ−1P′=∑iλi1eiei′
Every λi=0
Ak
PΛkP′=∑iλikeiei′
k=1,2,…
A1/2
PΛ1/2P′=∑iλieiei′
Every λi≥0
A−1/2
PΛ−1/2P′=∑iλi1eiei′
Every λi>0
For a positive definite A, which for a symmetric matrix means every eigenvalue is positive (see quadratic forms), all four exist and the square roots behave the way the notation suggests. The root A1/2 is symmetric and positive definite, and
Squaring it gives back A, because (eiei′)(ejej′) is eiei′ when i=j and 0 otherwise.
Projection matrices
A symmetric matrix H with HH=H is a projection matrix. Its eigenvalues are all 0 or 1, so its rank equals its trace. Two come up often.
The centering matrix C=I−n111′ turns a data column into its deviation vector, Cy=y−yˉ1. It has rank n−1, and (n−1)S=X′CX for an n×p data matrix X.
For Z with r linearly independent columns, H=Z(Z′Z)−1Z′ projects onto the span of those columns and gives the fitted values y^=Hy in regression. It has rank r.
Quadratic forms
The form
For a symmetric p×p matrix A, the quadratic form is the number
x′Ax=i=1∑pj=1∑paijxixj
For p=2 it is a11x12+2a12x1x2+a22x22. A nonsymmetric A gives the same form as its symmetric part 21(A+A′), so assuming symmetry costs nothing.
With the spectral decomposition and y=P′x,
x′Ax=i=1∑pλi(ei′x)2=λ1y12+⋯+λpyp2
In the eigenvector coordinates a quadratic form is just a weighted sum of squares, so the signs of the eigenvalues decide its sign.
Definite matrices
Name
Definition
Eigenvalues
Positive definite
x′Ax>0 for every x=0
All λi>0
Positive semidefinite
x′Ax≥0 for every x
All λi≥0
Indefinite
Takes both positive and negative values
Some positive and some negative
Positive semidefinite is also called nonnegative definite. For a symmetric A, each of these is equivalent to being positive definite.
every eigenvalue is positive
it can be written as A=B′B for some matrix B with linearly independent columns
every leading principal minor is positive, meaning the determinants of the top left blocks of sizes 1×1,2×2,…,p×p
For a 2×2 matrix the last test reads a11>0 and a11a22−a122>0. The example matrix passes with 5>0 and 10−4=6>0, matching its eigenvalues 6 and 1.
For positive semidefinite, the first two carry over with ≥0 and any matrix B, but the minor test does not. The matrix [000−1] has leading minors 0 and 0 but is not positive semidefinite.
A few more facts.
A positive definite matrix is invertible, has ∣A∣>0 and positive diagonal entries, and its inverse is positive definite.
A positive semidefinite matrix is positive definite exactly when it is invertible.
If A is positive semidefinite, so is CAC′. If A is positive definite and the rows of C are linearly independent, CAC′ is positive definite. This is why CSC′ in a test of contrasts can be inverted when S is positive definite.
Distance and ellipsoids
For a positive definite A, the number
(x−y)′A(x−y)
is a distance between the points x and y. The points with
(x−μ)′A(x−μ)=c2
form an ellipsoid centered at μ, with axes along the eigenvectors ei of A and half lengths c/λi. When A=Σ−1 the eigenvectors are those of Σ, the eigenvalues are the reciprocals of those of Σ, and the half lengths become cλi with λi now the eigenvalues of Σ. That is the picture behind density contours and Mahalanobis distance.
Covariance matrices
For any constant vector a,
a′Σa=Var(a′X)≥0
so every covariance matrix is positive semidefinite. It fails to be positive definite exactly when Var(a′X)=0 for some a=0. Then that combination of the variables is constant with probability 1, so any variable with a nonzero coefficient in a is determined exactly by the others through a linear formula. The same argument covers S, because a′Sa is the sample variance of the numbers a′x1,…,a′xn. Correlation matrices are positive semidefinite for the same reason.
Maximizing a quadratic form
Let B be symmetric p×p with eigenvalues λ1≥λ2≥⋯≥λp and orthonormal eigenvectors e1,…,ep. Then
x=0maxx′xx′Bx=λ1 at x=e1x=0minx′xx′Bx=λp at x=ep
and among nonzero x perpendicular to the first k eigenvectors, for k=1,2,…,p−1,
x⊥e1,…,ekmaxx′xx′Bx=λk+1 at x=ek+1
The ratio does not change when x is rescaled, so these are the same as maximizing x′Bx over unit vectors x′x=1, and any nonzero multiple of e1 also gives the maximum.
Why it works. Write x=Py. Then x′x=y′y and
x′Bx=i=1∑pλiyi2≤λ1i=1∑pyi2=λ1x′x
with equality at y=(1,0,…,0)′, which is x=e1. Being perpendicular to e1,…,ek forces y1=⋯=yk=0, and the same argument then gives λk+1.
Principal components. Take B=Σ. Since Var(a′X)=a′Σa, the unit vector a with the largest variance is e1, and the variance is λ1. That is the first principal component. Because Cov(a′X,e1′X)=a′Σe1=λ1a′e1, being uncorrelated with the first component means a⊥e1 when λ1>0, so the second component is e2′X with variance λ2, and so on.
A ratio of two forms. For symmetric B and positive definite W,
x=0maxx′Wxx′Bx
is the largest eigenvalue of W−1B, reached at a matching eigenvector. Substituting y=W1/2x turns it into the previous problem with the symmetric matrix W−1/2BW−1/2, which has the same eigenvalues as W−1B. This is the problem behind Fisher’s discriminant functions for several groups.
Extended Cauchy-Schwarz inequality
Let B be positive definite. For any vectors b and d,
(b′d)2≤(b′Bb)(d′B−1d)
with equality exactly when b=cB−1d or d=cBb for some number c. It is the ordinary inequality applied to B1/2b and B−1/2d, and with B=I it is the ordinary inequality.
The version used most is a maximization. For positive definite B and a fixed d=0,
x=0maxx′Bx(x′d)2=d′B−1d
reached at x=cB−1d for any c=0.
With B=S and d=xˉ−μ0, it says Hotelling’s T2 is the largest squared t statistic over all combinations a′xˉ, which is where the simultaneous intervals come from.
Split a p×p matrix after its first q rows and columns, so A11 is q×q and A22 is (p−q)×(p−q).
A=[A11A21A12A22]
Blocks multiply like entries, as long as the sizes fit and you keep the order of each product. The transpose A′ has A11′ and A22′ on the diagonal, A21′ top right and A12′ bottom left, so a symmetric A has A21=A12′.
Swapping the roles of the blocks gives the version for invertible A22, with
A11⋅2=A11−A12A22−1A21
in place of A22⋅1. So when A,A11 and A22 are all invertible, the bottom right block of A−1 is A22⋅1−1 and the top left block is A11⋅2−1, inverses of Schur complements rather than of the matching blocks of A. If A12=0 and A21=0, the inverse is block diagonal with blocks A11−1 and A22−1.
In statistics. With A=Σ positive definite, the Schur complement
Σ11⋅2=Σ11−Σ12Σ22−1Σ21
is the covariance of the first block X(1) given the second block X(2) for a multivariate normal, as in conditional distributions. The determinant rule gives ∣Σ∣=∣Σ22∣∣Σ11⋅2∣, which is how the joint normal density factors into a marginal density times a conditional one.
Matrix calculus
Gradients
For a function f of x∈Rp, the gradient ∂f/∂x is the column of partial derivatives ∂f/∂x1,…,∂f/∂xp. Setting it to 0 finds the stationary points. Every local maximum and minimum of a differentiable f on Rp is one, but a stationary point can also be a saddle, so deciding which it is needs a separate argument, such as the concavity used for the normal likelihood.
Function
Gradient
Condition
a′x=x′a
a
a constant
x′x
2x
None
x′Ax
(A+A′)x
Any constant square A
x′Ax
2Ax
A symmetric
(x−b)′A(x−b)
2A(x−b)
A symmetric
(y−Zx)′(y−Zx)
−2Z′(y−Zx)
None
The symmetric formula 2Ax is wrong for a nonsymmetric A. Take
A=[0010].
The form x′Ax=x1x2 has gradient (x2,x1)′=(A+A′)x, while 2Ax=(2x2,0)′. Setting the last gradient in the table to 0 gives the least squares equations Z′Zx=Z′y.
Matrix derivatives
For a function f of a matrix X,∂f/∂X is the matrix of partial derivatives ∂f/∂xij, the same shape as X. These formulas treat every entry of X as a separate variable.
Function
Derivative
Condition
tr(AX)=tr(XA)
A′
A is n×m when X is m×n
a′Xb
ab′
None
ln∣X∣
(X−1)′
X square with ∣X∣>0
tr(X−1A)
−(X−1AX−1)′
X invertible
When X and A are symmetric the transposes can be dropped. The entries of a symmetric matrix like Σ are not really separate, since σik=σki. Treating them as separate anyway is fine when the stationary point you find is symmetric, because it is then also a stationary point among symmetric matrices. The normal likelihood works out this way.
Maximum likelihood for the normal
For a random sample x1,…,xn from Np(μ,Σ) the log likelihood, leaving out a constant that involves neither μ nor Σ, is
ℓ(μ,Σ)=−2nln∣Σ∣−21j=1∑n(xj−μ)′Σ−1(xj−μ)
Mean. The gradient in μ is
Σ−1j=1∑n(xj−μ)=nΣ−1(xˉ−μ),
which is zero only at μ^=xˉ, whatever Σ is.
Covariance. Put μ=xˉ, write K=Σ−1 and let
A=j=1∑n(xj−xˉ)(xj−xˉ)′=(n−1)S.
Since ln∣Σ∣=−ln∣K∣, the trace trick gives
ℓ=2nln∣K∣−21tr(KA)
Its derivative in K is 2nK−1−21A, which is zero when K−1=A/n. So
Σ^=n1j=1∑n(xj−xˉ)(xj−xˉ)′=nn−1S
The answer is symmetric, and since ln∣K∣ is concave it is the maximum. It needs S to be positive definite, which requires n>p.
Random vectors
Let X be a random vector with mean μ=E(X) and covariance matrix Σ=Cov(X). Let Y be a second random vector with mean μY, and write μX for μ when both appear. Let A and B be constant matrices and a,b and c constant vectors, of sizes that fit. The expected value of a random vector or matrix is taken entry by entry, which is why constants pass through it.
Quantity
Formula
Linear function, mean
E(AX+b)=Aμ+b
Random matrix U
E(AUB)=AE(U)B
Covariance matrix
Cov(X)=E[(X−μ)(X−μ)′]=E(XX′)−μμ′
Linear function, covariance
Cov(AX+b)=AΣA′
One combination
Var(a′X)=a′Σa
Two combinations
Cov(a′X,c′X)=a′Σc
Cross covariance
Cov(X,Y)=E[(X−μX)(Y−μY)′] and Cov(AX,BY)=ACov(X,Y)B′
Uncorrelated sum
Cov(X+Y)=Cov(X)+Cov(Y) when Cov(X,Y)=0
Standardized vector
Z=Σ−1/2(X−μ) has E(Z)=0 and Cov(Z)=I, for positive definite Σ
Quadratic form
E(X′AX)=tr(AΣ)+μ′Aμ
Adding a constant shifts the mean and leaves the covariance alone, which is why b drops out of Cov(AX+b). For a random sample X1,…,Xn these rules give E(Xˉ)=μ and Cov(Xˉ)=n1Σ.
May we count page visits to understand which courses and learning features are useful? Cloudflare collects visit and performance statistics, without your account details or answers. Your choice does not affect access. Details