Skip to main content
v2026.11,986 entries · CC-BY 4.0

Principal Component Analysis Examples & Guide

Explore principal component analysis examples with complete step-by-step arithmetic, eigenvalue formulas, APA reporting, and practical code in R and Python.

Written and maintained by CASRAI Editorial Board

Published

On this page

Principal component analysis (PCA) is an unsupervised multivariate method that transforms correlated variables into a smaller set of uncorrelated principal components, ordered so that the first few retain most original variance. Quantitative researchers use principal component analysis to reduce dimensionality, eliminate multicollinearity, visualize sample clustering, and build composite indices. This guide provides concrete principal component analysis examples, covering step-by-step arithmetic, eigenvalue formulas, variance interpretation, APA 7th reporting, and verified code implementations.

What is principal component analysis? (Definition in one paragraph)

Principal component analysis is an orthogonal linear transformation introduced by Karl Pearson in 1901 and extended by Harold Hotelling in 1933. PCA rotates coordinate axes of an observed dataset onto new, mutually perpendicular axes aligned with directions of maximal sample variance (Jolliffe & Cadima, 2016). The first component (PC1) accounts for the largest possible variance; each subsequent component accounts for the largest remaining variance under orthogonality constraints. Preserving total variance allows retaining early components that capture dominant patterns while discarding minor components reflecting measurement noise. For visual interpretation of coordinate projections, see our guide on reading a PCA plot.

How does principal component analysis work? (Formula with every symbol explained)

PCA decomposes the sample covariance matrix S or correlation matrix R into orthogonal principal axes (NIST/SEMATECH, 2026). Given an n × p data matrix X, the procedure follows four steps:

  1. Centering and Covariance: Subtract column means x̄j = (1/n) ∑ xij to center X̃. The sample covariance matrix is S = (1 / (n − 1)) X̃T X̃, with variances sjj and covariances sjk. See our covariance matrix formula guide.
  2. Characteristic Equation: Maximizing variance solves (S − λ I) v = 0, where λ is an eigenvalue (component variance), I is identity, and v is an eigenvector (loadings). Setting det(S − λ I) = 0 yields p eigenvalues: λ1 ≥ λ2 ≥ … ≥ λp ≥ 0.
  3. Eigenvectors: Each unit eigenvector satisfies vkT vk = 1 with orthogonality: vjT vk = 0 for j ≠ k.
  4. Scores and Variance: Projection yields scores zik = vkT x̃i. Total variance is tr(S) = ∑ λk; component k explains variance proportion λk / tr(S).

Covariance vs. Correlation: Use covariance matrix S when variables share identical physical units. Use correlation matrix R (standardized z-scores) when variables have differing units to prevent high-variance variables from dominating PC1 (Jolliffe & Cadima, 2016).

Worked example with real numbers and the arithmetic shown

This worked principal component analysis example computes PCA for n = 4 participants and p = 2 variables: Exam Score (X1) and Study Hours (X2). Raw pairs (X1, X2) are: P1 = (4, 2); P2 = (8, 4); P3 = (12, 8); P4 = (16, 10).

Step 1: Centering Data

Means are x̄1 = 10.0 and x̄2 = 6.0. Centered values (x̃1 = X1 − 10, x̃2 = X2 − 6) are: P1 = (−6.0, −4.0); P2 = (−2.0, −2.0); P3 = (+2.0, +2.0); P4 = (+6.0, +4.0).

Step 2: Sample Covariance Matrix S

With divisor n − 1 = 3: s11 = 80/3 ≈ 26.6667; s22 = 40/3 ≈ 13.3333; s12 = 56/3 ≈ 18.6667. Covariance matrix S = [ [26.6667, 18.6667], [18.6667, 13.3333] ]; total variance tr(S) = 40.0000.

Step 3: Solve for Eigenvalues

Determinant det(S) = (80/3)(40/3) − (56/3)2 = 64/9 ≈ 7.1111. Characteristic equation: λ2 − 40.0 λ + 7.1111 = 0. Discriminant Δ = 402 − 4(7.1111) = 1571.5556 (√Δ ≈ 39.6428). Roots are:

  • λ1: (40.0 + 39.6428)/2 = 39.8214 (explained variance: 39.8214 / 40.0 = 99.55%)
  • λ2: (40.0 − 39.6428)/2 = 0.1786 (explained variance: 0.1786 / 40.0 = 0.45%)

Step 4: Solve for Unit Eigenvectors (Loadings)

For λ1 = 39.8214: solving (S − λ1 I) v1 = 0 with unit norm yields v1 = [0.8174, 0.5760]T. For λ2 = 0.1786, v2 = [0.5760, −0.8174]T. Orthogonality holds: (0.8174)(0.5760) + (0.5760)(−0.8174) = 0.0000.

Step 5: Compute Principal Component Scores

Scores are calculated via zik = v1k x̃i1 + v2k x̃i2:

  • P1: PC1 = (−6)(0.8174) + (−4)(0.5760) = −7.2087; PC2 = (−6)(0.5760) + (−4)(−0.8174) = −0.1866
  • P2: PC1 = (−2)(0.8174) + (−2)(0.5760) = −2.7869; PC2 = (−2)(0.5760) + (−2)(−0.8174) = +0.4827
  • P3: PC1 = (+2)(0.8174) + (+2)(0.5760) = +2.7869; PC2 = (+2)(0.5760) + (+2)(−0.8174) = −0.4827
  • P4: PC1 = (+6)(0.8174) + (+4)(0.5760) = +7.2087; PC2 = (+6)(0.5760) + (+4)(−0.8174) = +0.1866

Sample variance of PC1 scores equals 119.4643 / 3 = 39.8214, matching eigenvalue λ1.

How to interpret principal component analysis

Interpreting PCA involves examining eigenvalues, loadings, and score distributions:

Output Statistic Evaluation Threshold Substantive Meaning
Eigenvalue (λ) Kaiser rule: λ > 1.0 (correlation PCA); scree plot elbow. Variance explained by component. In correlation PCA, λ > 1.0 accounts for more variance than an average single variable.
Cumulative Variance Conventional target: 70% to 85% total variance. Indicates whether retained components adequately summarize the multidimensional system without substantive information loss.
Component Loadings (vjk) Salience threshold: |vjk| ≥ 0.40 or 0.50. Reflects weight and direction of variable j in component k. Positive loadings increase score; negative loadings reduce it.
Component Scores (zik) Mean = 0.0; standard deviation = √λk. Relative position of observations in reduced space. High positive scores reflect values well above average on that component dimension.

Assumptions and common mistakes in principal component analysis

Reliable applications require specific structural data conditions (Jolliffe & Cadima, 2016):

  • Linearity Assumption: PCA captures linear relationships only. Strong non-linear structures are poorly summarized by linear hyperplanes; in such settings, explore UMAP and t-SNE.
  • Continuous Numerical Data: Standard PCA requires continuous numeric data. Analyzing categorical items with linear PCA distorts correlation structures; use Multiple Correspondence Analysis instead.
  • Scale Sensitivity: Omitting standardization when variables have differing units allows variables with large numbers to dominate PC1 arbitrarily.
  • Confusing PCA with Factor Analysis: PCA is descriptive data reduction that partitions total variance without distinguishing common variance from unique error variance. When seeking unobservable causal latent constructs, researchers should apply factor analysis; see our comparison of exploratory and confirmatory factor analysis.
  • Over-retaining Noise Components: Retaining trailing components with tiny eigenvalues inflates model complexity and models sampling noise rather than systemic covariance.

How to report principal component analysis (APA example)

When reporting PCA in APA 7th style, specify sample size, extraction matrix, retention rules, eigenvalues, variance percentages, and a factor loadings table.

“A principal component analysis (PCA) was conducted on four standardized academic indicators across 120 undergraduates (N = 120). Bartlett’s test of sphericity was significant (χ²(6) = 214.38, p < .001), and KMO sampling adequacy was .78. Kaiser criterion (eigenvalues > 1.0) and scree plot inspection supported a two-component solution explaining 81.42% of variance. Component 1 (λ = 2.14, 53.50% variance) reflected engagement, loading on coursework (.84) and lab hours (.79). Component 2 (λ = 1.12, 27.92% variance) reflected communication, loading on writing (.81) and presentations (.76). Loadings appear in Table 1.”

Table 1: Component Loadings and Explained Variance

Variable Component 1 (Engagement) Component 2 (Communication)
Quantitative Coursework Score .84 .18
Research Laboratory Hours .79 .22
Technical Writing Proficiency .21 .81
Oral Presentation Evaluation .15 .76
Eigenvalue (λ) 2.14 1.12
% of Variance Explained 53.50% 27.92%

How to calculate principal component analysis in Excel, R and Python

Execute PCA across computational environments using verified routines:

1. Excel

With data in cells A2:B5: compute means in A6:B6 with =AVERAGE(A2:A5); center data in D2 with =A2:B5 - A6:B6; compute covariance matrix S in G2 via =MMULT(TRANSPOSE(D2#), D2#)/(COUNT(A2:A5)-1); and calculate PC1 scores in L2 with eigenvector v1 in J2:J3 using =MMULT(D2#, J2:J3).

2. R

data <- data.frame(Exam = c(4, 8, 12, 16), Study = c(2, 4, 8, 10))
pca_res <- prcomp(data, center = TRUE, scale. = FALSE)
summary(pca_res)
pca_res$rotation  # Loadings
pca_res$x         # Scores

3. Python

Using sklearn.decomposition.PCA. For scaling workflows, see our guide on PCA in Python (scikit-learn):

from sklearn.decomposition import PCA
X = [[4, 2], [8, 4], [12, 8], [16, 10]]
pca = PCA(n_components=2)
scores = pca.fit_transform(X)
print("Eigenvalues:", pca.explained_variance_)
print("Loadings:n", pca.components_)

Frequently asked questions

What does principal component analysis do?

PCA simplifies multidimensional datasets by transforming correlated variables into a smaller set of uncorrelated components. It orders components by variance explained, allowing analysts to compress feature spaces, eliminate multicollinearity, visualize sample clustering, and construct composite indices.

How to do principal component analysis?

To do PCA: (1) verify linear correlations; (2) center data and standardize if units differ; (3) compute covariance or correlation matrix; (4) solve for eigenvalues and unit eigenvectors; (5) select components via Kaiser rule (λ > 1) or scree plot; and (6) multiply centered data by eigenvectors to compute scores.

What is the difference between PCA and factor analysis?

PCA is an empirical dimension-reduction technique that redistributes all observed variance into orthogonal components without positing latent constructs. Exploratory Factor Analysis (EFA) models unobserved latent factors that cause observed correlations, distinguishing common variance from unique error variance.

When should you use the correlation matrix instead of the covariance matrix?

Use the correlation matrix when variables have differing units or vastly different variances. Performing PCA on the covariance matrix without standardization allows variables with large numerical values to dominate the first component, distorting the analysis.

How to interpret principal component analysis scores?

Interpret principal component scores relative to the sample centroid at (0, 0). Positive scores represent observations above average on that component dimension; negative scores represent observations below average. Observations with similar score coordinates share similar multidimensional profiles.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Principal Component Analysis Examples & Guide

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →