Advertisement
Guest User

feu

a guest
Oct 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. library(data.table)
  2. library(FactoMineR)
  3. library(factoextra)
  4. library(car)
  5. library(explor)
  6. library(rgl)
  7. library(dplyr)
  8. library(ggplot2)
  9. library(tidyr)
  10.  
  11. hapiness <- fread("C:/Users/PThav/Documents/M2_TIDE_PRE_RENTREE/PRE_RENTREE_R/data_td/Defi/hapiness.csv")
  12.  
  13. names(hapiness)[c(6,8,10)] <- c("Economy","Health","Trust")
  14.  
  15. hapiness_quanti <- hapiness %>% select_if(is.numeric)
  16. hapiness_quanti <- hapiness_quanti[,-c(1,2,3)]
  17.  
  18. ql_sup <- which(names(hapiness) == "Region")
  19. hapiness_pca <- PCA(hapiness_quanti, scale.unit = T, quali.sup = ql_sup, graph = F)
  20.  
  21. # Visualisation des valeurs propres
  22. fviz_screeplot(hapiness_pca, alpha = 0.5, addlabels = T, geom = "line") +
  23. geom_bar(stat = "identity", alpha = 0.2) +
  24. geom_point(color = "Orange") +
  25. geom_line(color = "Orange") +
  26. ggtitle("Part d'inertie conservée après projection sur le nouvel espace")
  27.  
  28. # Description des axes
  29. hapiness_pca$var
  30.  
  31. #valeurs propres
  32. hapiness_pca$eig
  33.  
  34. # Cercles des corrélations
  35. fviz_pca_var(hapiness_pca)
  36.  
  37. # Représentation des individus sur le premier plan factoriel
  38. fviz_pca_ind(hapiness_pca, label = "none", habillage = ql_sup, pointshape = 19,axes = c(1, 2), geom = c("point", "text"), alpha.ind = "cos2", invisible = "quali") +
  39. ggtitle("Representation des pays sur le premier plan factoriel")+
  40. theme(legend.position = "none")
  41.  
  42. dim_1 = hapiness_pca$var$coord[,1]
  43. dim_2 = hapiness_pca$var$coord[,2]
  44. dim_3 = hapiness_pca$var$coord[,3]
  45.  
  46. #plot en 3D
  47. dim3 <- scatter3d(x = dim_1, y = dim_2,0 z = dim_3, surface = FALSE,labels = rownames(hapiness_pca$var$coord),id.n=nrow(hapiness_pca$var$coord),groups = hapiness$)
  48. explor(scatter3d(x = dim_1, y = dim_2, z = dim_3, surface = FALSE,labels = rownames(hapiness_pca$var$coord),id.n=nrow(hapiness_pca$var$coord)))
  49. class(dim3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement