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 can also be a random vector, and is the correlation matrix. A prime means transpose, is a determinant and a trace. Critical values are upper percentiles, so , and each leave probability to their right. Unless a section says otherwise, is the number of variables and 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 variables on items gives an data matrix . Row is the observation , and is the value of variable on item .
| Quantity | Formula |
|---|---|
| Sample mean vector | |
| Sample covariance matrix | |
| Sample correlation | , collected in the matrix |
| Generalized variance | , the product of the eigenvalues of |
| Total variance | , the sum of the eigenvalues of |
The divisor makes unbiased. The generalized variance is zero exactly when some combination of the variables has no spread in the sample, which always happens when .
Population quantities
For a random vector , the mean vector is and the covariance matrix is
with off the diagonal and the variances on it. The correlation matrix has entries . 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 and and a constant matrix ,
| Quantity | Population | Sample |
|---|---|---|
| Mean of | ||
| Variance of | ||
| Covariance of and | ||
| Mean vector of | ||
| Covariance matrix of |
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 and , its contours are ellipsoids, and almost every exact test in the course assumes it.
Density and contours
A random vector with positive definite has density
The density is constant on the ellipsoids . If with unit eigenvectors , the axes of the ellipsoid point along the with half lengths . With the ellipsoid holds probability .
See also Covariance explorer to see how the ellipse changes with the covariance matrix in two dimensions
Key properties
If , then
- every linear combination is normal, with , and more generally for a constant matrix
- every subset of the variables is normal
- two blocks of variables are independent exactly when their cross covariance is , which relies on joint normality
- when is positive definite, the squared distance has a distribution
Conditional distributions. Split into blocks and , with and split to match, and suppose is invertible. Given , the block is normal with
The conditional mean is linear in , which is the link to regression, and the conditional covariance does not depend on at all.
Mahalanobis distance and checking normality
The Mahalanobis distance measures how far is from in standard deviation units, taking the correlations into account,
Points on the same density contour are at the same distance. To check a sample for normality, compute for every observation and plot the ordered values against quantiles. For normal data the points lie close to a straight line.
Sampling distributions
For a random sample of size from ,
| Result | Statement |
|---|---|
| Sample mean | |
| Sample covariance | has a Wishart distribution |
| Independence | and are independent |
| Maximum likelihood | and |
Without normality, but with positive definite and large, is approximately and is approximately . 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 test for each variable. Hotelling’s 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 that , with a random sample from and , compute
and reject at level when
For one variable, is the square of the usual statistic. The test gives the same answer whatever units the variables are measured in, and it agrees with the likelihood ratio test. The confidence region for is the ellipsoid of all that this test would not reject.
Simultaneous confidence intervals
After a test, you usually want intervals for individual means or combinations that all hold together. Each interval below has the form .
| Method | Multiplier | Use it when |
|---|---|---|
| intervals | you want any combinations, even ones chosen after seeing the data | |
| Bonferroni | you fix combinations in advance, which gives shorter intervals when is small | |
| Large sample | is large and normality is in doubt |
For a single mean , take with a one in place and zeros elsewhere, so the interval is centred at with in place of .
Paired and repeated measures
When each unit receives both treatments, work with the differences and run the one sample test of on them, using and .
When each unit receives treatments, choose a matrix of linearly independent contrasts and test that with
rejecting when
Comparing two mean vectors
Take independent samples of sizes and from and , so both populations share one covariance matrix. Pool the two estimates,
and test that with
Reject when
If the covariance matrices differ but and are both large, replace the bracket by and compare with .
MANOVA
MANOVA extends the two sample comparison to groups, in the same way that analysis of variance extends the 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 gives a sample of size , with . The observations are independent and normal with group means and a common covariance matrix . The null hypothesis is that all group means are equal.
| Matrix | Formula | Degrees of freedom |
|---|---|---|
| Between groups | ||
| Within groups | ||
| Total |
Here is the mean of group and the mean of all observations.
Wilks’ lambda and the other test statistics
The usual statistic is Wilks’ lambda,
which needs so that 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 , reject when
Software also reports Pillai’s trace, the Lawley-Hotelling trace and Roy’s largest root. All four are built from the eigenvalues of , and in large samples they usually agree. Some small cases have exact distributions under .
| Case | Statistic | Distribution |
|---|---|---|
Which means differ
After a rejection, Bonferroni intervals for every variable and every pair of groups and are
where is the th diagonal entry of . All of them hold together with probability at least .
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 have eigenvalues with orthonormal eigenvectors . The th principal component is .
| Property | Formula |
|---|---|
| Variance | |
| Uncorrelated | for |
| Total variance | |
| Share explained by | |
| Correlation of with |
The first component has the largest variance of all combinations with , 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 . The total variance is then , so component explains the share . Components from and from differ in general.
In a sample, use the eigenpairs of , or of for standardized data. The score of observation on component is . Scores on component have sample variance , 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 against and stop at the elbow, where the remaining eigenvalues are small and similar.
- Eigenvalues above 1. With , a common rule of thumb keeps the components that explain more than one standardized variable, those with .
- 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 common factors,
where is the matrix of loadings, holds the common factors and the specific factors. The factors have mean with , the specific factors have the diagonal covariance matrix , and and are uncorrelated. The model implies
So each variance splits as . The communality is the part explained by the common factors, and the specific variance is the rest. The loading is also the covariance of with factor .
Estimation
Principal component method. With the eigenpairs of or , the loadings for factor are , and each specific variance is the diagonal entry of minus the communality. Factor explains the share of the total sample variance, or with .
Maximum likelihood. Assuming normality, maximize the likelihood over and . This also gives a large sample test of whether factors are enough. Reject at level when
where . The test needs and large and .
Rotation
Loadings are not unique. For any orthogonal matrix , the rotated loadings reproduce the same , the same communalities and the same . 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 and with densities and , prior probabilities and , and misclassification costs and , the rule with the smallest expected cost assigns to when
and to otherwise. Here is the cost of putting an item from into . With equal costs and priors, simply goes to the population with the larger density there. With populations and equal costs, choose the population with the largest , which is the largest posterior probability.
Normal populations
If the populations are , the rule takes one of two forms. With equal costs, assign to the population with the largest score.
| Covariances | Score | Shape of the boundary |
|---|---|---|
| Equal, | linear | |
| Unequal | quadratic |
In practice replace by , and by or by . The quadratic rule needs each to be invertible, so , and it is more sensitive to departures from normality.
Fisher’s linear discriminant
Fisher looked for the combination that separates two samples best relative to the spread within them, without assuming normality. The best choice is
and a new item goes to when is at least the midpoint of and . 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,
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 with entries and with entries, , with covariance blocks , positive definite and cross covariance . The first canonical pair and maximizes
with both variates scaled to variance 1. Each later pair maximizes it among combinations uncorrelated with the earlier pairs. The maximized values are the canonical correlations, and their squares are the eigenvalues of
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 from the sample blocks of or . For normal data and large , reject that all canonical correlations are zero, meaning , when
To test whether only the first are nonzero, start the product at and use .
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
| Distance | Formula | When to use it |
|---|---|---|
| Euclidean | variables on comparable scales | |
| Standardized Euclidean | variables in different units | |
| Mahalanobis | also allows for correlation | |
| Minkowski | gives city block distance and 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 and .
| Linkage | Distance between clusters | Behaviour |
|---|---|---|
| Single | the closest pair of items | tends to form long chains |
| Complete | the farthest pair of items | favours compact clusters |
| Average | the average over all pairs | lies between the two |
| Ward | the increase in the within cluster sum of squares | favours compact clusters of similar size |
For Ward’s method, merging clusters and with and items raises the within cluster sum of squares by
k-means
- Choose the number of clusters and a starting set of centroids or groups.
- Assign each item to the cluster with the nearest centroid.
- Recompute each centroid as the mean of its items.
- 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 .