Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyrilobolonsky/50353598fe53750bd221 to your computer and use it in GitHub Desktop.
Save cyrilobolonsky/50353598fe53750bd221 to your computer and use it in GitHub Desktop.
Global Fintech | Principal Component Analysis (PCA) with R | global-fintech.blogspot.com
#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