Method · Statistics Library

Principal Component Analysis (PCA)

PCA rotates a set of correlated numeric variables onto a smaller number of uncorrelated components, ordered by how much of the total variance each one captures, so many measurements can be summarized by a few numbers.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Imagine four body measurements on an animal that all tend to be big or small together: a bigger animal tends to have a longer bill, deeper bill, longer flippers, AND more mass. PCA notices that shared 'bigness' and builds a single new variable (the first principal component) that captures as much of that shared up-and-down movement as one number can. A second component then captures whatever is left over that is uncorrelated with the first in the analyzed sample (maybe a shape difference unrelated to overall size), and so on.

Each component is a weighted combination of your original variables (the card shows these weights as loadings), and the components are built to be uncorrelated with each other in your data, so each one tells you something the others do not. The eigenvalues (how much of the total spread each component captures) and the scree plot (a chart of those amounts, largest first) help you decide how many components to keep: often the first one or two capture most of the spread, but how many you need depends on your purpose, and a small later component is not automatically just noise.

PCA is a repackaging tool, not a truth-detector: it finds the directions in which your data spread out most, with no idea of what causes anything. It is easy to confuse with factor analysis, which looks similar but asks a different question: PCA compresses many variables into a few; factor analysis proposes hidden common factors to explain why variables correlate (and fitting it does not prove those factors are real).

PCA stands for principal component analysis, a dimensionality reduction method that replaces many correlated columns with a few new summary columns. PCA is computed with an eigenvalue decomposition of the correlation or covariance matrix, and each eigenvalue says how much variance its component carries.

Practitioner explanation

KernelStats standardizes by default, fitting PCA on the correlation matrix so that a large-scale variable (grams) cannot dominate a small-scale one (millimeters) purely because of units. The standardization is deliberately rescaled by sqrt((n-1)/n) after scikit-learn's StandardScaler (which divides by the population/ddof=0 SD) so the decomposed matrix is EXACTLY the sample (ddof=1) correlation matrix: the convention that makes eigenvalues sum to p (the number of variables) to the last decimal and matches R's prcomp(scale. = TRUE), rather than being inflated by a factor of n/(n-1). This convention match was a deliberate, verified fix (an earlier build mixed ddof conventions and inflated every eigenvalue and correlation-scale loading); getting it right is why the eigenvalue-sum-to-p property in the Learn More tab is a fact about this card's numbers, not an approximation.

The card reports Bartlett's sphericity test and KMO as supplementary summaries of correlation structure. Their usual verbal cutoffs are heuristics, not universal validity gates for PCA. PCA remains mathematically defined for uncorrelated variables, although compression may be limited. Neither a small Bartlett p-value nor a high KMO establishes that a retained component has a useful substantive meaning.

The card's loadings are eigenvectors multiplied by sqrt(eigenvalue). On its default unit-sample-variance standardized data these equal variable-component correlations and lie in [-1,1]. With standardization off, these raw-scale loadings need not be bounded by one; divide a loading by that variable's sample SD to obtain its correlation with the component. Score weights and scaled loadings are different matrices. Constant-variable safeguards are implementation checks, not evidence of substantive validity.

When to use it

Consider it when

You have several correlated continuous variables and want to summarize them with fewer, uncorrelated numbers, for exploration, visualization (a 2-D biplot), or to build features for a downstream model.

Use caution when

You need a causal explanation, the variance-maximizing directions do not answer the scientific question, or you require guaranteed retention of low-variance but important signals. Inspect scaling, outliers, missingness and component stability. A low KMO is a caution about shared correlation, not a mathematical prohibition on PCA. For a latent-variable model consider factor analysis and its additional assumptions.

Formulas and symbols

Percent of variance explained by component k

% variancek=λk∑jλj×100\text{\% variance}_k = \dfrac{\lambda_k}{\sum_j \lambda_j} \times 100

lambda_k is the variance of component k. The denominator sums eigenvalues over all components, including those not retained. Under this card's default unit-sample-variance standardization, their sum is p, the number of analyzed variables; raw-scale PCA has a different total variance.

Scaled eigenvector loadings and component correlations

Lik=vikλk,Corr⁡(Xi,Tk)=LiksiL_{ik}=v_{ik}\sqrt{\lambda_k},\qquad\operatorname{Corr}(X_i,T_k)=\frac{L_{ik}}{s_i}

