In probability theory and statistics, a covariance matrix (also known as auto-covariance matrix, dispersion matrix, variance matrix, or variance–covariance matrix) is a square matrix giving the covariance between each pair of elements of a given random vector. Intuitively, the covariance matrix generalizes the notion of variance to multiple dimensions. As an example, the variation in a collection of random points in two-dimensional space cannot be characterized fully by a single number, nor would the variances in the x and y directions contain all of the necessary information; a 2×2 matrix would be necessary to fully characterize the two-dimensional variation. Any covariance matrix is symmetric and positive semi-definite and its main diagonal contains variances (i.e., the covariance of each element with itself). The covariance matrix of a random vector 𝐗 is typically denoted by K𝐗𝐗, Σ or S.
Definition Throughout this article, boldfaced unsubscripted 𝐗 and 𝐘 are used to refer to random vectors, and Roman subscripted Xi and Yi are used to refer to scalar random variables. If the entries in the column vector 𝐗=(X1,X2,…,Xn)𝖳 are random variables, each with finite variance and expected value, then the covariance matrix K𝐗𝐗 is the matrix whose (i,j) entry is the covariance KXiXj=cov[Xi,Xj]=E[(Xi−E[Xi])(Xj−E[Xj])] where the operator E denotes the expected value (mean) of its argument.
Conflicting nomenclatures and notations Nomenclatures differ. Some statisticians, following the probabilist William Feller in his two-volume book An Introduction to Probability Theory and Its Applications, call the matrix K𝐗𝐗 the variance of the random vector 𝐗, because it is the natural generalization to higher dimensions of the 1-dimensional variance. Others call it the covariance matrix, because it is the matrix of covariances between the scalar components of the vector 𝐗. var(𝐗)=cov(𝐗,𝐗)=E[(𝐗−E[𝐗])(𝐗−E[𝐗])𝖳]. Both forms are quite standard, and there is no ambiguity between them. The matrix K𝐗𝐗 is also often called the variance-covariance matrix, since the diagonal terms are in fact variances. By comparison, the notation for the cross-covariance matrix between two vectors is cov(𝐗,𝐘)=K𝐗𝐘=E[(𝐗−E[𝐗])(𝐘−E[𝐘])𝖳].
Properties
Relation to the autocorrelation matrix The auto-covariance matrix K𝐗𝐗 is related to the autocorrelation matrix R𝐗𝐗 by K𝐗𝐗=E[(𝐗−E[𝐗])(𝐗−E[𝐗])𝖳]=R𝐗𝐗−E[𝐗]E[𝐗]𝖳 where the autocorrelation matrix is defined as R𝐗𝐗=E[𝐗𝐗𝖳].
Relation to the correlation matrix
An entity closely related to the covariance matrix is the matrix of Pearson product-moment correlation coefficients between each of the random variables in the random vector 𝐗, which can be written as corr(𝐗)=(diag(K𝐗𝐗))−12K𝐗𝐗(diag(K𝐗𝐗))−12, where diag(K𝐗𝐗) is the matrix of the diagonal elements of K𝐗𝐗 (i.e., a diagonal matrix of the variances of Xi for i=1,…,n). Equivalently, the correlation matrix can be seen as the covariance matrix of the standardized random variables Xi/σ(Xi) for i=1,…,n. corr(𝐗)=[1E[(X1−μ1)(X2−μ2)]σ(X1)σ(X2)⋯E[(X1−μ1)(Xn−μn)]σ(X1)σ(Xn)E[(X2−μ2)(X1−μ1)]σ(X2)σ(X1)1⋯E[(X2−μ2)(Xn−μn)]σ(X2)σ(Xn)⋮⋮⋱⋮E[(Xn−μn)(X1−μ1)]σ(Xn)σ(X1)E[(Xn−μn)(X2−μ2)]σ(Xn)σ(X2)⋯1]. Each element on the principal diagonal of a correlation matrix is the correlation of a random variable with itself, which always equals 1. Each off-diagonal element is between −1 and +1 inclusive.
Inverse of the covariance matrix The inverse of this matrix, K𝐗𝐗−1, if it exists, is the inverse covariance matrix, also known as the precision matrix (or concentration matrix). Just as the covariance matrix can be written as the rescaling of a correlation matrix by the marginal variances: cov(𝐗)=[σx10σx2⋱0σxn] ×[1ρx1,x2⋯ρx1,xnρx2,x11⋯ρx2,xn⋮⋮⋱⋮ρxn,x1ρxn,x2⋯1] ×[σx10σx2⋱0σxn] So, using the idea of partial correlation, and partial variance, the inverse covariance matrix can be expressed analogously: cov(𝐗)−1=[1σx1∣x2…01σx2∣x1,x3…⋱01σxn∣x1…xn−1] ×[1−ρx1,x2∣x3…⋯−ρx1,xn∣x2…xn−1−ρx2,x1∣x3…1⋯−ρx2,xn∣x1,x3…xn−1⋮⋮⋱⋮−ρxn,x1∣x2…xn−1−ρxn,x2∣x1,x3…xn−1⋯1] ×[1σx1∣x2…01σx2∣x1,x3…⋱01σxn∣x1…xn−1] This duality motivates a number of other dualities between marginalizing and conditioning for Gaussian random variables.
Basic properties For K𝐗𝐗=var(𝐗)=E[(𝐗−E[𝐗])(𝐗−E[𝐗])𝖳] and 𝝁𝐗=E[𝐗], where 𝐗=(X1,…,Xn)𝖳 is an n-dimensional random variable, the following basic properties apply:
K𝐗𝐗=E(𝐗𝐗𝖳)−𝝁𝐗𝝁𝐗𝖳 K𝐗𝐗 is positive-semidefinite, i.e. 𝐚TK𝐗𝐗𝐚≥0for all 𝐚∈ℝn
K𝐗𝐗 is symmetric, i.e. K𝐗𝐗𝖳=K𝐗𝐗 For any constant (i.e. non-random) m×n matrix 𝐀 and constant m×1 vector 𝐚, one has var(𝐀𝐗+𝐚)=𝐀var(𝐗)𝐀𝖳 If 𝐘 is another random vector with the same dimension as 𝐗, then var(𝐗+𝐘)=var(𝐗)+cov(𝐗,𝐘)+cov(𝐘,𝐗)+var(𝐘) where cov(𝐗,𝐘) is the cross-covariance matrix of 𝐗 and 𝐘.
Block matrices The joint mean 𝝁 and joint covariance matrix 𝜮 of 𝐗 and 𝐘 can be written in block form 𝝁=[𝝁X𝝁Y],𝜮=[K𝐗𝐗K𝐗𝐘K𝐘𝐗K𝐘𝐘] where K𝐗𝐗=var(𝐗), K𝐘𝐘=var(𝐘) and K𝐗𝐘=K𝐘𝐗𝖳=cov(𝐗,𝐘). K𝐗𝐗 and K𝐘𝐘 can be identified as the variance matrices of the marginal distributions for 𝐗 and 𝐘 respectively. If 𝐗 and 𝐘 are jointly normally distributed, 𝐗,𝐘∼ 𝒩(𝝁,𝜮), then the conditional distribution for 𝐘 given 𝐗 is given by 𝐘∣𝐗∼ 𝒩(𝝁𝐘|𝐗,K𝐘|𝐗), defined by conditional mean 𝝁𝐘|𝐗=𝝁𝐘+K𝐘𝐗K𝐗𝐗−1(𝐗−𝝁𝐗) and conditional variance K𝐘|𝐗=K𝐘𝐘−K𝐘𝐗K𝐗𝐗−1K𝐗𝐘. The matrix K𝐘𝐗K𝐗𝐗−1 is known as the matrix of regression coefficients, while in linear algebra K𝐘|𝐗 is the Schur complement of K𝐗𝐗 in 𝜮. The matrix of regression coefficients may often be given in transpose form, K𝐗𝐗−1K𝐗𝐘, suitable for post-multiplying a row vector of explanatory variables 𝐗𝖳 rather than pre-multiplying a column vector 𝐗. In this form they correspond to the coefficients obtained by inverting the matrix of the normal equations of ordinary least squares (OLS).
… excerpt ends here. Continue reading the full article.

![Covariance matrix: A bivariate Gaussian probability density function centered at (0, 0), with covariance matrix given by
[10.50.51]](https://thumb.wikimedia.org/wikipedia/commons/thumb/c/c0/Gaussian-2d.png/330px-Gaussian-2d.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)


![Covariance matrix: Figure 1: Construction of a partial covariance map of N2 molecules undergoing Coulomb explosion induced by a free-electron laser.[13] Panels a and b map the two terms of the covariance matrix, which is shown in panel c. Panel d maps common-mode correlations via intensity fluctuations of the laser. Panel e maps the partial covariance matrix that is corrected for the intensity fluctuations. Panel f shows that 10% overcorrection improves the map and makes ion-ion correlations clearly visible. Owing to momentum conservation these correlations appear as lines approximately perpendicular to the autocorrelation line (and to the periodic modulations which are caused by detector ringing).](https://thumb.wikimedia.org/wikipedia/commons/thumb/c/ce/Stages_of_partial_covariance_mapping.png/500px-Stages_of_partial_covariance_mapping.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)