Skip to main content

PCA & Dimension Reduction

Topic: Principal component analysis, interpretation of loadings and scores, other dimension reduction methods.

Note

Fall 2026: one lecture this week — Monday Nov 9. Wednesday Nov 11 is Veterans Day (no class). Highlights of the L13 material are folded into Monday; the full method-selection guide is below.

Learning Objectives

  • Explain what PCA does: centre and scale, find the direction with the widest spread, rotate
  • Say what eigenvectors (loadings), scores and eigenvalues are, and find each in prcomp() output
  • Decide how many PCs to keep, and name a PC from its loadings
  • Use PC scores as predictors in a model
  • Choose between PCA, PCoA, NMDS and UMAP/t-SNE

Slides

Interactive

R Code

Data

  • cassava.csv (1006 cassava landraces: the 19 bioclimatic variables of each home site, and root dry matter)
  • winedata.csv (the Week 1 wine data, for Problem Set 7)

Which Ordination Method, When?

You will meet several dimension-reduction methods this week. They answer different questions — use this to choose:

Method Input Structure Axes interpretable? Best for
PCA Continuous variables Linear Yes — loadings tell you which variables drive each axis Correlated continuous measurements (traits, climate, spectra); making composite variables for downstream models
PCoA Any distance matrix Linear embedding of the distances Partly — axes reflect the chosen distance, not variables When your data are naturally a distance/dissimilarity (genetic distance, Bray-Curtis)
NMDS Any distance matrix Non-linear, rank-based No — only relative positions matter; always report stress Ecological community/species-abundance data with many zeros
UMAP / t-SNE High-dimensional anything Non-linear, local-neighborhood No — axis units and between-cluster distances are not meaningful Visualization only, for large datasets (e.g. single-cell expression)

Rules of thumb:

  • If your variables are continuous and you want to interpret the axes or reuse the scores in a model → PCA.
  • If what you actually have is a distance matrix → PCoA (linear) or NMDS (rank-based; the ecology default).
  • UMAP/t-SNE make pretty pictures, not measurements. Never read distances between clusters, or axis values, as quantities — and never feed their coordinates into downstream statistical models.

Key Packages

library(ggplot2)
library(vegan)    # NMDS: metaMDS()
library(umap)     # UMAP
library(Rtsne)    # t-SNE

Assignment

Problem Set 7: Principal Component Analysis — due Monday, November 16, 1:10 PM. Submit on Canvas.