Skip to content
VibeFormer
Advanced30 min

The Multivariate Normal Distribution

Mean vectors and covariance matrices, contours of constant density, marginals and conditionals.

The Multivariate Normal Distribution

Intuition first

The multivariate normal extends the bell curve to several dimensions at once. Instead of a mean and a variance, it has a mean vector saying where the centre is and a covariance matrix saying how the dimensions vary and how they vary together.

Geometrically, the contours of constant density are ellipses (or ellipsoids). The covariance matrix determines their shape and orientation: equal variances and zero covariance give circles, unequal variances give axis-aligned ellipses, and non-zero covariance tilts them. Reading a covariance matrix as an ellipse is the single most useful mental image in multivariate statistics.

It matters out of proportion to its apparent narrowness because it is the only multivariate distribution that is genuinely tractable. Linear combinations stay normal, marginals are normal, conditionals are normal and their means are linear in the conditioning variables — which is exactly where linear regression comes from. PCA, LDA, Gaussian mixtures, Kalman filters and Gaussian processes all rest on this one distribution.

Definition

XNd(μ,Σ),f(x)=1(2π)d/2Σ1/2exp(12(xμ)TΣ1(xμ))\mathbf{X} \sim \mathcal{N}_d(\boldsymbol{\mu}, \Sigma), \qquad f(\mathbf{x}) = \frac{1}{(2\pi)^{d/2}\lvert\Sigma\rvert^{1/2}}\exp\left(-\frac{1}{2}(\mathbf{x}-\boldsymbol{\mu})^{\mathsf{T}}\Sigma^{-1}(\mathbf{x}-\boldsymbol{\mu})\right)
Notation used in this lesson
SymbolMeaning
μMean vector, d components
ΣCovariance matrix, d × d, symmetric positive definite
|Σ|Determinant — the generalised variance
Σ⁻¹Precision matrix
Squared Mahalanobis distance

Reading the covariance matrix

For two dimensions:

Σ=(σ12ρσ1σ2ρσ1σ2σ22)\Sigma = \begin{pmatrix} \sigma_1^2 & \rho\sigma_1\sigma_2 \\ \rho\sigma_1\sigma_2 & \sigma_2^2\end{pmatrix}
ρ = 0, σ₁ = σ₂ρ = 0, σ₁ > σ₂ρ = 0.8
Constant-density contours. Equal variances with zero covariance give circles; unequal variances give axis-aligned ellipses; non-zero covariance tilts them, with the tilt direction set by the sign of ρ.

The eigenvectors of Σ\Sigma give the ellipse axes and the eigenvalues their squared lengths. That is precisely what PCA computes: the principal components are the eigenvectors of the covariance matrix, ordered by how much variance each direction carries.

The three properties that make it tractable

Linear combinations stay normal. For any matrix AA and vector bb:

AX+bN(Aμ+b,  AΣAT)A\mathbf{X} + b \sim \mathcal{N}\big(A\boldsymbol{\mu} + b,\; A\Sigma A^{\mathsf{T}}\big)

Marginals are normal. Just pick out the relevant entries of μ\boldsymbol\mu and the corresponding block of Σ\Sigma — no integration required.

Conditionals are normal, with linear means. Partition X=(X1,X2)\mathbf{X} = (\mathbf{X}_1, \mathbf{X}_2):

X1X2=x2    N(μ1+Σ12Σ221(x2μ2),    Σ11Σ12Σ221Σ21)\mathbf{X}_1 \mid \mathbf{X}_2 = \mathbf{x}_2 \;\sim\; \mathcal{N}\Big(\boldsymbol{\mu}_1 + \Sigma_{12}\Sigma_{22}^{-1}(\mathbf{x}_2 - \boldsymbol{\mu}_2),\;\; \Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1}\Sigma_{21}\Big)
What the conditional formula is telling youAdvanced

Two features deserve attention.

