O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

First, the data is read and then the correlation plot of the relevant dimensions is generated to examine whether there is scope for PCA to yield some dimensionality reduction. Next, the PCA model is generated using the prcomp function. We use scale=TRUE to generate the model based on the correlation matrix and not the covariance matrix. We then use the summary function to get different information on the model and then a barplot as well as a scree plot of the variances by PCA is generated using the plot function. Finally, we generate a biplot that uses the first two principal components as the main axes and shows how each variable loads on these two components. The top and right axes correspond to the scores of the data points ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required