Friday, September 18, 2020

Scree plot from PCA

 ## 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 

plot(pca1, type = "lines", main = "PCA for USArrests")




0 comments:

Post a Comment