The conditional mean is linear in x2\mathbf{x}_2. The coefficient matrix Σ12Σ221\Sigma_{12}\Sigma_{22}^{-1} is exactly the matrix of regression coefficients. In the bivariate case it reduces to

E[X1X2=x2]=μ1+ρσ1σ2(x2μ2)\E[X_1 \mid X_2 = x_2] = \mu_1 + \rho\frac{\sigma_1}{\sigma_2}(x_2 - \mu_2)

and ρσ1/σ2\rho\sigma_1/\sigma_2 is the familiar least-squares slope. So linear regression is the conditional mean of a multivariate normal. That is why linear regression is the right model when the joint distribution is normal, and why it is only an approximation otherwise.

The conditional variance does not depend on x2\mathbf{x}_2. The term Σ11Σ12Σ221Σ21\Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1}\Sigma_{21} — the Schur complement — is a constant. This is homoscedasticity, assumed by ordinary least squares, and here it is a consequence of joint normality rather than an extra assumption.

The conditional variance is also never larger than the marginal variance: conditioning on information can only reduce uncertainty, and the reduction is exactly ρ2\rho^2 of it in the bivariate case, since

σ122=σ12(1ρ2)\sigma_{1\mid 2}^2 = \sigma_1^2(1 - \rho^2)

That 1ρ21 - \rho^2 is the residual fraction of variance, so ρ2\rho^2 is the fraction explained — which is R2R^2.

Solved problem 1 · Bivariate normal: marginals, conditionals, and a probability

Heights (X1X_1, cm) and weights (X2X_2, kg) are bivariate normal with

μ=(17575),Σ=(646060144)\boldsymbol\mu = \begin{pmatrix}175 \\ 75\end{pmatrix}, \qquad \Sigma = \begin{pmatrix}64 & 60 \\ 60 & 144\end{pmatrix}

(a) Find the correlation. (b) Find the distribution of weight given height 185 cm. (c) Find P(weight>85height=185)\Prob(\text{weight} > 85 \mid \text{height} = 185).

Step 1 — part (a): extract the correlation

σ1=64=8,σ2=144=12\sigma_1 = \sqrt{64} = 8, \qquad \sigma_2 = \sqrt{144} = 12ρ=Covσ1σ2=608×12=6096=0.625\rho = \frac{\Cov}{\sigma_1\sigma_2} = \frac{60}{8 \times 12} = \frac{60}{96} = 0.625

Step 2 — part (b): the conditional mean

Using the bivariate form with X2X_2 as the target and X1X_1 as the conditioner:

E[X2X1=x1]=μ2+ρσ2σ1(x1μ1)\E[X_2 \mid X_1 = x_1] = \mu_2 + \rho\frac{\sigma_2}{\sigma_1}(x_1 - \mu_1)

The slope is

ρσ2σ1=0.625×128=0.625×1.5=0.9375 kg per cm\rho\frac{\sigma_2}{\sigma_1} = 0.625 \times \frac{12}{8} = 0.625 \times 1.5 = 0.9375 \text{ kg per cm}

At x1=185x_1 = 185:

E[X2X1=185]=75+0.9375(185175)=75+9.375=84.375 kg\E[X_2 \mid X_1 = 185] = 75 + 0.9375(185 - 175) = 75 + 9.375 = 84.375 \text{ kg}

Step 3 — the conditional variance

σ212=σ22(1ρ2)=144(10.6252)=144(10.390625)=144×0.609375=87.75\sigma_{2\mid 1}^2 = \sigma_2^2(1 - \rho^2) = 144\big(1 - 0.625^2\big) = 144(1 - 0.390625) = 144 \times 0.609375 = 87.75σ21=87.759.3675\sigma_{2\mid1} = \sqrt{87.75} \approx 9.3675

So

X2X1=185    N(84.375,  87.75)X_2 \mid X_1 = 185 \;\sim\; \mathcal{N}(84.375,\; 87.75)

Step 4 — part (c): standardise within the conditional

