Principal Component Analysis: An Introduction
Take 500,000 genetic markers measured in 2,000 people. Or 20 skull measurements taken on 300 fossil specimens. Try to draw a picture of how the individuals relate to one another. You cannot plot 500,000 axes. Yet when Alkes Price and colleagues plotted just the first two derived axes from genome-wide SNP data in 2006, European individuals fell into a scatter that mirrored the map of Europe almost exactly. This was a northwest-to-southeast gradient recovered from genotypes alone. No geographic information had been supplied to the algorithm. That picture is Principal Component Analysis (PCA). The fact that geography "falls out" of genetic covariance is one of the most striking demonstrations in quantitative biology. It shows that structure hiding in high-dimensional data can be recovered. This is done by finding the directions along which the data vary the most. PCA matters because biological data are almost always high-dimensional. Examples include thousands of genes, hundreds of thousands of SNPs, and dozens of morphological traits. Multi-channel imaging or flow-cytometry readouts are also high-dimensional. Most of that dimensionality is redundant. Nearby genes are co-expressed, and correlated SNPs travel together on a chromosome (Linkage Disequilibrium). Skull length and skull width move together across individuals of different body size. PCA exploits exactly this redundancy. It re-expresses the data in a new coordinate system. In this system, the axes are ranked by how much variance each one explains. A handful of "principal components" can often stand in for the entire dataset. This comes with minimal loss of information. The big picture is this: PCA is a linear, variance-maximizing re-description of data. It is built entirely from the Covariance Matrix (or correlation matrix) of the original variables. It does not use labels, group identities, or any outcome variable. It is purely a geometric summary of how variables co-vary. That unsupervised character is both its power and its main pitfall. No assumptions about groups are baked in, which is powerful. But it can find structure that has nothing to do with the biological question you actually care about. This includes things like batch effects or sequencing depth. This article builds PCA from the geometry of variance and covariance. It proceeds up through the eigen-decomposition that computes it. It walks through the population-genetics and morphometric applications that made it a workhorse in biology. It reproduces the logic of the classic 2008 Novembre "Genes mirror geography" study. It also works two quantitative examples — one genomic, one morphometric. This connects the abstract linear algebra to real data you could actually compute by hand.
- PCA finds new axes (principal components, PCs) that are linear combinations of the original variables, ranked by the amount of variance they capture.
- PC1 is the direction of maximum variance in the data; PC2 is the next-best direction orthogonal to PC1; and so on.
- Mathematically, PCs are the eigenvectors of the covariance (or correlation) matrix; the corresponding eigenvalues give the variance explained by each PC.
- In population genetics, PCA of SNP genotype matrices recovers axes of ancestry, and PC scatterplots often reproduce geographic maps ("genes mirror geography").
- In morphometrics, PCA of trait-covariance matrices identifies major axes of shape/size variation, such as an overall-size axis versus a shape-contrast axis.
- PCA is unsupervised, sensitive to scaling and outliers, and can absorb technical artifacts (batch, depth) — a direct prerequisite for interpreting structure correctly in Genome-Wide Association Statistics, where the top PCs are used to correct for population stratification.
Principal Component Analysis re-expresses correlated, high-dimensional data as a small number of uncorrelated axes, each capturing as much of the total variance as geometrically possible, without using any information about group labels.
The core idea
Suppose you measure variables (SNP genotypes, gene expression levels, skull dimensions) on individuals. Each individual is a point in -dimensional space. If the variables are correlated — which biological variables almost always are — the cloud of points is not spherical; it is elongated, like a cigar or a pancake, because variation along some combinations of variables is much larger than along others. PCA finds the orientation of that cigar. Formally, a principal component is a linear combination of the original (usually centered, and often standardized) variables,
chosen so that (1) the variance of across individuals is as large as possible, and (2) the weight vector has unit length, , so the solution is not made arbitrarily large by simply inflating the coefficients. The second component, , is defined the same way subject to the additional constraint that it be uncorrelated with (geometrically, orthogonal to) . This continues until there are as many PCs as original variables, at which point the total variance in the data has been fully re-partitioned — no information is lost, only reorganized, if you keep all components. The crucial theorem that makes PCA computable is that these variance-maximizing directions are exactly the eigenvectors of the covariance matrix (or the sample covariance matrix ), and the variance captured by each PC is exactly the corresponding eigenvalue . Because is symmetric, its eigenvectors are automatically orthogonal, which is precisely the uncorrelated-axes property PCA requires — this is not a coincidence but the reason PCA is defined via eigen-decomposition rather than by some more complicated search. The eigenvalues sum to the total variance in the data (the trace of ), so is the proportion of total variance explained by — the number quoted on every PCA plot axis label.
Mechanism — how the axes are actually found
Step 1: Center (and possibly scale) the data. For each variable, subtract its mean across individuals so that every variable has mean zero. If variables are on very different scales (e.g., height in cm mixed with a hormone concentration in pg/mL), each is also divided by its standard deviation, converting the covariance matrix into a correlation matrix; otherwise PCA would be dominated by whichever variable happens to have large numeric units, an artifact of measurement scale rather than biology.
Step 2: Compute the covariance matrix. For centered variables measured on individuals, the sample covariance matrix is
a symmetric matrix whose diagonal entries are variances of each variable and whose off-diagonal entries are covariances between pairs of variables. This matrix is the entire input to PCA — PCA never looks at the raw data again once (or the correlation matrix) is formed.
Step 3: Eigen-decompose the covariance matrix. Solve for eigenvectors and eigenvalues . Each eigenvector, called a loading vector, gives the recipe (the weights ) for building one principal component out of the original variables. In genomic applications this decomposition is usually done via Singular Value Decomposition of the (centered) data matrix directly, which is numerically more stable than forming explicitly and is mathematically equivalent.
Step 4: Project the data. Each individual's PC score is obtained by taking the dot product of their (centered) trait vector with each loading vector:
These scores are the new coordinates plotted on a PCA scatterplot; an individual far to the right on the PC1 axis has a trait combination strongly aligned with the PC1 loading vector.
Step 5: Decide how many PCs to keep. Because measures variance captured, a scree plot of eigenvalue against PC number typically shows a steep drop followed by a long, shallow tail; the "elbow" is often used as an informal cutoff, keeping only the PCs before the tail flattens, on the reasoning that the tail represents noise rather than structured signal.
The key intuition from this figure generalizes without change to 500,000 dimensions: the covariance matrix defines an ellipsoid (in dimensions) whose principal axes are exactly the PCs, ordered from longest (most variance) to shortest.
In genomic datasets the "signal" PCs (here, PC1–PC3, together explaining 77% of variance) typically correspond to interpretable axes such as ancestry, sex, or a strong batch effect, while the long flat tail is diffuse noise from individual SNP genotyping error or expression measurement variability — this is exactly the noise floor that motivates dimensionality reduction before downstream statistical testing in Genome-Wide Association Statistics.
The evidence — genes mirror geography
The canonical demonstration that PCA recovers real, interpretable biological structure — not just an arbitrary rotation of noise — is the population-genetic work initiated by Cavalli-Sforza's group in the 1970s–90s and brought to genome-wide data by Alkes Price et al. (2006, Nature Genetics, "Principal components analysis corrects for stratification in genome-wide association studies") and, most vividly, John Novembre et al. (2008, Nature, "Genes mirror geography within Europe").
What was done. Novembre and colleagues genotyped roughly 3,000 Europeans (the POPRES dataset) at about 500,000 SNPs across the genome. They built the individual-by-SNP genotype matrix (each entry coded as 0, 1, or 2 copies of a reference allele), computed the sample covariance matrix across individuals, and performed PCA — technically an SVD-based variant adapted for genotype data (the EIGENSOFT/smartpca method developed by Price, Patterson, and Reich). No geographic coordinates or country labels were given to the algorithm; only genotypes were used as input.
What was observed. The scatterplot of PC1 versus PC2 scores reproduced, with startling fidelity, a rotated and slightly distorted map of Europe: individuals from Portugal and Spain clustered in the southwest of the plot, Finns and other Scandinavians clustered in the northeast, and individuals from intermediate countries (France, Germany, Italy, the Balkans) filled in the intermediate space in roughly the correct relative geographic positions. The correlation between an individual's PC1–PC2 position and their true country-of-origin coordinates was strong enough that the authors could predict an individual's country of origin to within a few hundred kilometers, purely from genotype-derived PC scores.
What it proved. This result demonstrated that most human genetic variation within a continental group is structured by isolation by distance — genetic similarity decays smoothly with geographic distance because migration and mating are geographically local — and that this smooth, continuous gradient (rather than discrete "races" or clusters) is precisely the kind of variance-maximizing linear structure that PCA is built to detect. It also validated the earlier, more theoretical proposal of Price et al. (2006) that the top few PCs of genome-wide genotype data are an efficient empirical proxy for ancestry, directly justifying their use as covariates to correct for population stratification — a confounding structure that, left uncorrected, produces false-positive associations in genome-wide association studies (a problem foreshadowing the methodological core of Genome-Wide Association Statistics). Related work by Cavalli-Sforza, Menozzi and Piazza in The History and Geography of Human Genes (1994) had shown similar continent-scale gradients using classical PCA on allele-frequency data decades earlier, and Reich and colleagues later extended the same logic to ancient DNA, using PCA to project ancient samples onto axes built from present-day populations and thereby infer ancestry proportions and migration history.
Worked examples
Example 1 — population structure from a toy SNP dataset. Suppose you genotype 6 individuals at 4 SNPs (coded as allele dosage 0, 1, or 2), and — to keep the arithmetic tractable — the individuals come from two weakly diverged populations, A (individuals 1–3) and B (individuals 4–6):
| Individual | SNP1 | SNP2 | SNP3 | SNP4 |
|---|---|---|---|---|
| 1 (Pop A) | 0 | 0 | 2 | 1 |
| 2 (Pop A) | 0 | 1 | 2 | 0 |
| 3 (Pop A) | 1 | 0 | 1 | 1 |
| 4 (Pop B) | 2 | 2 | 0 | 1 |
| 5 (Pop B) | 2 | 1 | 0 | 0 |
| 6 (Pop B) | 1 | 2 | 1 | 2 |
Column means are (1.0, 1.0, 1.0, 0.833). Centering subtracts these from each column; e.g., individual 1's centered SNP1 value is . Without grinding through the full eigen-decomposition by hand, the qualitative structure is instructive: SNP1 and SNP2 both take low values in Pop A and high values in Pop B, so they are strongly positively correlated across individuals; SNP3 takes high values in Pop A and low values in Pop B, so it is strongly negatively correlated with SNP1 and SNP2. SNP4 shows no consistent population difference — it varies almost independently of population. A PCA on this covariance structure will produce a PC1 loading vector with large positive weight on SNP1 and SNP2, large negative weight on SNP3, and near-zero weight on SNP4 — because that combination is exactly the linear combination whose value differs most between the two clusters, hence has maximal variance across all six individuals. Projecting each individual onto this PC1 gives strongly negative scores for individuals 1–3 and strongly positive scores for individuals 4–6, cleanly separating the two populations on a single axis — this is the mechanism, in miniature, behind the Novembre et al. European map: real, replicated allele-frequency differences between geographically or ancestrally structured groups are precisely the kind of correlated variation that maximizes variance along a shared axis, so PCA discovers population structure as a side effect of maximizing variance, without ever being told population labels. If instead you standardized each SNP (dividing by its standard deviation) before running PCA, SNP4 — despite carrying almost no population signal — would receive a small but nonzero PC1 loading (it is not perfectly independent in a sample of only 6), and doing PCA on unstandardized allele counts is in fact the more common and defensible choice in population genetics, because SNP allele frequency and variance are mathematically linked (variance under Hardy–Weinberg), and this relationship is precisely what many ancestry-informative PCA methods intentionally rely on.
Example 2 — a morphometric PCA with an asymmetric size/shape signal. A field biologist measures 5 skull traits (in mm) on a sample of turtle skulls spanning both sexes and a wide size range: skull length (SL), skull width (SW), jaw length (JL), orbit diameter (OD), and interorbital distance (IOD). The raw trait correlation matrix (correlation, not covariance, is used here because traits are on the same unit but on different natural scales of variability) looks like this:
| SL | SW | JL | OD | IOD | |
|---|---|---|---|---|---|
| SL | 1.00 | 0.86 | 0.91 | 0.34 | 0.78 |
| SW | 0.86 | 1.00 | 0.83 | 0.29 | 0.81 |
| JL | 0.91 | 0.83 | 1.00 | 0.31 | 0.74 |
| OD | 0.34 | 0.29 | 0.31 | 1.00 | 0.22 |
| IOD | 0.78 | 0.81 | 0.74 | 0.22 | 1.00 |
Notice the asymmetry: SL, SW, JL, and IOD are all strongly positively correlated with one another (0.74–0.91), but OD (orbit diameter) is only weakly correlated with the others (0.22–0.34). This is a classic biological pattern — most skull dimensions scale together with overall body/head size, but eye size is comparatively size-invariant across individuals (a phenomenon well documented in vertebrate cranial allometry, since neural and sensory tissue often grows more slowly than the rest of the skull, a pattern called negative allometry). PCA on this correlation matrix typically yields:
| PC | Eigenvalue | % variance | Interpretation |
|---|---|---|---|
| PC1 | 3.55 | 71% | General size (all traits load positively, OD loads weakly) |
| PC2 | 0.85 | 17% | Contrast: OD vs. the rest (shape) |
| PC3–5 | 0.60 total | 12% | Residual/noise |
PC1's loadings would be approximately (0.49, 0.47, 0.48, 0.20, 0.46) — nearly equal, large positive weights on SL, SW, JL, IOD, and a much smaller weight on OD — confirming PC1 is a size axis: an individual with a high PC1 score is simply a large-skulled turtle across almost every dimension measured. PC2's loadings would be dominated by OD with an opposite sign from the rest, roughly (−0.25, −0.22, −0.20, 0.90, −0.18) — a shape axis contrasting relatively large eyes against a comparatively small skull, capturing individuals whose orbit size deviates from what overall skull size alone would predict. A biologist plotting PC1 (x-axis) against PC2 (y-axis) would see the population spread mainly left-to-right by size, with residual up-down scatter reflecting the size-independent, orbit-driven variation — precisely the kind of size/shape decomposition that motivated Sewall Wright's early use of principal-axis methods on turtle shell measurements in the 1930s and that remains standard practice in modern geometric morphometrics.
Common misconceptions & traps
| Misconception | Why it is wrong |
|---|---|
| "PC1 always represents the most biologically important variable." | PC1 captures the most statistical variance, which need not align with biological importance; a technical artifact (batch effect, sequencing depth) can dominate PC1 if it happens to be the largest source of variance. |
| "PCA identifies clusters or groups." | PCA is a rotation/projection method; it does not perform clustering. Clusters may become visually apparent on a PC scatterplot, but PCA itself makes no group assignments — that requires a separate clustering algorithm (e.g., k-means, ADMIXTURE). |
| "The percentage of variance explained tells you how 'good' the analysis is." | A low %-variance-explained for PC1–PC2 does not mean PCA failed; for genuinely high-dimensional, noisy data (e.g., single-cell RNA-seq with 20,000 genes) even 10–20% in the top two PCs can represent strong, interpretable structure. |
| "PCA requires or implies causal relationships between variables." | PCA is purely descriptive/geometric; correlated variables loading on the same PC are not thereby shown to cause one another. |
| "Standardizing data never matters." | Choosing covariance vs. correlation PCA can change results substantially; variables with large variance (often simply large numeric units) dominate covariance-based PCA unless standardized first. |
| "More PCs retained always means a better model." | Retaining too many PCs reintroduces noise dimensions and can overfit downstream models (e.g., inflating false-positive associations if noisy PCs are used as GWAS covariates). |
The scientist behind it
Principal Component Analysis was invented independently twice: by Karl Pearson in 1901, in a paper titled "On Lines and Planes of Closest Fit to Systems of Points in Space," which posed PCA geometrically as finding the best-fitting line or plane through a cloud of points by minimizing the perpendicular (orthogonal) distances of points to that line — a formulation mathematically equivalent to maximizing variance along the line. The method was independently rediscovered and given its modern statistical formulation, name, and computational algorithm by Harold Hotelling in 1933, in "Analysis of a Complex of Statistical Variables into Principal Components," where he framed the problem explicitly in terms of extracting uncorrelated components ranked by variance from a set of correlated psychological test scores. Its biological uptake was slower: it entered population genetics substantially through Luigi Luca Cavalli-Sforza, whose decades-long project mapping human allele-frequency variation onto geography (culminating in the 1994 monograph The History and Geography of Human Genes, with Paolo Menozzi and Alberto Piazza) used principal-components maps of Europe and the world as a central visual and analytical tool decades before genome-wide SNP data existed, and it was modernized for genome-scale data by Nick Patterson, Alkes Price, and David Reich in the mid-2000s, whose EIGENSOFT software and stratification-correction methodology made PCA a mandatory preprocessing step in essentially every genome-wide association study conducted since.
Origins · 1 minHarold Hotelling and how this was discovered
Hotelling worked at the intersection of statistics and economics, also developing Hotelling's T² statistic and canonical correlation analysis; his 1933 paper gave PCA its rigorous variance-maximization formulation and its enduring name.
Where this matters today
Genome-wide association studies (GWAS). The top 5–20 PCs of genome-wide genotype data are routinely included as covariates in association-testing regressions to absorb population stratification, preventing ancestry-correlated allele frequency differences from masquerading as disease associations — a direct methodological bridge to Genome-Wide Association Statistics.
Single-cell and bulk transcriptomics. PCA is the near-universal first step in single-cell RNA-seq pipelines (e.g., Seurat, Scanpy), used to reduce tens of thousands of genes to 10–50 PCs before clustering cells into putative cell types or feeding the reduced space into nonlinear embeddings such as t-SNE or UMAP.
Ancient DNA and human population history. Ancient genomes are commonly "projected" onto PCs built from present-day reference populations, letting researchers infer the ancestry composition and migration history of archaeological samples relative to modern genetic variation (used extensively in Reich-lab ancient-DNA studies of Eurasian population turnover).
Conservation genetics. PCA on SNP or microsatellite data from endangered populations detects cryptic population structure, inbreeding-driven substructure, and admixture between subspecies, informing management units and translocation decisions.
Agricultural and plant breeding genomics. PCA of genotyped breeding-line panels corrects for population structure in genomic-selection and marker-association models in crops such as maize, rice, and wheat, analogous to its GWAS role in humans.
Quantitative morphology and paleontology. PCA of landmark or linear-measurement matrices remains the standard tool for summarizing shape variation across fossil specimens, living species comparisons, and developmental growth series, separating size-related from shape-related variation as in the turtle-skull example above.
Public health surveillance. PCA of pathogen genomic surveillance data (e.g., influenza or SARS-CoV-2 sequence variation) helps visualize antigenic drift and lineage relationships, informing vaccine strain selection.
Ask the tutor: How do I decide whether a cluster I see on a PCA plot of my RNA-seq or SNP data reflects real biology versus a technical batch effect?
Is PCA the same thing as factor analysis?
No, though they are often confused. PCA is a purely descriptive, deterministic transformation: it re-expresses the observed variance exactly, with no underlying statistical model or error term, and every component is a fixed linear combination of the observed variables. Factor analysis, by contrast, posits a generative statistical model in which a smaller number of unobserved "latent factors" plus variable-specific error terms are assumed to have produced the observed correlations, and it estimates those latent factors under that assumed model. In practice PCA is used more often in genomics because it makes no distributional assumptions and its uniqueness (up to sign) makes results directly reproducible, while factor analysis is more common in psychometrics where a specific causal latent-variable model is of scientific interest.
Should I use the covariance matrix or the correlation matrix to run PCA?
Use the correlation matrix (equivalently, standardize each variable to unit variance before covariance-based PCA) whenever your variables are measured in different units or have very different natural variances — otherwise a variable like "body mass in grams" will numerically swamp a variable like "heart rate in beats per minute" purely due to scale, not biology. Use the raw covariance matrix when variables are already commensurate and their differing variances are themselves biologically meaningful, as in SNP genotype data, where a common allele's naturally larger variance ( near ) versus a rare allele's smaller variance is precisely the signal ancestry-PCA methods are designed to exploit.
How many principal components should I keep?
There is no single universally correct rule, but three heuristics are widely used. The scree plot elbow method retains PCs before the eigenvalue curve flattens into a noise tail. The Kaiser criterion retains PCs with eigenvalue greater than 1 when using a correlation matrix, on the logic that a PC should explain at least as much variance as a single original (standardized) variable to be worth keeping. Permutation-based methods (e.g., the Tracy-Widom statistic used in population genetics, or parallel analysis) compare observed eigenvalues to those expected under a null model of no structure, retaining only PCs that significantly exceed random expectation. In GWAS practice, researchers often retain a fixed conventional number (commonly the first 5–10 PCs) as covariates rather than relying purely on a statistical cutoff.
Can PCA handle missing data, like ungenotyped SNPs or unmeasured traits?
Standard PCA, as derived from an eigen-decomposition of a complete covariance matrix, requires complete data; missing entries must be handled before the standard algorithm can run. Common approaches include mean-imputation (replacing a missing genotype with the average allele frequency at that SNP, standard practice in tools like EIGENSOFT), or specialized methods such as probabilistic PCA that explicitly model missingness within an expectation-maximization framework. Naive imputation can bias PC scores toward zero for samples with many missing values, so most population-genetic pipelines apply strict missingness filters (e.g., excluding SNPs or individuals with more than 1–5% missing genotypes) before running PCA rather than relying heavily on imputation.
Why do genotype-based PCA plots sometimes show a horseshoe or arch shape instead of a simple gradient?
This is a well-documented artifact called the horseshoe effect, arising when the underlying biological structure is a continuous one-dimensional gradient (such as isolation-by-distance along a geographic transect) but is being represented in two or more dimensions. Because PCA components must be mutually orthogonal, a smooth linear gradient in the true underlying variable gets mathematically "folded" so that PC2 becomes a curved (often quadratic) function of PC1, bending the scatterplot into an arch. This is a known limitation of linear PCA on strongly one-dimensional data and is one motivation for nonlinear reduction methods such as t-SNE or UMAP in some contexts, though PCA's horseshoe is still directly interpretable once recognized, unlike arbitrary nonlinear distortions.
Is PCA reversible — can I reconstruct the original data from the PC scores?
Yes, if you keep all components: since the transformation is just a rotation of axes (an orthogonal linear transformation), no information is lost, and the original centered data can be exactly reconstructed by multiplying PC scores back through the loading vectors. If you keep only the top PCs, reconstruction is only approximate — you recover the best possible rank- linear approximation of the original data (a fact formalized by the Eckart–Young theorem), which is precisely why PCA is used for lossy compression and denoising: discarding low-variance PCs removes noise while retaining the dominant structured signal.
How does PCA relate to population stratification in GWAS, and why does it foreshadow that topic?
Population stratification is the confounding that arises in a GWAS when allele frequencies differ systematically between subpopulations that are also, coincidentally or causally, associated with the trait being studied (e.g., differing disease prevalence by ancestry group). Because PCA on genome-wide SNP data recovers axes of ancestry as its top components (as in the Novembre et al. result), including those top PCs as covariates in an association regression statistically "removes" the ancestry-driven component of both genotype and phenotype variation before testing for a true genetic association, dramatically reducing false-positive rates. This makes PCA a load-bearing preprocessing step, not an optional visualization, in essentially every modern GWAS pipeline.