Ad Code

R Script for Principle component Analysis


install.packages("factoextra") 
library(factoextra) 

import the input file in "Excel Format" 

res.pca <- prcomp(PCA, scale = TRUE) 

fviz_eig(res.pca) 

fviz_pca_ind(
  res.pca,
  col.ind = "cos2", 
  gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  repel = TRUE
) 

fviz_pca_var(
  res.pca,
  col.var = "contrib",
  gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  repel = TRUE
) 

fviz_pca_biplot(
  res.pca,
  repel = TRUE,
  col.var = "#2E9FDF",
  col.ind = "#696969"
) 

eig.val <- get_eigenvalue(res.pca) 
eig.val 

res.var <- get_pca_var(res.pca) 
res.var$coord          # Coordinates 
res.var$contrib        # Contributions to the PCs 
res.var$cos2           # Quality of representation

Post a Comment

0 Comments

Close Menu