Created
February 27, 2016 08:16
-
-
Save sureshgorakala/6e335dec0606f3c519df to your computer and use it in GitHub Desktop.
Data Science using R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(pca) | |
data("crimtab") #load data | |
head(crimtab) #show sample data | |
dim(crimtab) #check dimensions | |
str(crimtab) #show structure of the data | |
sum(crimtab) | |
colnames(crimtab) | |
apply(crimtab,2,var) #check the variance accross the variables | |
pca =prcomp(crimtab) #applying principal component analysis on crimtab data | |
par(mar = rep(2, 4)) #plot to show variable importance | |
plot(pca) | |
'below code changes the directions of the biplot, if we donot include | |
the below two lines the plot will be mirror image to the below one.' | |
pca$rotation=-pca$rotation | |
pca$x=-pca$x | |
biplot (pca , scale =0) #plot pca components using biplot in r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment