Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- library(FactoMineR)
- library(factoextra)
- library(car)
- library(explor)
- library(rgl)
- library(dplyr)
- library(ggplot2)
- library(tidyr)
- hapiness <- fread("C:/Users/PThav/Documents/M2_TIDE_PRE_RENTREE/PRE_RENTREE_R/data_td/Defi/hapiness.csv")
- names(hapiness)[c(6,8,10)] <- c("Economy","Health","Trust")
- hapiness_quanti <- hapiness %>% select_if(is.numeric)
- hapiness_quanti <- hapiness_quanti[,-c(1,2,3)]
- ql_sup <- which(names(hapiness) == "Region")
- hapiness_pca <- PCA(hapiness_quanti, scale.unit = T, quali.sup = ql_sup, graph = F)
- # Visualisation des valeurs propres
- fviz_screeplot(hapiness_pca, alpha = 0.5, addlabels = T, geom = "line") +
- geom_bar(stat = "identity", alpha = 0.2) +
- geom_point(color = "Orange") +
- geom_line(color = "Orange") +
- ggtitle("Part d'inertie conservée après projection sur le nouvel espace")
- # Description des axes
- hapiness_pca$var
- #valeurs propres
- hapiness_pca$eig
- # Cercles des corrélations
- fviz_pca_var(hapiness_pca)
- # Représentation des individus sur le premier plan factoriel
- 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") +
- ggtitle("Representation des pays sur le premier plan factoriel")+
- theme(legend.position = "none")
- dim_1 = hapiness_pca$var$coord[,1]
- dim_2 = hapiness_pca$var$coord[,2]
- dim_3 = hapiness_pca$var$coord[,3]
- #plot en 3D
- 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$)
- 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)))
- class(dim3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement