13.4 Generating PC’s using R

Corresponding reading: PMA6 Ch 14.3-14.4

Calculating the principal components in R can be done using the function prcomp() and princomp(). This section of notes uses princomp(), not for any specific reason. STHDA has a good overview of the difference between prcomp() and princomp(). It appears that prcomp() may have some more post-analysis fancy visualizations available.

  • Requirements of data: This must be a numeric matrix. Since I made up this example by generating data in section 13.2, I know they are numeric.
  • The summary output above shows the first PC (Comp.1) explains the highest proportion of variance.
  • The values for the matrix \(\mathbf{A}\) is contained in pr$loadings.

To visualize these new axes, we plot the centered data.

Plot the original data on the new axes we see that PC1 and PC2 are uncorrelated. The red vectors show you where the original coordinates were at.