How many principal components are noise?

Principal components analysis ranks directions by the variance they carry, and the first few components are often read as the structure in the data. But pure noise, with every direction carrying the same variance σ², still gives sample eigenvalues that spread over a range. For n observations of p variables they follow the Marchenko–Pastur law, between σ²(1 − √γ)² and σ²(1 + √γ)², with γ = p/(n − 1). An eigenvalue inside that range is no evidence of anything. The panels show the law, when a real signal escapes it, and what the first two components show when the signal is a batch effect.

1 The eigenvalues of pure noise

Draw n observations of p independent variables, each with variance σ², and take the eigenvalues of their sample covariance. Every population eigenvalue is σ², but the sample ones spread out: the largest comes out too large and the smallest too small, the more so as p approaches n. As n and p grow together, their histogram settles on the Marchenko–Pastur density. Taken by rank, each eigenvalue has its own place in that spread, and the largest wanders either side of the upper edge.

Grey: the eigenvalues of every simulated sample, as a density. Ink: the Marchenko–Pastur density for γ = p/(n − 1), with its edges dashed. σ² is the true variance of every direction.

One eigenvalue at a time

Each eigenvalue across the samples, largest first: the median (dot) and 5–95% range (bar). The dashed line is where the law puts it, its quantile at 1 − (k − ½)/p. Up to 60 are shown.

2 When a signal leaves the bulk

Now give the population a few directions with extra variance, spikes: population eigenvalues 1 + θ against the noise's 1. A spike shows as a sample eigenvalue beyond the upper edge only when θ exceeds √γ, the Baik–Ben Arous–Péché threshold, and then it comes out too large, near (1 + θ)(1 + γ/θ). Below the threshold the spike is lost in the bulk, and the sample eigenvector that should point along it points nowhere in particular. Above it, the squared cosine between the two is (1 − γ/θ²)/(1 + γ/θ), short of 1 however clear the spike.

    One simulated sample's eigenvalues against the noise's law; the triangles are the sample eigenvalues the spikes give (filled when the spike is past the threshold, hollow when it is not).

    Where a spike's eigenvalue ends up

    How well its eigenvector points along the truth

    Ink: the limits as n and p grow with p/n fixed. Triangles: the simulated spikes, the median and 5–95% range of their eigenvalue, and the mean squared cosine of their eigenvector with the true direction. Dashed: the threshold √γ and, above, the upper edge and the population eigenvalue 1 + θ.

    0 for no spike. The noise has variance 1 in every direction.

    3 What the first two components show

    The example measures 200 samples on 500 features. Each feature is shaped by 49 latent factors and noise, and a batch, half the samples, shifts every feature by a small random amount: variance 10 against the 89 or so each feature has in all. Because the shift is shared across all 500 features, it adds up to a spike far above the factors', and the first principal component separates the batches cleanly. Regressing each feature on the batch removes the shift from every component exactly. With interactions, each factor's effect also differs between the batches, which that correction leaves in place.

      As measured

      Batch regressed out

      Each sample on the first two principal components, each scaled to variance 1.

      How far apart the batches are on each component

      The difference between the batches' mean scores, in SDs of the component, as measured. After the batch is regressed out it is 0 on every component.

      The eigenvalues against the noise's edge

      The largest 100 eigenvalues on a log scale, as measured (orange) and with the batch regressed out (blue), against the upper edge the noise alone would give.

      How it works

      The law

      The sample covariance of n observations divides by n − 1 because the data are centred first, which uses up one degree of freedom, so the law's ratio is γ = p/(n − 1). Its density, √((b − x)(x − a)) / (2π σ² γ x) between the edges a and b, has a closed-form distribution function, which places each eigenvalue's expected position. When p exceeds n − 1 the covariance has rank n − 1, and the other p − n + 1 eigenvalues are exactly 0. The law describes the limit as n and p grow together; at finite sizes the largest eigenvalue fluctuates around the upper edge on a scale of n−2/3 (the Tracy–Widom law), so it falls outside the edge in a fair share of noise-only samples.

      Computing

      Each sample is drawn with a seed, so a seed gives the same eigenvalues for the same settings. The covariance's eigenvalues come from whichever of XᵀX and XXᵀ is smaller, reduced to tridiagonal form by Householder reflections and solved by the implicit QL method, in a background worker so the page stays responsive. A spike lies along a coordinate axis; since the noise looks the same in every direction, that changes no eigenvalue. The API provides the same computations.

      Spikes

      The threshold and the two limits are those of Baik, Ben Arous and Péché (2005) and Paul (2007). They hold as n and p grow; at finite sizes a spike just past the threshold is lower than its limit and its eigenvector less aligned, and one just below it still lifts the largest eigenvalue a little.