d <- read.csv("https://stats.dip.jp/01_ds/data/UN_jp.csv")
library(DT)
datatable(d,caption="United Nations")
r <- prcomp(d[, 4:ncol(d)], scale = T)
summary(r)
## Importance of components:
##                           PC1    PC2     PC3     PC4     PC5
## Standard deviation     1.9015 0.8551 0.63807 0.42872 0.24968
## Proportion of Variance 0.7231 0.1462 0.08143 0.03676 0.01247
## Cumulative Proportion  0.7231 0.8693 0.95077 0.98753 1.00000
options(digits = 1) 
(variance <- r$sdev^2)
## [1] 3.62 0.73 0.41 0.18 0.06
(proportion_variance <- variance / sum(variance))
## [1] 0.72 0.15 0.08 0.04 0.01
(cumulative_propotion <- cumsum(proportion_variance))
## [1] 0.7 0.9 1.0 1.0 1.0
evec <- r$rotation
datatable(round(evec, 2))
rownames(r$x) <- d$国名
datatable(round(r$x, 2))
library(factoextra)
## 要求されたパッケージ ggplot2 をロード中です
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
fviz_screeplot(r, addlabels = T)

fviz_contrib(r, choice = "var", axes = 1, top = 5)

fviz_contrib(r, choice = "var", axes = 2, top = 5)

library("corrplot")
## corrplot 0.94 loaded
var <- get_pca_var(r)
corrplot(var$cor, is.corr = T, addCoef.col = "gray") 

fviz_pca_var(r, 
             col.var = "contrib", # 色分け 
             repel = T) # repel: テキストラベルの重なり防止

fviz_pca_biplot(r, col.ind = "contrib", repel = T)

1.第一主成分:乳児死亡率、平均寿命、出生数などの健康面の指標 第二主成分:GDPや都市人口率などの経済指標

2.Luxembourg