Created
December 26, 2015 18:17
-
-
Save cyrilobolonsky/50353598fe53750bd221 to your computer and use it in GitHub Desktop.
Global Fintech | Principal Component Analysis (PCA) with R | global-fintech.blogspot.com
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
#Principal Component Analysis with R using the library FacoMineR | |
#1)preliminaries | |
#adding the file to R | |
auto<-read.table("auto2004.csv", header=TRUE, sep=",") | |
#viewing the structure of the file | |
str(auto) | |
#attaching the file to the R memory | |
attach(auto) | |
#installing the library FactoMineR | |
library(FactoMineR) | |
#2)conducting the PCA | |
res.pca<-PCA(auto[,3:8], scale.unit=TRUE, ncp=6, graph=F) | |
res.pca$eig | |
barplot(res.pca$eig[,1]) | |
res.pca<-PCA(auto[,3:8], scale.unit=TRUE, ncp=2, graph=T) | |
res.pca$ind$coord | |
res.pca$ind$coord->fact | |
cbind(auto, fact)->auto | |
res.pca$var$cor | |
dimdesc(res.pca, axes=c(1,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment