Understanding PCA Foundations
Introduction
Embark on an exciting journey through the world of Principal Component Analysis (PCA). In this lesson, we will explore the indispensable roles of eigenvalues and eigenvectors in understanding the PCA framework and dive into the computation of these mathematical constructs using R. Our adventure will cover the essential role of the covariance matrix and how to compute it. Ready? Set? Let's start!
Collecting Data
At the onset, we start with a dataset housing different physical measures: weight_lbs (in lbs), height_inches (in inches), and height_cm (in cm). We capture these in R using vectors and combine them into a data frame for easy manipulation:
Here, the data frame df represents our collected dataset.
Introduction to Standardization
Before performing Principal Component Analysis, we need to standardize the data. This means changing the scale of our data so that each feature has a mean of 0 and a standard deviation of 1.
PCA is sensitive to the scale of the features. Features with larger scales will dominate the variance calculations and may bias the results toward those features. Standardizing the data ensures that each feature contributes equally to the analysis, preventing this bias.
To standardize the data, each feature is transformed using the following formula:
Where:
- is the standardized value of the feature.
- is the original value of the feature.
- is the mean of the feature.
- is the standard deviation of the feature.
Plotting Standardized Data
Let's standardize just the two height columns in our dataset using R's scale() function and visualize the standardized data using ggplot2:
Output:

After standardization, our data is now centered and scaled, making the variables more comparable.

