Reference sheet

Multivariate statistics reference

The main definitions, formulas and conditions of multivariate statistical analysis on one page, from mean vectors and the multivariate normal to classification and clustering.

Each section starts with the big idea in a few sentences, then gives the results you will look up most often, with the conditions they need.

Bold lowercase letters are vectors and bold capitals are matrices. A bold capital such as X\mathbf X can also be a random vector, and ρ\boldsymbol\rho is the correlation matrix. A prime means transpose, ∣A∣\lvert \mathbf A \rvert is a determinant and tr⁡(A)\operatorname{tr}(\mathbf A) a trace. Critical values are upper percentiles, so Fa,b(α)F_{a,b}(\alpha), tν(α)t_\nu(\alpha) and χν2(α)\chi^2_\nu(\alpha) each leave probability α\alpha to their right. Unless a section says otherwise, pp is the number of variables and nn the number of observations.

Describing multivariate data

With several variables measured on each item, one mean and one variance are no longer enough. The data are summarized by a mean vector and a covariance matrix, and most of the course is about what these two objects can tell you.

The data matrix and its summaries

Measuring pp variables on nn items gives an n×pn \times p data matrix X\mathbf X. Row jj is the observation xj′\mathbf x_j', and xjkx_{jk} is the value of variable kk on item jj.

QuantityFormula
Sample mean vectorxˉ=1n∑j=1nxj\bar{\mathbf x} = \frac{1}{n}\sum_{j=1}^n \mathbf x_j
Sample covariance matrixS=1n−1∑j=1n(xj−xˉ)(xj−xˉ)′\mathbf S = \frac{1}{n-1}\sum_{j=1}^n (\mathbf x_j - \bar{\mathbf x})(\mathbf x_j - \bar{\mathbf x})'
Sample correlationrik=siksii skkr_{ik} = \dfrac{s_{ik}}{\sqrt{s_{ii}\,s_{kk}}}, collected in the matrix R\mathbf R
Generalized variance∣S∣\lvert \mathbf S \rvert, the product of the eigenvalues of S\mathbf S
Total variancetr⁡(S)=s11+⋯+spp\operatorname{tr}(\mathbf S) = s_{11} + \cdots + s_{pp}, the sum of the eigenvalues of S\mathbf S

The divisor n−1n - 1 makes S\mathbf S unbiased. The generalized variance is zero exactly when some combination of the variables has no spread in the sample, which always happens when n≤pn \le p.

Population quantities

For a random vector X=(X1,…,Xp)′\mathbf X = (X_1, \dots, X_p)', the mean vector is μ=E(X)\boldsymbol\mu = E(\mathbf X) and the covariance matrix is

Σ=E[(X−μ)(X−μ)′],\boldsymbol\Sigma = E\big[(\mathbf X - \boldsymbol\mu)(\mathbf X - \boldsymbol\mu)'\big],

with σik=Cov⁡(Xi,Xk)\sigma_{ik} = \operatorname{Cov}(X_i, X_k) off the diagonal and the variances σii\sigma_{ii} on it. The correlation matrix ρ\boldsymbol\rho has entries ρik=σik/σiiσkk\rho_{ik} = \sigma_{ik}/\sqrt{\sigma_{ii}\sigma_{kk}}. The covariance matrix is symmetric and positive semidefinite, and positive definite unless some nontrivial combination of the variables has zero variance.

Linear combinations

Most methods in the course work by forming combinations of the variables, so these rules come up everywhere. For constant vectors b\mathbf b and c\mathbf c and a constant matrix C\mathbf C,

QuantityPopulationSample
Mean of c′X\mathbf c'\mathbf Xc′μ\mathbf c'\boldsymbol\muc′xˉ\mathbf c'\bar{\mathbf x}
Variance of c′X\mathbf c'\mathbf Xc′Σc\mathbf c'\boldsymbol\Sigma\mathbf cc′Sc\mathbf c'\mathbf S\mathbf c
Covariance of b′X\mathbf b'\mathbf X and c′X\mathbf c'\mathbf Xb′Σc\mathbf b'\boldsymbol\Sigma\mathbf cb′Sc\mathbf b'\mathbf S\mathbf c
Mean vector of CX\mathbf C\mathbf XCμ\mathbf C\boldsymbol\muCxˉ\mathbf C\bar{\mathbf x}
Covariance matrix of CX\mathbf C\mathbf XCΣC′\mathbf C\boldsymbol\Sigma\mathbf C'CSC′\mathbf C\mathbf S\mathbf C'

See also Linear algebra refresher for eigenvalues, quadratic forms and positive definite matrices

The multivariate normal

The multivariate normal plays the role the bell curve plays for one variable. It is described completely by μ\boldsymbol\mu and Σ\boldsymbol\Sigma, its contours are ellipsoids, and almost every exact test in the course assumes it.

Density and contours

A random vector X∼Np(μ,Σ)\mathbf X \sim N_p(\boldsymbol\mu, \boldsymbol\Sigma) with Σ\boldsymbol\Sigma positive definite has density

f(x)=1(2π)p/2 ∣Σ∣1/2 exp⁡ ⁣(−12(x−μ)′Σ−1(x−μ)).f(\mathbf x) = \frac{1}{(2\pi)^{p/2}\,\lvert \boldsymbol\Sigma \rvert^{1/2}}\, \exp\!\left(-\frac{1}{2}(\mathbf x - \boldsymbol\mu)'\boldsymbol\Sigma^{-1}(\mathbf x - \boldsymbol\mu)\right).

The density is constant on the ellipsoids (x−μ)′Σ−1(x−μ)=c2(\mathbf x - \boldsymbol\mu)'\boldsymbol\Sigma^{-1}(\mathbf x - \boldsymbol\mu) = c^2. If Σei=λiei\boldsymbol\Sigma\mathbf e_i = \lambda_i\mathbf e_i with unit eigenvectors ei\mathbf e_i, the axes of the ellipsoid point along the ei\mathbf e_i with half lengths cλic\sqrt{\lambda_i}. With c2=χp2(α)c^2 = \chi^2_p(\alpha) the ellipsoid holds probability 1−α1 - \alpha.

See also Covariance explorer to see how the ellipse changes with the covariance matrix in two dimensions

Key properties

If X∼Np(μ,Σ)\mathbf X \sim N_p(\boldsymbol\mu, \boldsymbol\Sigma), then

  • every linear combination is normal, with a′X∼N(a′μ, a′Σa)\mathbf a'\mathbf X \sim N(\mathbf a'\boldsymbol\mu,\ \mathbf a'\boldsymbol\Sigma\mathbf a), and more generally AX+d∼Nq(Aμ+d, AΣA′)\mathbf A\mathbf X + \mathbf d \sim N_q(\mathbf A\boldsymbol\mu + \mathbf d,\ \mathbf A\boldsymbol\Sigma\mathbf A') for a constant q×pq \times p matrix A\mathbf A
  • every subset of the variables is normal
  • two blocks of variables are independent exactly when their cross covariance is 0\mathbf 0, which relies on joint normality
  • when Σ\boldsymbol\Sigma is positive definite, the squared distance (X−μ)′Σ−1(X−μ)(\mathbf X - \boldsymbol\mu)'\boldsymbol\Sigma^{-1}(\mathbf X - \boldsymbol\mu) has a χp2\chi^2_p distribution

Conditional distributions. Split X\mathbf X into blocks X(1)\mathbf X^{(1)} and X(2)\mathbf X^{(2)}, with μ\boldsymbol\mu and Σ\boldsymbol\Sigma split to match, and suppose Σ22\boldsymbol\Sigma_{22} is invertible. Given X(2)=x(2)\mathbf X^{(2)} = \mathbf x^{(2)}, the block X(1)\mathbf X^{(1)} is normal with

mean μ(1)+Σ12Σ22−1(x(2)−μ(2)),covariance Σ11−Σ12Σ22−1Σ21.\begin{aligned} \text{mean } &\boldsymbol\mu^{(1)} + \boldsymbol\Sigma_{12}\boldsymbol\Sigma_{22}^{-1}(\mathbf x^{(2)} - \boldsymbol\mu^{(2)}), \\[0.6em] \text{covariance } &\boldsymbol\Sigma_{11} - \boldsymbol\Sigma_{12}\boldsymbol\Sigma_{22}^{-1}\boldsymbol\Sigma_{21}. \end{aligned}

The conditional mean is linear in x(2)\mathbf x^{(2)}, which is the link to regression, and the conditional covariance does not depend on x(2)\mathbf x^{(2)} at all.

Mahalanobis distance and checking normality

The Mahalanobis distance measures how far x\mathbf x is from μ\boldsymbol\mu in standard deviation units, taking the correlations into account,

d(x,μ)=(x−μ)′Σ−1(x−μ).d(\mathbf x, \boldsymbol\mu) = \sqrt{(\mathbf x - \boldsymbol\mu)'\boldsymbol\Sigma^{-1}(\mathbf x - \boldsymbol\mu)}.

Points on the same density contour are at the same distance. To check a sample for normality, compute dj2=(xj−xˉ)′S−1(xj−xˉ)d_j^2 = (\mathbf x_j - \bar{\mathbf x})'\mathbf S^{-1}(\mathbf x_j - \bar{\mathbf x}) for every observation and plot the ordered values against χp2\chi^2_p quantiles. For normal data the points lie close to a straight line.

Sampling distributions

For a random sample of size nn from Np(μ,Σ)N_p(\boldsymbol\mu, \boldsymbol\Sigma),

ResultStatement
Sample meanXˉ∼Np(μ,1nΣ)\bar{\mathbf X} \sim N_p\left(\boldsymbol\mu, \frac{1}{n}\boldsymbol\Sigma\right)
Sample covariance(n−1)S(n-1)\mathbf S has a Wishart distribution Wn−1(Σ)W_{n-1}(\boldsymbol\Sigma)
IndependenceXˉ\bar{\mathbf X} and S\mathbf S are independent
Maximum likelihoodμ^=Xˉ\hat{\boldsymbol\mu} = \bar{\mathbf X} and Σ^=n−1nS\hat{\boldsymbol\Sigma} = \frac{n-1}{n}\mathbf S

Without normality, but with Σ\boldsymbol\Sigma positive definite and n−pn - p large, n (Xˉ−μ)\sqrt n\,(\bar{\mathbf X} - \boldsymbol\mu) is approximately Np(0,Σ)N_p(\mathbf 0, \boldsymbol\Sigma) and n(Xˉ−μ)′S−1(Xˉ−μ)n(\bar{\mathbf X} - \boldsymbol\mu)'\mathbf S^{-1}(\bar{\mathbf X} - \boldsymbol\mu) is approximately χp2\chi^2_p. This is what makes the large sample tests below work.

Inference about mean vectors

Testing several means at once is not the same as running a separate tt test for each variable. Hotelling’s T2T^2 does it in one step, accounts for the correlations, and keeps the overall error rate at the level you choose.

Hotelling’s T² for one mean vector

To test H0H_0 that μ=μ0\boldsymbol\mu = \boldsymbol\mu_0, with a random sample from Np(μ,Σ)N_p(\boldsymbol\mu, \boldsymbol\Sigma) and n>pn > p, compute

T2=n(xˉ−μ0)′S−1(xˉ−μ0)T^2 = n(\bar{\mathbf x} - \boldsymbol\mu_0)'\mathbf S^{-1}(\bar{\mathbf x} - \boldsymbol\mu_0)

and reject at level α\alpha when

T2>(n−1)pn−p Fp, n−p(α).T^2 > \frac{(n-1)p}{n-p}\,F_{p,\,n-p}(\alpha).

For one variable, T2T^2 is the square of the usual tt statistic. The test gives the same answer whatever units the variables are measured in, and it agrees with the likelihood ratio test. The 100(1−α)%100(1 - \alpha)\% confidence region for μ\boldsymbol\mu is the ellipsoid of all μ\boldsymbol\mu that this test would not reject.

Simultaneous confidence intervals

After a test, you usually want intervals for individual means or combinations a′μ\mathbf a'\boldsymbol\mu that all hold together. Each interval below has the form a′xˉ±(multiplier)×a′Sa/n\mathbf a'\bar{\mathbf x} \pm (\text{multiplier}) \times \sqrt{\mathbf a'\mathbf S\mathbf a / n}.

MethodMultiplierUse it when
T2T^2 intervalsp(n−1)n−p Fp, n−p(α)\sqrt{\dfrac{p(n-1)}{n-p}\,F_{p,\,n-p}(\alpha)}you want any combinations, even ones chosen after seeing the data
Bonferronitn−1 ⁣(α2m)t_{n-1}\!\left(\dfrac{\alpha}{2m}\right)you fix mm combinations in advance, which gives shorter intervals when mm is small
Large sampleχp2(α)\sqrt{\chi^2_p(\alpha)}n−pn - p is large and normality is in doubt

For a single mean μk\mu_k, take a\mathbf a with a one in place kk and zeros elsewhere, so the interval is centred at xˉk\bar x_k with skk/n\sqrt{s_{kk}/n} in place of a′Sa/n\sqrt{\mathbf a'\mathbf S\mathbf a/n}.

Paired and repeated measures

When each unit receives both treatments, work with the differences dj=x1j−x2j\mathbf d_j = \mathbf x_{1j} - \mathbf x_{2j} and run the one sample test of δ=0\boldsymbol\delta = \mathbf 0 on them, using dˉ\bar{\mathbf d} and Sd\mathbf S_d.

When each unit receives qq treatments, choose a (q−1)×q(q-1) \times q matrix C\mathbf C of linearly independent contrasts and test H0H_0 that Cμ=0\mathbf C\boldsymbol\mu = \mathbf 0 with

T2=n(Cxˉ)′(CSC′)−1Cxˉ,T^2 = n(\mathbf C\bar{\mathbf x})'(\mathbf C\mathbf S\mathbf C')^{-1}\mathbf C\bar{\mathbf x},

rejecting when

T2>(n−1)(q−1)n−q+1 Fq−1, n−q+1(α).T^2 > \frac{(n-1)(q-1)}{n-q+1}\,F_{q-1,\,n-q+1}(\alpha).

Comparing two mean vectors

Take independent samples of sizes n1n_1 and n2n_2 from Np(μ1,Σ)N_p(\boldsymbol\mu_1, \boldsymbol\Sigma) and Np(μ2,Σ)N_p(\boldsymbol\mu_2, \boldsymbol\Sigma), so both populations share one covariance matrix. Pool the two estimates,

Spooled=(n1−1)S1+(n2−1)S2n1+n2−2,\mathbf S_{\text{pooled}} = \frac{(n_1 - 1)\mathbf S_1 + (n_2 - 1)\mathbf S_2}{n_1 + n_2 - 2},

and test H0H_0 that μ1=μ2\boldsymbol\mu_1 = \boldsymbol\mu_2 with

T2=(xˉ1−xˉ2)′[(1n1+1n2)Spooled]−1(xˉ1−xˉ2).T^2 = (\bar{\mathbf x}_1 - \bar{\mathbf x}_2)'\left[\left(\frac{1}{n_1} + \frac{1}{n_2}\right)\mathbf S_{\text{pooled}}\right]^{-1}(\bar{\mathbf x}_1 - \bar{\mathbf x}_2).

Reject when

T2>(n1+n2−2)pn1+n2−p−1 Fp, n1+n2−p−1(α).T^2 > \frac{(n_1 + n_2 - 2)p}{n_1 + n_2 - p - 1}\,F_{p,\,n_1 + n_2 - p - 1}(\alpha).

If the covariance matrices differ but n1−pn_1 - p and n2−pn_2 - p are both large, replace the bracket by 1n1S1+1n2S2\frac{1}{n_1}\mathbf S_1 + \frac{1}{n_2}\mathbf S_2 and compare T2T^2 with χp2(α)\chi^2_p(\alpha).

MANOVA

MANOVA extends the two sample comparison to gg groups, in the same way that analysis of variance extends the tt test. It splits the total variation into a part between the groups and a part within them, and asks whether the first is large compared with the second.

Model and the two matrices

Group ℓ\ell gives a sample of size nℓn_\ell, with n=n1+⋯+ngn = n_1 + \cdots + n_g. The observations are independent and normal with group means μℓ\boldsymbol\mu_\ell and a common covariance matrix Σ\boldsymbol\Sigma. The null hypothesis H0H_0 is that all group means are equal.

MatrixFormulaDegrees of freedom
Between groupsB=∑ℓnℓ(xˉℓ−xˉ)(xˉℓ−xˉ)′\mathbf B = \sum_{\ell} n_\ell(\bar{\mathbf x}_\ell - \bar{\mathbf x})(\bar{\mathbf x}_\ell - \bar{\mathbf x})'g−1g - 1
Within groupsW=∑ℓ(nℓ−1)Sℓ\mathbf W = \sum_{\ell} (n_\ell - 1)\mathbf S_\elln−gn - g
TotalB+W\mathbf B + \mathbf Wn−1n - 1

Here xˉℓ\bar{\mathbf x}_\ell is the mean of group ℓ\ell and xˉ\bar{\mathbf x} the mean of all nn observations.

Wilks’ lambda and the other test statistics

The usual statistic is Wilks’ lambda,

Λ∗=∣W∣∣B+W∣,\Lambda^* = \frac{\lvert \mathbf W \rvert}{\lvert \mathbf B + \mathbf W \rvert},

which needs n−g≥pn - g \ge p so that W\mathbf W is invertible. It lies between 0 and 1, and small values mean the group means are far apart compared with the spread inside the groups. For large nn, reject H0H_0 when

−(n−1−p+g2)ln⁡Λ∗>χp(g−1)2(α).-\left(n - 1 - \frac{p + g}{2}\right)\ln\Lambda^* > \chi^2_{p(g-1)}(\alpha).

Software also reports Pillai’s trace, the Lawley-Hotelling trace and Roy’s largest root. All four are built from the eigenvalues of W−1B\mathbf W^{-1}\mathbf B, and in large samples they usually agree. Some small cases have exact FF distributions under H0H_0.

CaseStatisticDistribution
p=1p = 1(n−gg−1)(1−Λ∗Λ∗)\left(\dfrac{n-g}{g-1}\right)\left(\dfrac{1-\Lambda^*}{\Lambda^*}\right)Fg−1, n−gF_{g-1,\,n-g}
p=2p = 2(n−g−1g−1)(1−Λ∗Λ∗)\left(\dfrac{n-g-1}{g-1}\right)\left(\dfrac{1-\sqrt{\Lambda^*}}{\sqrt{\Lambda^*}}\right)F2(g−1), 2(n−g−1)F_{2(g-1),\,2(n-g-1)}
g=2g = 2(n−p−1p)(1−Λ∗Λ∗)\left(\dfrac{n-p-1}{p}\right)\left(\dfrac{1-\Lambda^*}{\Lambda^*}\right)Fp, n−p−1F_{p,\,n-p-1}
g=3g = 3(n−p−2p)(1−Λ∗Λ∗)\left(\dfrac{n-p-2}{p}\right)\left(\dfrac{1-\sqrt{\Lambda^*}}{\sqrt{\Lambda^*}}\right)F2p, 2(n−p−2)F_{2p,\,2(n-p-2)}

Which means differ

After a rejection, Bonferroni intervals for every variable ii and every pair of groups kk and ℓ\ell are

xˉki−xˉℓi±tn−g ⁣(αpg(g−1))wiin−g(1nk+1nℓ),\bar x_{ki} - \bar x_{\ell i} \pm t_{n-g}\!\left(\frac{\alpha}{pg(g-1)}\right)\sqrt{\frac{w_{ii}}{n-g}\left(\frac{1}{n_k} + \frac{1}{n_\ell}\right)},

where wiiw_{ii} is the iith diagonal entry of W\mathbf W. All of them hold together with probability at least 1−α1 - \alpha.

Principal components

Principal components replace the original variables with new uncorrelated ones, ordered from most to least variance. When a few of them carry most of the variance, they give a simpler description of the data with little lost.

The components

Let Σ\boldsymbol\Sigma have eigenvalues λ1≥λ2≥⋯≥λp≥0\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_p \ge 0 with orthonormal eigenvectors e1,…,ep\mathbf e_1, \dots, \mathbf e_p. The iith principal component is Yi=ei′XY_i = \mathbf e_i'\mathbf X.

PropertyFormula
VarianceVar⁡(Yi)=λi\operatorname{Var}(Y_i) = \lambda_i
UncorrelatedCov⁡(Yi,Yk)=0\operatorname{Cov}(Y_i, Y_k) = 0 for i≠ki \ne k
Total varianceσ11+⋯+σpp=λ1+⋯+λp\sigma_{11} + \cdots + \sigma_{pp} = \lambda_1 + \cdots + \lambda_p
Share explained by YkY_kλkλ1+⋯+λp\dfrac{\lambda_k}{\lambda_1 + \cdots + \lambda_p}
Correlation of YiY_i with XkX_keikλiσkk\dfrac{e_{ik}\sqrt{\lambda_i}}{\sqrt{\sigma_{kk}}}

The first component has the largest variance of all combinations a′X\mathbf a'\mathbf X with a′a=1\mathbf a'\mathbf a = 1, and each later one has the largest variance among those uncorrelated with the earlier ones. For a multivariate normal, the eigenvectors are the axes of the density ellipsoids.

Standardized variables and sample components

When the variables are in different units or have very different variances, standardize first and use the eigenpairs of the correlation matrix ρ\boldsymbol\rho. The total variance is then pp, so component kk explains the share λk/p\lambda_k/p. Components from Σ\boldsymbol\Sigma and from ρ\boldsymbol\rho differ in general.

In a sample, use the eigenpairs (λ^i,e^i)(\hat\lambda_i, \hat{\mathbf e}_i) of S\mathbf S, or of R\mathbf R for standardized data. The score of observation jj on component ii is e^i′(xj−xˉ)\hat{\mathbf e}_i'(\mathbf x_j - \bar{\mathbf x}). Scores on component ii have sample variance λ^i\hat\lambda_i, and scores on different components are uncorrelated.

How many to keep

  • Cumulative share. Keep enough components to explain a chosen share of the total variance, often around 80 to 90 percent.
  • Scree plot. Plot λ^i\hat\lambda_i against ii and stop at the elbow, where the remaining eigenvalues are small and similar.
  • Eigenvalues above 1. With R\mathbf R, a common rule of thumb keeps the components that explain more than one standardized variable, those with λ^i>1\hat\lambda_i > 1.
  • Interpretation. A component you cannot interpret or use is rarely worth keeping.

See also Linear algebra refresher for eigenvalues and the spectral decomposition

Factor analysis

Factor analysis explains the correlations among many observed variables through a few unobserved common factors. Where principal components summarize variance, factor analysis models covariance.

The model

With m<pm < p common factors,

X−μ=LF+ε,\mathbf X - \boldsymbol\mu = \mathbf L\mathbf F + \boldsymbol\varepsilon,

where L\mathbf L is the p×mp \times m matrix of loadings, F\mathbf F holds the common factors and ε\boldsymbol\varepsilon the specific factors. The factors have mean 0\mathbf 0 with Cov⁡(F)=I\operatorname{Cov}(\mathbf F) = \mathbf I, the specific factors have the diagonal covariance matrix Ψ\boldsymbol\Psi, and F\mathbf F and ε\boldsymbol\varepsilon are uncorrelated. The model implies

Σ=LL′+Ψ.\boldsymbol\Sigma = \mathbf L\mathbf L' + \boldsymbol\Psi.

So each variance splits as σii=hi2+ψi\sigma_{ii} = h_i^2 + \psi_i. The communality hi2=ℓi12+⋯+ℓim2h_i^2 = \ell_{i1}^2 + \cdots + \ell_{im}^2 is the part explained by the common factors, and the specific variance ψi\psi_i is the rest. The loading ℓij\ell_{ij} is also the covariance of XiX_i with factor jj.

Estimation

Principal component method. With (λ^i,e^i)(\hat\lambda_i, \hat{\mathbf e}_i) the eigenpairs of S\mathbf S or R\mathbf R, the loadings for factor jj are λ^j e^j\sqrt{\hat\lambda_j}\,\hat{\mathbf e}_j, and each specific variance is the diagonal entry of S\mathbf S minus the communality. Factor jj explains the share λ^j/(s11+⋯+spp)\hat\lambda_j / (s_{11} + \cdots + s_{pp}) of the total sample variance, or λ^j/p\hat\lambda_j / p with R\mathbf R.

Maximum likelihood. Assuming normality, maximize the likelihood over L\mathbf L and Ψ\boldsymbol\Psi. This also gives a large sample test of whether mm factors are enough. Reject at level α\alpha when

(n−1−2p+4m+56)ln⁡∣L^L^′+Ψ^∣∣Sn∣>χν2(α),ν=(p−m)2−p−m2,\left(n - 1 - \frac{2p + 4m + 5}{6}\right)\ln\frac{\lvert \hat{\mathbf L}\hat{\mathbf L}' + \hat{\boldsymbol\Psi} \rvert}{\lvert \mathbf S_n \rvert} > \chi^2_\nu(\alpha), \qquad \nu = \frac{(p - m)^2 - p - m}{2},

where Sn=n−1nS\mathbf S_n = \frac{n-1}{n}\mathbf S. The test needs nn and n−pn - p large and ν>0\nu > 0.

Rotation

Loadings are not unique. For any orthogonal m×mm \times m matrix T\mathbf T, the rotated loadings LT\mathbf L\mathbf T reproduce the same Σ\boldsymbol\Sigma, the same communalities and the same Ψ\boldsymbol\Psi. Rotation uses this freedom to make the factors easier to read. Varimax, the most common choice, pushes each loading toward 0 or toward a large value, so each factor ends up with a few clearly large loadings.

Classification

Classification assigns a new item to one of several known groups from its measurements. The best rule weighs how likely the measurements are in each group, how common each group is, and how costly each kind of mistake is.

The optimal rule

For two populations π1\pi_1 and π2\pi_2 with densities f1f_1 and f2f_2, prior probabilities p1p_1 and p2p_2, and misclassification costs c(1∣2)c(1 \mid 2) and c(2∣1)c(2 \mid 1), the rule with the smallest expected cost assigns x0\mathbf x_0 to π1\pi_1 when

f1(x0)f2(x0)≥c(1∣2)c(2∣1)⋅p2p1,\frac{f_1(\mathbf x_0)}{f_2(\mathbf x_0)} \ge \frac{c(1 \mid 2)}{c(2 \mid 1)} \cdot \frac{p_2}{p_1},

and to π2\pi_2 otherwise. Here c(1∣2)c(1 \mid 2) is the cost of putting an item from π2\pi_2 into π1\pi_1. With equal costs and priors, x0\mathbf x_0 simply goes to the population with the larger density there. With gg populations and equal costs, choose the population with the largest pkfk(x)p_k f_k(\mathbf x), which is the largest posterior probability.

Normal populations

If the populations are Np(μi,Σi)N_p(\boldsymbol\mu_i, \boldsymbol\Sigma_i), the rule takes one of two forms. With equal costs, assign x\mathbf x to the population with the largest score.

CovariancesScore di(x)d_i(\mathbf x)Shape of the boundary
Equal, Σi=Σ\boldsymbol\Sigma_i = \boldsymbol\Sigmaμi′Σ−1x−12μi′Σ−1μi+ln⁡pi\boldsymbol\mu_i'\boldsymbol\Sigma^{-1}\mathbf x - \frac{1}{2}\boldsymbol\mu_i'\boldsymbol\Sigma^{-1}\boldsymbol\mu_i + \ln p_ilinear
Unequal−12ln⁡∣Σi∣−12(x−μi)′Σi−1(x−μi)+ln⁡pi-\frac{1}{2}\ln\lvert \boldsymbol\Sigma_i \rvert - \frac{1}{2}(\mathbf x - \boldsymbol\mu_i)'\boldsymbol\Sigma_i^{-1}(\mathbf x - \boldsymbol\mu_i) + \ln p_iquadratic

In practice replace μi\boldsymbol\mu_i by xˉi\bar{\mathbf x}_i, and Σ\boldsymbol\Sigma by Spooled\mathbf S_{\text{pooled}} or Σi\boldsymbol\Sigma_i by Si\mathbf S_i. The quadratic rule needs each Si\mathbf S_i to be invertible, so ni>pn_i > p, and it is more sensitive to departures from normality.

Fisher’s linear discriminant

Fisher looked for the combination y=a′xy = \mathbf a'\mathbf x that separates two samples best relative to the spread within them, without assuming normality. The best choice is

a^=Spooled−1(xˉ1−xˉ2),\hat{\mathbf a} = \mathbf S_{\text{pooled}}^{-1}(\bar{\mathbf x}_1 - \bar{\mathbf x}_2),

and a new item goes to π1\pi_1 when a^′x0\hat{\mathbf a}'\mathbf x_0 is at least the midpoint of a^′xˉ1\hat{\mathbf a}'\bar{\mathbf x}_1 and a^′xˉ2\hat{\mathbf a}'\bar{\mathbf x}_2. This is the same rule as the normal rule with equal covariances, costs and priors. The separation it achieves is the squared Mahalanobis distance between the sample means,

D2=(xˉ1−xˉ2)′Spooled−1(xˉ1−xˉ2).D^2 = (\bar{\mathbf x}_1 - \bar{\mathbf x}_2)'\mathbf S_{\text{pooled}}^{-1}(\bar{\mathbf x}_1 - \bar{\mathbf x}_2).

Judging a rule

The apparent error rate, the share of the training items the rule gets wrong, is too optimistic because the rule is judged on the data that built it. Leave-one-out cross-validation is fairer. Hold out one item, build the rule from the rest, classify the held-out item, and repeat for every item. The share misclassified this way is a nearly unbiased estimate of the error rate on new data.

Canonical correlation

Canonical correlation measures the association between two sets of variables, such as test scores and later performance. It finds the combinations of the two sets that are most strongly correlated with each other, then the next best pair, and so on.

Canonical variates

Split the variables into X(1)\mathbf X^{(1)} with pp entries and X(2)\mathbf X^{(2)} with qq entries, p≤qp \le q, with covariance blocks Σ11\boldsymbol\Sigma_{11}, Σ22\boldsymbol\Sigma_{22} positive definite and cross covariance Σ12\boldsymbol\Sigma_{12}. The first canonical pair U1=a′X(1)U_1 = \mathbf a'\mathbf X^{(1)} and V1=b′X(2)V_1 = \mathbf b'\mathbf X^{(2)} maximizes

Corr⁡(U,V)=a′Σ12ba′Σ11a b′Σ22b,\operatorname{Corr}(U, V) = \frac{\mathbf a'\boldsymbol\Sigma_{12}\mathbf b}{\sqrt{\mathbf a'\boldsymbol\Sigma_{11}\mathbf a}\,\sqrt{\mathbf b'\boldsymbol\Sigma_{22}\mathbf b}},

with both variates scaled to variance 1. Each later pair maximizes it among combinations uncorrelated with the earlier pairs. The maximized values ρ1∗≥⋯≥ρp∗\rho_1^* \ge \cdots \ge \rho_p^* are the canonical correlations, and their squares are the eigenvalues of

Σ11−1Σ12Σ22−1Σ21.\boldsymbol\Sigma_{11}^{-1}\boldsymbol\Sigma_{12}\boldsymbol\Sigma_{22}^{-1}\boldsymbol\Sigma_{21}.

The canonical correlations do not change when either set is replaced by nonsingular linear combinations of itself, so standardizing the variables leaves them the same. The first one is at least as large as the absolute correlation between any single variable in one set and any single variable in the other.

Testing

Compute ρ^1∗≥⋯≥ρ^p∗\hat\rho_1^* \ge \cdots \ge \hat\rho_p^* from the sample blocks of S\mathbf S or R\mathbf R. For normal data and large nn, reject H0H_0 that all canonical correlations are zero, meaning Σ12=0\boldsymbol\Sigma_{12} = \mathbf 0, when

−(n−1−p+q+12)ln⁡∏i=1p(1−ρ^i∗2)>χpq2(α).-\left(n - 1 - \frac{p + q + 1}{2}\right)\ln\prod_{i=1}^p\left(1 - \hat\rho_i^{*2}\right) > \chi^2_{pq}(\alpha).

To test whether only the first kk are nonzero, start the product at i=k+1i = k + 1 and use χ(p−k)(q−k)2(α)\chi^2_{(p-k)(q-k)}(\alpha).

Cluster analysis

Cluster analysis looks for groups in data when no groups are given in advance. The answer depends on how distance is measured and on how clusters are joined, so it is worth trying more than one choice.

Distances between items

DistanceFormulaWhen to use it
Euclidean∑k(xk−yk)2\sqrt{\sum_k (x_k - y_k)^2}variables on comparable scales
Standardized Euclidean∑k(xk−yk)2/skk\sqrt{\sum_k (x_k - y_k)^2/s_{kk}}variables in different units
Mahalanobis(x−y)′S−1(x−y)\sqrt{(\mathbf x - \mathbf y)'\mathbf S^{-1}(\mathbf x - \mathbf y)}also allows for correlation
Minkowski(∑k∣xk−yk∣m)1/m\left(\sum_k \lvert x_k - y_k \rvert^m\right)^{1/m}m=1m = 1 gives city block distance and m=2m = 2 Euclidean

Hierarchical clustering

Agglomerative clustering starts with every item as its own cluster and repeatedly merges the two closest clusters until one remains. A dendrogram records which clusters merged and at what distance, and cutting it at a chosen height gives the clusters. The linkage decides the distance between clusters AA and BB.

LinkageDistance between clustersBehaviour
Singlethe closest pair of itemstends to form long chains
Completethe farthest pair of itemsfavours compact clusters
Averagethe average over all pairslies between the two
Wardthe increase in the within cluster sum of squaresfavours compact clusters of similar size

For Ward’s method, merging clusters AA and BB with NAN_A and NBN_B items raises the within cluster sum of squares by

NANBNA+NB(xˉA−xˉB)′(xˉA−xˉB).\frac{N_A N_B}{N_A + N_B}(\bar{\mathbf x}_A - \bar{\mathbf x}_B)'(\bar{\mathbf x}_A - \bar{\mathbf x}_B).

k-means

  1. Choose the number of clusters KK and a starting set of KK centroids or groups.
  2. Assign each item to the cluster with the nearest centroid.
  3. Recompute each centroid as the mean of its items.
  4. Repeat steps 2 and 3 until no item changes cluster.

With Euclidean distance neither step can increase the within cluster sum of squares, so the algorithm always stops, but possibly at a local minimum. Run it from several starts, standardize variables in different units, and compare a few values of KK.