## Use datasets:USArrests
data(USArrests) # Get datafile
names(USArrests) # View variable names
## Scaled PCA using entire data.frame
pca1 = prcomp(USArrests, scale = TRUE)
## Both following commands produce same PCA as previous
pca2 = prcomp(~., data = USArrests, scale = TRUE)
pca3 = prcomp(~ Murder + Assault + Rape + UrbanPop,
data = USArrests, scale = TRUE)
pca1 # View result
names(pca1) # View elements in result object
summary(pca1) # Summary
## Plots for results...
## Scree-plot of variances (Figure 2-5)
#plot(pca1, type = "lines", main = "PCA for USArrests")
## Bi-plot of result (Figure 2-6)
biplot(pca1, col = 1, cex = c(0.8, 1.2), expand = 0.9)
0 comments:
Post a Comment