z=8584.3759.3675=0.6259.36750.06672z = \frac{85 - 84.375}{9.3675} = \frac{0.625}{9.3675} \approx 0.06672P(X2>85X1=185)=1Φ(0.0667)10.5266=0.4734\Prob(X_2 > 85 \mid X_1 = 185) = 1 - \Phi(0.0667) \approx 1 - 0.5266 = 0.4734

Step 5 — compare with the unconditional answer

Without knowing the height:

z=857512=0.8333P(X2>85)10.7977=0.2023z = \frac{85 - 75}{12} = 0.8333 \quad\Longrightarrow\quad \Prob(X_2 > 85) \approx 1 - 0.7977 = 0.2023

Knowing the person is 10 cm above average height more than doubles the probability that they exceed 85 kg, from 20% to 47%. Conditioning also cut the standard deviation from 12 to 9.37, a reduction of exactly 1ρ2=0.609=0.781\sqrt{1-\rho^2} = \sqrt{0.609} = 0.781.

Answer

(a) ρ=0.625\rho = 0.625; (b) N(84.375,  87.75)\mathcal{N}(84.375,\; 87.75) with SD 9.379.37; (c) 0.473\approx 0.473, against an unconditional 0.2020.202.

Independence and zero correlation coincide here

For general random variables, zero correlation does not imply independence. For jointly normal variables it does:

ρ=0    X1 ⁣ ⁣ ⁣X2(jointly normal only)\rho = 0 \iff X_1 \ind X_2 \qquad \text{(jointly normal only)}

Degenerate cases

If Σ\Sigma is singular the density does not exist, because Σ1\Sigma^{-1} and Σ1/2\lvert\Sigma\rvert^{-1/2} are undefined. This happens when one variable is an exact linear combination of others — the distribution then lives on a lower-dimensional subspace.

python
import numpy as np
from scipy import stats

mu = np.array([175.0, 75.0])
Sigma = np.array([[64.0, 60.0],
                  [60.0, 144.0]])

s1, s2 = np.sqrt(Sigma[0,0]), np.sqrt(Sigma[1,1])
rho = Sigma[0,1] / (s1 * s2)
print(f"rho {rho:.4f}   sigma1 {s1:.1f}  sigma2 {s2:.1f}")

# Conditional distribution of weight given height = 185.
x1 = 185.0
slope = Sigma[1,0] / Sigma[0,0]                 # = rho * s2/s1
cond_mu = mu[1] + slope * (x1 - mu[0])
cond_var = Sigma[1,1] - Sigma[1,0]**2 / Sigma[0,0]
print(f"\nslope {slope:.4f} kg/cm   cond mean {cond_mu:.4f}  cond var {cond_var:.4f}")
print(f"P(W > 85 | H = 185) {stats.norm.sf(85, cond_mu, np.sqrt(cond_var)):.4f}")
print(f"P(W > 85)           {stats.norm.sf(85, mu[1], s2):.4f}")

# Eigenstructure: the ellipse axes are the principal components.
vals, vecs = np.linalg.eigh(Sigma)
print(f"\neigenvalues {vals.round(3)}  (axis lengths squared)")
print(f"variance explained by PC1: {vals[-1]/vals.sum():.1%}")

# Verify by simulation, including the conditional slice.
rng = np.random.default_rng(0)
X = rng.multivariate_normal(mu, Sigma, 2_000_000)
band = np.abs(X[:,0] - 185) < 0.25
print(f"\nempirical cond mean {X[band,1].mean():.4f}  sd {X[band,1].std():.4f}")
print(f"theory              {cond_mu:.4f}       {np.sqrt(cond_var):.4f}")

# Mahalanobis distance is chi-squared with d degrees of freedom.
diff = X - mu
d2 = np.einsum('ij,jk,ik->i', diff, np.linalg.inv(Sigma), diff)
print(f"\nMahalanobis²: mean {d2.mean():.4f} (theory 2)  "
      f"95th pct {np.percentile(d2, 95):.4f} (chi2(2) {stats.chi2.ppf(0.95, 2):.4f})")