v_ik is the eigenvector weight, lambda_k the component variance and s_i the sample SD of analyzed variable i. For unit-variance standardized variables s_i=1, so L is a correlation. With standardization off, L is raw-scale and can exceed one in magnitude.

Component decomposition

T=XcV,Xc≈TkVk⊤T=X_cV,\qquad X_c\approx T_kV_k^\top

X_c contains centered variables, additionally standardized when that option is on. Columns of V are orthonormal eigenvectors (score weights), T the scores, and k indexes retained components. Reconstruction uses V, not the scaled loading matrix L=V sqrt(Lambda); restore scaling and means to return to original units.

Assumptions and checks

  • If the variables are already nearly uncorrelated (the correlation matrix close to an identity matrix, or a low sampling-adequacy score), there is little shared structure for components to summarize, and the first few components will explain little more variance than any single original variable.

    In KernelStats: Bartlett's test of sphericity and the Kaiser-Meyer-Olkin sampling-adequacy statistic, both computed on the correlation matrix and reported directly on the card, with an honest 'not computable' verdict when the matrix is singular or a variable is constant.

  • Linearity. PCA finds only LINEAR combinations of the variables; a genuinely curved (nonlinear) structure in the data gets spread across many components instead of concentrated in the first few, understating how much low-dimensional structure the data actually has.

    In KernelStats: Not checked by KernelStats: no nonlinearity diagnostic is run; consider MDS with a non-Euclidean distance, or a nonlinear technique, if the components explain surprisingly little variance despite visibly related variables.

Alternatives

  • Exploratory Factor Analysis. You believe a small number of unobserved, latent constructs CAUSE the correlations among your variables and want to model and interpret those constructs, rather than simply compress the variance.
  • Multidimensional Scaling (MDS). You only have pairwise distances between objects (not the original variable matrix), or you only trust the RANK ORDER of the distances rather than their magnitudes.
  • k-Means Clustering. The goal is to group the observations (rows) into clusters rather than to reduce the dimensionality of the variables (columns).

Worked example

Scenario

PCA on four standardized penguin body measurements (bill length, bill depth, flipper length, body mass) across 342 penguins, keeping all components.

Result

PC1 (eigenvalue 2.75) explains 68.8% of variance, with correlation-scale loadings of 0.96 for flipper length, 0.91 for body mass, 0.76 for bill length and -0.66 for bill depth (a size axis on which deeper bills go with smaller birds in the pooled data); PC2 (eigenvalue 0.77) explains 19.3% and is almost purely a bill axis (bill depth 0.70, bill length 0.52, flipper and mass near 0); KMO = 0.69, Bartlett's chi-square(6) = 838.1, p < .001.

Interpretation

Two components capture 88% of the total variance across four measurements, with a size component and a secondary bill-dimension component (the card's Kaiser and elbow rules both recommend keeping only one; the 80% cumulative rule recommends two), a reasonable case for summarizing the four original measurements as two, keeping in mind PC2's meaning would need checking against species identity before being taken as a real biological axis.

Dataset: penguins.csv

Common misconceptions

Misconception

PCA and Factor Analysis are the same technique with different names, so it doesn't matter which one I pick.

Correction

PCA is a pure re-expression of the data that carries ALL variance (shared and variable-specific) into the components, with no error term and nothing latent. Factor analysis is a model that SPLITS each variable's variance into a common part (explained by inferred latent factors) and a unique part (noise/specific variance). Use PCA to compress or build features; use factor analysis when you believe in, and want to interpret, hidden causes.

Misconception

The first principal component always represents something meaningful and interpretable, like 'overall size'.

Correction

PCA maximizes variance captured, with no guarantee the resulting axis corresponds to anything a domain expert would recognize as a coherent concept. Interpretability of a component is something you check by reading its loadings, not something PCA guarantees by construction.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §6.5.5.1 Properties of Principal Components, NIST/SEMATECH (2012), §6.5.5.1.
  2. An Index of Factorial Simplicity, Kaiser, H. F. (1974), Psychometrika, 39(1), 31-36.
  3. R stats documentation: Principal Components Analysis (prcomp), R Core Team, Value and Note.
  4. Penn State STAT 505: principal component analysis, Penn State Department of Statistics.