That final check is worth knowing: d2χd2d^2 \sim \chi^2_d, which is how you set a principled multivariate outlier threshold rather than eyeballing one per dimension.

Exercise 1

XN2 ⁣((00),(4229))\mathbf{X} \sim \mathcal{N}_2\!\left(\begin{pmatrix}0\\0\end{pmatrix}, \begin{pmatrix}4 & 2\\ 2 & 9\end{pmatrix}\right). Find the distribution of Y=2X1X2Y = 2X_1 - X_2.

Show solution

Write Y=AXY = A\mathbf{X} with A=(2,1)A = (2, -1), a 1×21 \times 2 matrix. Linear combinations of a multivariate normal are normal, so YY is univariate normal.

Mean:

E[Y]=Aμ=2(0)1(0)=0\E[Y] = A\boldsymbol\mu = 2(0) - 1(0) = 0

Variance:

Var(Y)=AΣAT=(21)(4229)(21)\Var(Y) = A\Sigma A^{\mathsf{T}} = \begin{pmatrix}2 & -1\end{pmatrix}\begin{pmatrix}4 & 2\\2&9\end{pmatrix}\begin{pmatrix}2\\-1\end{pmatrix}

First multiply ΣAT\Sigma A^{\mathsf T}:

(4229)(21)=(8249)=(65)\begin{pmatrix}4 & 2\\2&9\end{pmatrix}\begin{pmatrix}2\\-1\end{pmatrix} = \begin{pmatrix}8 - 2\\ 4 - 9\end{pmatrix} = \begin{pmatrix}6\\-5\end{pmatrix}

Then:

(21)(65)=12+5=17\begin{pmatrix}2 & -1\end{pmatrix}\begin{pmatrix}6\\-5\end{pmatrix} = 12 + 5 = 17

So YN(0,17)Y \sim \mathcal{N}(0, 17).

Check against the scalar formula:

Var(2X1X2)=4Var(X1)+Var(X2)4Cov(X1,X2)=16+98=17  \Var(2X_1 - X_2) = 4\Var(X_1) + \Var(X_2) - 4\Cov(X_1,X_2) = 16 + 9 - 8 = 17 \;\checkmark

Note the positive covariance reduced the variance of the difference — the two variables move together, so subtracting cancels part of the shared fluctuation.

Exercise 2

Explain why Mahalanobis distance is preferred to Euclidean distance for detecting multivariate outliers.

Show solution

Euclidean distance treats all directions as equivalent and ignores both scale and correlation. Mahalanobis distance,

d2=(xμ)TΣ1(xμ)d^2 = (\mathbf{x} - \boldsymbol\mu)^{\mathsf T}\Sigma^{-1}(\mathbf{x} - \boldsymbol\mu)

corrects for both.

Scale. With height in centimetres (SD 8) and weight in kilograms (SD 12), a Euclidean distance adds centimetres to kilograms — meaningless, and dominated by whichever variable happens to have larger units. Change height to metres and the answer changes completely. Mahalanobis divides each direction by its standard deviation, making it unit-free.

Correlation. With ρ=0.625\rho = 0.625, a person 10 cm taller and 9 kg heavier than average is entirely typical, since that is precisely the pattern the correlation predicts. A person 10 cm taller and 9 kg lighter is unusual. Both points are the same Euclidean distance from the mean. Mahalanobis distance, via Σ1\Sigma^{-1}, knows the ellipse is tilted and gives the second point a much larger value.

It has a calibrated threshold. For multivariate normal data, d2χd2d^2 \sim \chi^2_d, so the 95th percentile of χd2\chi^2_d is a principled cut-off. Euclidean distance has no such reference distribution, leaving the threshold arbitrary.

The practical caveat: Σ\Sigma must be estimated, and the sample covariance is itself distorted by outliers — the very things being detected. Robust estimators such as the minimum covariance determinant exist for this reason.


That completes the distributions in this module. Next: Statistics and Inference, which uses all of this to reason from samples back to populations.