=— title: “Kelompok 12_anmul_yuli_devita” author: “yuli and devita” date: “2026-03-03” output: html_document —

LOAD DATASET

# Load dataset
df <- read_csv("/cloud/project/countries.csv")
## Rows: 188 Columns: 21
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (4): Country, Region, GDP per Capita, Data Quality
## dbl (17): Population (millions), HDI, Cropland Footprint, Grazing Footprint,...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Lihat struktur data
str(df)
## spc_tbl_ [188 × 21] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ Country                       : chr [1:188] "Afghanistan" "Albania" "Algeria" "Angola" ...
##  $ Region                        : chr [1:188] "Middle East/Central Asia" "Northern/Eastern Europe" "Africa" "Africa" ...
##  $ Population (millions)         : num [1:188] 29.82 3.16 38.48 20.82 0.09 ...
##  $ HDI                           : num [1:188] 0.46 0.73 0.73 0.52 0.78 0.83 0.73 NA 0.93 0.88 ...
##  $ GDP per Capita                : chr [1:188] "$614.66" "$4,534.37" "$5,430.57" "$4,665.91" ...
##  $ Cropland Footprint            : num [1:188] 0.3 0.78 0.6 0.33 NA 0.78 0.74 NA 2.68 0.82 ...
##  $ Grazing Footprint             : num [1:188] 0.2 0.22 0.16 0.15 NA 0.79 0.18 NA 0.63 0.27 ...
##  $ Forest Footprint              : num [1:188] 0.08 0.25 0.17 0.12 NA 0.29 0.34 NA 0.89 0.63 ...
##  $ Carbon Footprint              : num [1:188] 0.18 0.87 1.14 0.2 NA 1.08 0.89 NA 4.85 4.14 ...
##  $ Fish Footprint                : num [1:188] 0 0.02 0.01 0.09 NA 0.1 0.01 NA 0.11 0.06 ...
##  $ Total Ecological Footprint    : num [1:188] 0.79 2.21 2.12 0.93 5.38 ...
##  $ Cropland                      : num [1:188] 0.24 0.55 0.24 0.2 NA 2.64 0.44 NA 5.42 0.71 ...
##  $ Grazing Land                  : num [1:188] 0.2 0.21 0.27 1.42 NA 1.86 0.26 NA 5.81 0.16 ...
##  $ Forest Land                   : num [1:188] 0.02 0.29 0.03 0.64 NA 0.66 0.1 NA 2.01 2.04 ...
##  $ Fishing Water                 : num [1:188] 0 0.07 0.01 0.26 NA 1.67 0.02 NA 3.19 0 ...
##  $ Urban Land                    : num [1:188] 0.04 0.06 0.03 0.04 NA 0.1 0.07 NA 0.14 0.15 ...
##  $ Total Biocapacity             : num [1:188] 0.5 1.18 0.59 2.55 0.94 ...
##  $ Biocapacity Deficit or Reserve: num [1:188] -0.3 -1.03 -1.53 1.61 -4.44 ...
##  $ Earths Required               : num [1:188] 0.46 1.27 1.22 0.54 3.11 1.82 1.29 6.86 5.37 3.5 ...
##  $ Countries Required            : num [1:188] 1.6 1.87 3.61 0.37 5.7 ...
##  $ Data Quality                  : chr [1:188] "6" "6" "5" "6" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   Country = col_character(),
##   ..   Region = col_character(),
##   ..   `Population (millions)` = col_double(),
##   ..   HDI = col_double(),
##   ..   `GDP per Capita` = col_character(),
##   ..   `Cropland Footprint` = col_double(),
##   ..   `Grazing Footprint` = col_double(),
##   ..   `Forest Footprint` = col_double(),
##   ..   `Carbon Footprint` = col_double(),
##   ..   `Fish Footprint` = col_double(),
##   ..   `Total Ecological Footprint` = col_double(),
##   ..   Cropland = col_double(),
##   ..   `Grazing Land` = col_double(),
##   ..   `Forest Land` = col_double(),
##   ..   `Fishing Water` = col_double(),
##   ..   `Urban Land` = col_double(),
##   ..   `Total Biocapacity` = col_double(),
##   ..   `Biocapacity Deficit or Reserve` = col_double(),
##   ..   `Earths Required` = col_double(),
##   ..   `Countries Required` = col_double(),
##   ..   `Data Quality` = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
# Lihat 6 data pertama
head(df)
## # A tibble: 6 × 21
##   Country             Region       Population (millions…¹   HDI `GDP per Capita`
##   <chr>               <chr>                         <dbl> <dbl> <chr>           
## 1 Afghanistan         Middle East…                  29.8   0.46 $614.66         
## 2 Albania             Northern/Ea…                   3.16  0.73 $4,534.37       
## 3 Algeria             Africa                        38.5   0.73 $5,430.57       
## 4 Angola              Africa                        20.8   0.52 $4,665.91       
## 5 Antigua and Barbuda Latin Ameri…                   0.09  0.78 $13,205.10      
## 6 Argentina           Latin Ameri…                  41.1   0.83 $13,540.00      
## # ℹ abbreviated name: ¹​`Population (millions)`
## # ℹ 16 more variables: `Cropland Footprint` <dbl>, `Grazing Footprint` <dbl>,
## #   `Forest Footprint` <dbl>, `Carbon Footprint` <dbl>, `Fish Footprint` <dbl>,
## #   `Total Ecological Footprint` <dbl>, Cropland <dbl>, `Grazing Land` <dbl>,
## #   `Forest Land` <dbl>, `Fishing Water` <dbl>, `Urban Land` <dbl>,
## #   `Total Biocapacity` <dbl>, `Biocapacity Deficit or Reserve` <dbl>,
## #   `Earths Required` <dbl>, `Countries Required` <dbl>, `Data Quality` <chr>

MEMASTIKAN NUMERIK dan Pemilihan variavel gunakan 10 sub-indeks

df_selected <- df[, c(
  "HDI",
  "Cropland Footprint",
  "Grazing Footprint",
  "Forest Footprint",
  "Carbon Footprint",
  "Fish Footprint",
  "Total Ecological Footprint",
  "Total Biocapacity",
  "Biocapacity Deficit or Reserve",
  "Earths Required"
)]

Cek missing:

colSums(is.na(df_selected))
##                            HDI             Cropland Footprint 
##                             16                             15 
##              Grazing Footprint               Forest Footprint 
##                             15                             15 
##               Carbon Footprint                 Fish Footprint 
##                             15                             15 
##     Total Ecological Footprint              Total Biocapacity 
##                              0                              0 
## Biocapacity Deficit or Reserve                Earths Required 
##                              0                              0

Imputasi median (jika ada NA):

df_selected <- data.frame(
  lapply(df_selected, function(x) {
    x[is.na(x)] <- median(x, na.rm = TRUE)
    return(x)
  })
)

colSums(is.na(df_selected))
##                            HDI             Cropland.Footprint 
##                              0                              0 
##              Grazing.Footprint               Forest.Footprint 
##                              0                              0 
##               Carbon.Footprint                 Fish.Footprint 
##                              0                              0 
##     Total.Ecological.Footprint              Total.Biocapacity 
##                              0                              0 
## Biocapacity.Deficit.or.Reserve                Earths.Required 
##                              0                              0
colSums(is.na(df_selected))
##                            HDI             Cropland.Footprint 
##                              0                              0 
##              Grazing.Footprint               Forest.Footprint 
##                              0                              0 
##               Carbon.Footprint                 Fish.Footprint 
##                              0                              0 
##     Total.Ecological.Footprint              Total.Biocapacity 
##                              0                              0 
## Biocapacity.Deficit.or.Reserve                Earths.Required 
##                              0                              0
head (df_selected)
##    HDI Cropland.Footprint Grazing.Footprint Forest.Footprint Carbon.Footprint
## 1 0.46               0.30              0.20             0.08             0.18
## 2 0.73               0.78              0.22             0.25             0.87
## 3 0.73               0.60              0.16             0.17             1.14
## 4 0.52               0.33              0.15             0.12             0.20
## 5 0.78               0.52              0.18             0.26             1.14
## 6 0.83               0.78              0.79             0.29             1.08
##   Fish.Footprint Total.Ecological.Footprint Total.Biocapacity
## 1           0.00                       0.79              0.50
## 2           0.02                       2.21              1.18
## 3           0.01                       2.12              0.59
## 4           0.09                       0.93              2.55
## 5           0.07                       5.38              0.94
## 6           0.10                       3.14              6.92
##   Biocapacity.Deficit.or.Reserve Earths.Required
## 1                          -0.30            0.46
## 2                          -1.03            1.27
## 3                          -1.53            1.22
## 4                           1.61            0.54
## 5                          -4.44            3.11
## 6                           3.78            1.82

KARAKTERISTIK DATA (statistika deskriptif)

describe(df_selected)
##                                vars   n mean    sd median trimmed  mad    min
## HDI                               1 188 0.69  0.15   0.72    0.70 0.15   0.34
## Cropland.Footprint                2 188 0.57  0.34   0.52    0.53 0.24   0.07
## Grazing.Footprint                 3 188 0.26  0.34   0.18    0.20 0.13   0.00
## Forest.Footprint                  4 188 0.36  0.35   0.26    0.31 0.17   0.01
## Carbon.Footprint                  5 188 1.75  1.83   1.14    1.46 1.37   0.00
## Fish.Footprint                    6 188 0.12  0.15   0.07    0.09 0.07   0.00
## Total.Ecological.Footprint        7 188 3.32  2.37   2.74    3.00 2.11   0.42
## Total.Biocapacity                 8 188 4.02 11.69   1.31    1.89 1.15   0.05
## Biocapacity.Deficit.or.Reserve    9 188 0.70 11.77  -0.73   -0.81 1.72 -14.14
## Earths.Required                  10 188 1.92  1.37   1.58    1.73 1.22   0.24
##                                   max  range  skew kurtosis   se
## HDI                              0.94   0.60 -0.43    -0.75 0.01
## Cropland.Footprint               2.68   2.61  2.53    10.52 0.02
## Grazing.Footprint                3.47   3.47  5.39    43.09 0.02
## Forest.Footprint                 3.03   3.02  3.57    20.02 0.03
## Carbon.Footprint                12.65  12.65  2.20     7.48 0.13
## Fish.Footprint                   0.82   0.82  2.55     7.13 0.01
## Total.Ecological.Footprint      15.82  15.40  1.60     3.97 0.17
## Total.Biocapacity              111.35 111.30  7.06    54.37 0.85
## Biocapacity.Deficit.or.Reserve 109.01 123.15  6.93    53.61 0.86
## Earths.Required                  9.14   8.90  1.60     3.97 0.10

KORELASI MATRIX

df_selected <- data.frame(lapply(df_selected, function(x) as.numeric(as.character(x))))
cor_matrix <- cor(df_selected)

corrplot(cor_matrix,
         method = "color",      # kotak warna
         type = "upper",        # segitiga atas
         addCoef.col = "black", # angka di dalam kotak
         number.cex = 0.7,      # ukuran angka
         tl.col = "black",      # warna nama variabel
         tl.srt = 45,           # rotasi label
         diag = FALSE)          # hilangkan diagonal

str(df_selected)
## 'data.frame':    188 obs. of  10 variables:
##  $ HDI                           : num  0.46 0.73 0.73 0.52 0.78 0.83 0.73 0.72 0.93 0.88 ...
##  $ Cropland.Footprint            : num  0.3 0.78 0.6 0.33 0.52 0.78 0.74 0.52 2.68 0.82 ...
##  $ Grazing.Footprint             : num  0.2 0.22 0.16 0.15 0.18 0.79 0.18 0.18 0.63 0.27 ...
##  $ Forest.Footprint              : num  0.08 0.25 0.17 0.12 0.26 0.29 0.34 0.26 0.89 0.63 ...
##  $ Carbon.Footprint              : num  0.18 0.87 1.14 0.2 1.14 1.08 0.89 1.14 4.85 4.14 ...
##  $ Fish.Footprint                : num  0 0.02 0.01 0.09 0.07 0.1 0.01 0.07 0.11 0.06 ...
##  $ Total.Ecological.Footprint    : num  0.79 2.21 2.12 0.93 5.38 ...
##  $ Total.Biocapacity             : num  0.5 1.18 0.59 2.55 0.94 ...
##  $ Biocapacity.Deficit.or.Reserve: num  -0.3 -1.03 -1.53 1.61 -4.44 ...
##  $ Earths.Required               : num  0.46 1.27 1.22 0.54 3.11 1.82 1.29 6.86 5.37 3.5 ...
colSums(is.na(df_selected))
##                            HDI             Cropland.Footprint 
##                              0                              0 
##              Grazing.Footprint               Forest.Footprint 
##                              0                              0 
##               Carbon.Footprint                 Fish.Footprint 
##                              0                              0 
##     Total.Ecological.Footprint              Total.Biocapacity 
##                              0                              0 
## Biocapacity.Deficit.or.Reserve                Earths.Required 
##                              0                              0
#cor_matrix <- cor(df_selected)

#corrplot(cor_matrix,
         #method = "color",
         # = "upper",
         #addCoef.col = "black",     # tampilkan angka
         #tl.col = "black",          # warna label
         #tl.srt = 45,               # rotasi label
         #number.cex = 0.7)          # ukuran angka

UJI ASUMSI

KMO(cor(df_selected))
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = cor(df_selected))
## Overall MSA =  0.71
## MSA for each item = 
##                            HDI             Cropland.Footprint 
##                           0.93                           0.85 
##              Grazing.Footprint               Forest.Footprint 
##                           0.76                           0.74 
##               Carbon.Footprint                 Fish.Footprint 
##                           0.95                           0.61 
##     Total.Ecological.Footprint              Total.Biocapacity 
##                           0.70                           0.39 
## Biocapacity.Deficit.or.Reserve                Earths.Required 
##                           0.40                           0.85

OPSIONAL DI MASUKKAN KE CODE APA ENGGA (saya buat soalnya biar bisa di publish di Rpubs)

# 1. Load Data
df <- read.csv("countries.csv")

# 2. Scaling (Pastikan baris ini ada DI ATAS baris KMO)
df_scaled <- scale(df[, c(
  "HDI",
  "Cropland.Footprint",
  "Grazing.Footprint",
  "Forest.Footprint",
  "Carbon.Footprint",
  "Fish.Footprint",
  "Total.Ecological.Footprint",
  "Total.Biocapacity",
  "Biocapacity.Deficit.or.Reserve",
  "Earths.Required"
)])

# 3. Baru panggil KMO
library(psych)
KMO(df_scaled)
## Warning in sqrt(S2): NaNs produced
## Warning in cov2cor(Q): diag(V) had non-positive or NA entries; the non-finite
## result may be dubious
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = df_scaled)
## Overall MSA =  NaN
## MSA for each item = 
##                            HDI             Cropland.Footprint 
##                            NaN                            NaN 
##              Grazing.Footprint               Forest.Footprint 
##                            NaN                            NaN 
##               Carbon.Footprint                 Fish.Footprint 
##                            NaN                            NaN 
##     Total.Ecological.Footprint              Total.Biocapacity 
##                            NaN                            NaN 
## Biocapacity.Deficit.or.Reserve                Earths.Required 
##                            NaN                            NaN
KMO(df_scaled)
## Warning in sqrt(S2): NaNs produced
## Warning in cov2cor(Q): diag(V) had non-positive or NA entries; the non-finite
## result may be dubious
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = df_scaled)
## Overall MSA =  NaN
## MSA for each item = 
##                            HDI             Cropland.Footprint 
##                            NaN                            NaN 
##              Grazing.Footprint               Forest.Footprint 
##                            NaN                            NaN 
##               Carbon.Footprint                 Fish.Footprint 
##                            NaN                            NaN 
##     Total.Ecological.Footprint              Total.Biocapacity 
##                            NaN                            NaN 
## Biocapacity.Deficit.or.Reserve                Earths.Required 
##                            NaN                            NaN
df_selected2 <- df_selected[, names(df_selected) != "Total.Biocapacity"]

colnames(df_selected2)
## [1] "HDI"                            "Cropland.Footprint"            
## [3] "Grazing.Footprint"              "Forest.Footprint"              
## [5] "Carbon.Footprint"               "Fish.Footprint"                
## [7] "Total.Ecological.Footprint"     "Biocapacity.Deficit.or.Reserve"
## [9] "Earths.Required"
df_scaled2 <- scale(df_selected2)

KMO(df_scaled2)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = df_scaled2)
## Overall MSA =  0.8
## MSA for each item = 
##                            HDI             Cropland.Footprint 
##                           0.93                           0.85 
##              Grazing.Footprint               Forest.Footprint 
##                           0.73                           0.69 
##               Carbon.Footprint                 Fish.Footprint 
##                           0.95                           0.78 
##     Total.Ecological.Footprint Biocapacity.Deficit.or.Reserve 
##                           0.73                           0.60 
##                Earths.Required 
##                           0.73

Bartlett Test

cortest.bartlett(cor(df_scaled2), n = nrow(df_scaled2))
## $chisq
## [1] 2756.2
## 
## $p.value
## [1] 0
## 
## $df
## [1] 36

STANDARISASI DATA

df_scaled <- scale(df_selected2)
df_scaled_matrix <- scale(df_selected2)
attr(df_scaled, "scaled:center")
##                            HDI             Cropland.Footprint 
##                      0.6892226                      0.5735638 
##              Grazing.Footprint               Forest.Footprint 
##                      0.2565426                      0.3647340 
##               Carbon.Footprint                 Fish.Footprint 
##                      1.7518617                      0.1182979 
##     Total.Ecological.Footprint Biocapacity.Deficit.or.Reserve 
##                      3.3176064                      0.7020745 
##                Earths.Required 
##                      1.9157447
colMeans(df_scaled)
##                            HDI             Cropland.Footprint 
##                  -2.318716e-16                  -9.674774e-17 
##              Grazing.Footprint               Forest.Footprint 
##                  -6.352041e-17                   5.755037e-17 
##               Carbon.Footprint                 Fish.Footprint 
##                   5.880528e-17                  -2.629767e-17 
##     Total.Ecological.Footprint Biocapacity.Deficit.or.Reserve 
##                  -2.744185e-17                   4.775103e-18 
##                Earths.Required 
##                  -6.874303e-19
apply(df_scaled, 2, sd)
##                            HDI             Cropland.Footprint 
##                              1                              1 
##              Grazing.Footprint               Forest.Footprint 
##                              1                              1 
##               Carbon.Footprint                 Fish.Footprint 
##                              1                              1 
##     Total.Ecological.Footprint Biocapacity.Deficit.or.Reserve 
##                              1                              1 
##                Earths.Required 
##                              1

MELIHAT MEAN ASLI PAKE SCALE ()

attr(df_scaled_matrix, "scaled:center")
##                            HDI             Cropland.Footprint 
##                      0.6892226                      0.5735638 
##              Grazing.Footprint               Forest.Footprint 
##                      0.2565426                      0.3647340 
##               Carbon.Footprint                 Fish.Footprint 
##                      1.7518617                      0.1182979 
##     Total.Ecological.Footprint Biocapacity.Deficit.or.Reserve 
##                      3.3176064                      0.7020745 
##                Earths.Required 
##                      1.9157447
df_scaled <- as.data.frame(df_scaled)
head(df_scaled)
##          HDI Cropland.Footprint Grazing.Footprint Forest.Footprint
## 1 -1.5331435        -0.80108097        -0.1670847       -0.8228831
## 2  0.2727377         0.60451006        -0.1079842       -0.3315821
## 3  0.2727377         0.07741342        -0.2852857       -0.5627825
## 4 -1.1318366        -0.71323153        -0.3148360       -0.7072828
## 5  0.6071601        -0.15685175        -0.2261852       -0.3026820
## 6  0.9415825         0.60451006         1.5763803       -0.2159818
##   Carbon.Footprint Fish.Footprint Total.Ecological.Footprint
## 1       -0.8591763     -0.7751770                -1.06608162
## 2       -0.4820238     -0.6441219                -0.46716088
## 3       -0.3344423     -0.7096495                -0.50512064
## 4       -0.8482444     -0.1854290                -1.00703310
## 5       -0.3344423     -0.3164841                 0.86986643
## 6       -0.3672382     -0.1199015                -0.07490996
##   Biocapacity.Deficit.or.Reserve Earths.Required
## 1                    -0.08512833     -1.06287918
## 2                    -0.14714337     -0.47147593
## 3                    -0.18961942     -0.50798230
## 4                     0.07713018     -1.00446899
## 5                    -0.43683005      0.87195862
## 6                     0.26147625     -0.06990582

PRINCIPAL COMPONENT ANALYSIS

pca <- prcomp(df_scaled2, center = TRUE, scale. = TRUE)

summary(pca)
## Importance of components:
##                           PC1    PC2    PC3    PC4    PC5     PC6     PC7
## Standard deviation     2.0089 1.0837 1.0148 0.9923 0.8679 0.73770 0.57982
## Proportion of Variance 0.4484 0.1305 0.1144 0.1094 0.0837 0.06047 0.03735
## Cumulative Proportion  0.4484 0.5789 0.6933 0.8027 0.8864 0.94690 0.98425
##                            PC8      PC9
## Standard deviation     0.37646 0.001763
## Proportion of Variance 0.01575 0.000000
## Cumulative Proportion  1.00000 1.000000

Tentukan jumlah komponen

eigen_value <- pca$sdev^2
eigen_value
## [1] 4.035797e+00 1.174348e+00 1.029837e+00 9.846036e-01 7.532913e-01
## [6] 5.442080e-01 3.361878e-01 1.417235e-01 3.107763e-06
eigen_value[eigen_value > 1]
## [1] 4.035797 1.174348 1.029837
data.frame(
  Komponen = paste0("PC", 1:length(pca$sdev)),
  Eigenvalue = pca$sdev^2,
  Proporsi_Varian = (pca$sdev^2) / sum(pca$sdev^2),
  Kumulatif = cumsum((pca$sdev^2) / sum(pca$sdev^2))
)
##   Komponen   Eigenvalue Proporsi_Varian Kumulatif
## 1      PC1 4.035797e+00    4.484219e-01 0.4484219
## 2      PC2 1.174348e+00    1.304831e-01 0.5789051
## 3      PC3 1.029837e+00    1.144263e-01 0.6933314
## 4      PC4 9.846036e-01    1.094004e-01 0.8027318
## 5      PC5 7.532913e-01    8.369903e-02 0.8864308
## 6      PC6 5.442080e-01    6.046756e-02 0.9468984
## 7      PC7 3.361878e-01    3.735420e-02 0.9842526
## 8      PC8 1.417235e-01    1.574706e-02 0.9999997
## 9      PC9 3.107763e-06    3.453070e-07 1.0000000

Scree Plot

fviz_eig(pca, addlabels = TRUE)
## Warning in geom_bar(stat = "identity", fill = barfill, color = barcolor, :
## Ignoring empty aesthetic: `width`.

prop_var <- eigen_value / sum(eigen_value)
cum_var <- cumsum(prop_var)

data.frame(
  PC = paste0("PC", 1:length(eigen_value)),
  Eigenvalue = eigen_value,
  Proporsi = prop_var,
  Kumulatif = cum_var
)
##    PC   Eigenvalue     Proporsi Kumulatif
## 1 PC1 4.035797e+00 4.484219e-01 0.4484219
## 2 PC2 1.174348e+00 1.304831e-01 0.5789051
## 3 PC3 1.029837e+00 1.144263e-01 0.6933314
## 4 PC4 9.846036e-01 1.094004e-01 0.8027318
## 5 PC5 7.532913e-01 8.369903e-02 0.8864308
## 6 PC6 5.442080e-01 6.046756e-02 0.9468984
## 7 PC7 3.361878e-01 3.735420e-02 0.9842526
## 8 PC8 1.417235e-01 1.574706e-02 0.9999997
## 9 PC9 3.107763e-06 3.453070e-07 1.0000000

LOADINGS (INTERPRETASI)

loading <- pca$rotation
loading
##                                        PC1         PC2         PC3         PC4
## HDI                             0.39962722 -0.11229071 -0.09806487 -0.03464002
## Cropland.Footprint              0.33813409  0.20592000 -0.22439714  0.26731629
## Grazing.Footprint               0.11793849  0.29904237  0.69433812 -0.44228385
## Forest.Footprint                0.21729301  0.58116165 -0.31467874  0.25513385
## Carbon.Footprint                0.43583516 -0.16854262  0.08556846 -0.05713497
## Fish.Footprint                  0.10544646 -0.44297920 -0.47288446 -0.54142659
## Total.Ecological.Footprint      0.47859700 -0.02678479  0.09310399 -0.04532560
## Biocapacity.Deficit.or.Reserve -0.07514487  0.54013932 -0.33259280 -0.60509031
## Earths.Required                 0.47860694 -0.02659784  0.09312930 -0.04514343
##                                       PC5         PC6         PC7          PC8
## HDI                            -0.2136665  0.41554952 -0.77364141  0.004052255
## Cropland.Footprint              0.2872232  0.66253349  0.43730384 -0.093636086
## Grazing.Footprint               0.4246501  0.12689615 -0.10039717 -0.111507093
## Forest.Footprint                0.3502886 -0.47483509 -0.29608269 -0.122814494
## Carbon.Footprint               -0.2901083 -0.22952148  0.19410073 -0.772357840
## Fish.Footprint                  0.5166516 -0.09183116  0.01082753 -0.020220622
## Total.Ecological.Footprint     -0.1036426 -0.19206130  0.16911231  0.428361924
## Biocapacity.Deficit.or.Reserve -0.4429702  0.10852156  0.13274722  0.015138940
## Earths.Required                -0.1037479 -0.19240433  0.16877985  0.427820055
##                                          PC9
## HDI                            -7.716656e-05
## Cropland.Footprint              1.889865e-04
## Grazing.Footprint               2.286860e-07
## Forest.Footprint               -3.113628e-04
## Carbon.Footprint               -3.025181e-04
## Fish.Footprint                  1.469850e-04
## Total.Ecological.Footprint     -7.069529e-01
## Biocapacity.Deficit.or.Reserve  4.339122e-05
## Earths.Required                 7.072604e-01

MENGAMBIL SAMPAI PC3 KARENA EIGENVALUE > 1

loading <- pca$rotation[,1:3]
round(loading,2)
##                                  PC1   PC2   PC3
## HDI                             0.40 -0.11 -0.10
## Cropland.Footprint              0.34  0.21 -0.22
## Grazing.Footprint               0.12  0.30  0.69
## Forest.Footprint                0.22  0.58 -0.31
## Carbon.Footprint                0.44 -0.17  0.09
## Fish.Footprint                  0.11 -0.44 -0.47
## Total.Ecological.Footprint      0.48 -0.03  0.09
## Biocapacity.Deficit.or.Reserve -0.08  0.54 -0.33
## Earths.Required                 0.48 -0.03  0.09

INTERPRETASI KOMPONEN

library(psych)
print.psych(loading, cut = 0.5)

METODE FAKTOR AALYSIS (FA)

varcov = cov(df_scaled)
pc = eigen(varcov)

cat("eigen value:")
## eigen value:
pc$values
## [1] 4.035797e+00 1.174348e+00 1.029837e+00 9.846036e-01 7.532913e-01
## [6] 5.442080e-01 3.361878e-01 1.417235e-01 3.107763e-06
cat("eigen vector:")
## eigen vector:
pc$vectors
##              [,1]        [,2]        [,3]        [,4]       [,5]        [,6]
##  [1,] -0.39962722 -0.11229071 -0.09806487  0.03464002 -0.2136665  0.41554952
##  [2,] -0.33813409  0.20592000 -0.22439714 -0.26731629  0.2872232  0.66253349
##  [3,] -0.11793849  0.29904237  0.69433812  0.44228385  0.4246501  0.12689615
##  [4,] -0.21729301  0.58116165 -0.31467874 -0.25513385  0.3502886 -0.47483509
##  [5,] -0.43583516 -0.16854262  0.08556846  0.05713497 -0.2901083 -0.22952148
##  [6,] -0.10544646 -0.44297920 -0.47288446  0.54142659  0.5166516 -0.09183116
##  [7,] -0.47859700 -0.02678479  0.09310399  0.04532560 -0.1036426 -0.19206130
##  [8,]  0.07514487  0.54013932 -0.33259280  0.60509031 -0.4429702  0.10852156
##  [9,] -0.47860694 -0.02659784  0.09312930  0.04514343 -0.1037479 -0.19240433
##              [,7]         [,8]          [,9]
##  [1,]  0.77364141 -0.004052255 -7.716656e-05
##  [2,] -0.43730384  0.093636086  1.889865e-04
##  [3,]  0.10039717  0.111507093  2.286860e-07
##  [4,]  0.29608269  0.122814494 -3.113628e-04
##  [5,] -0.19410073  0.772357840 -3.025181e-04
##  [6,] -0.01082753  0.020220622  1.469850e-04
##  [7,] -0.16911231 -0.428361924 -7.069529e-01
##  [8,] -0.13274722 -0.015138940  4.339122e-05
##  [9,] -0.16877985 -0.427820055  7.072604e-01
sp = sum(pc$values[1:3])

L1 = sqrt(pc$values[1])*pc$vectors[,1]
L2 = sqrt(pc$values[2])*pc$vectors[,2]
L3 = sqrt(pc$values[3])*pc$vectors[,3]

L = cbind(L1,L2,L3)
cat("factor loading:")
## factor loading:
L
##               L1          L2          L3
##  [1,] -0.8028229 -0.12168646 -0.09951709
##  [2,] -0.6792875  0.22315005 -0.22772019
##  [3,] -0.2369301  0.32406429  0.70462044
##  [4,] -0.4365263  0.62978948 -0.31933875
##  [5,] -0.8755621 -0.18264517  0.08683563
##  [6,] -0.2118345 -0.48004481 -0.47988731
##  [7,] -0.9614676 -0.02902597  0.09448275
##  [8,]  0.1509607  0.58533466 -0.33751810
##  [9,] -0.9614876 -0.02882337  0.09450844

FA with function Principal

fa <- principal(df_scaled, nfactors = 3, rotate = "none")
fa
## Principal Components Analysis
## Call: principal(r = df_scaled, nfactors = 3, rotate = "none")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                                  PC1   PC2   PC3   h2    u2 com
## HDI                             0.80 -0.12  0.10 0.67 0.331 1.1
## Cropland.Footprint              0.68  0.22  0.23 0.56 0.437 1.5
## Grazing.Footprint               0.24  0.32 -0.70 0.66 0.342 1.7
## Forest.Footprint                0.44  0.63  0.32 0.69 0.311 2.3
## Carbon.Footprint                0.88 -0.18 -0.09 0.81 0.192 1.1
## Fish.Footprint                  0.21 -0.48  0.48 0.51 0.494 2.4
## Total.Ecological.Footprint      0.96 -0.03 -0.09 0.93 0.066 1.0
## Biocapacity.Deficit.or.Reserve -0.15  0.59  0.34 0.48 0.521 1.8
## Earths.Required                 0.96 -0.03 -0.09 0.93 0.066 1.0
## 
##                        PC1  PC2  PC3
## SS loadings           4.04 1.17 1.03
## Proportion Var        0.45 0.13 0.11
## Cumulative Var        0.45 0.58 0.69
## Proportion Explained  0.65 0.19 0.17
## Cumulative Proportion 0.65 0.83 1.00
## 
## Mean item complexity =  1.5
## Test of the hypothesis that 3 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.08 
##  with the empirical chi square  83.74  with prob <  8e-13 
## 
## Fit based upon off diagonal values = 0.96
df_scaled <- as.matrix(scale(df_selected2))
str(df_scaled)
##  num [1:188, 1:9] -1.533 0.273 0.273 -1.132 0.607 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:9] "HDI" "Cropland.Footprint" "Grazing.Footprint" "Forest.Footprint" ...
##  - attr(*, "scaled:center")= Named num [1:9] 0.689 0.574 0.257 0.365 1.752 ...
##   ..- attr(*, "names")= chr [1:9] "HDI" "Cropland.Footprint" "Grazing.Footprint" "Forest.Footprint" ...
##  - attr(*, "scaled:scale")= Named num [1:9] 0.15 0.341 0.338 0.346 1.829 ...
##   ..- attr(*, "names")= chr [1:9] "HDI" "Cropland.Footprint" "Grazing.Footprint" "Forest.Footprint" ...
cor_matrix <- cor(df_scaled)

det(cor_matrix)
## [1] 2.91713e-07
round(cor(df_scaled), 2)
##                                  HDI Cropland.Footprint Grazing.Footprint
## HDI                             1.00               0.52              0.08
## Cropland.Footprint              0.52               1.00              0.08
## Grazing.Footprint               0.08               0.08              1.00
## Forest.Footprint                0.21               0.44              0.06
## Carbon.Footprint                0.66               0.41              0.13
## Fish.Footprint                  0.19               0.08             -0.05
## Total.Ecological.Footprint      0.70               0.54              0.25
## Biocapacity.Deficit.or.Reserve -0.08              -0.09              0.04
## Earths.Required                 0.70               0.54              0.25
##                                Forest.Footprint Carbon.Footprint Fish.Footprint
## HDI                                        0.21             0.66           0.19
## Cropland.Footprint                         0.44             0.41           0.08
## Grazing.Footprint                          0.06             0.13          -0.05
## Forest.Footprint                           1.00             0.20          -0.03
## Carbon.Footprint                           0.20             1.00           0.16
## Fish.Footprint                            -0.03             0.16           1.00
## Total.Ecological.Footprint                 0.36             0.87           0.17
## Biocapacity.Deficit.or.Reserve             0.10            -0.14          -0.01
## Earths.Required                            0.36             0.87           0.16
##                                Total.Ecological.Footprint
## HDI                                                  0.70
## Cropland.Footprint                                   0.54
## Grazing.Footprint                                    0.25
## Forest.Footprint                                     0.36
## Carbon.Footprint                                     0.87
## Fish.Footprint                                       0.17
## Total.Ecological.Footprint                           1.00
## Biocapacity.Deficit.or.Reserve                      -0.14
## Earths.Required                                      1.00
##                                Biocapacity.Deficit.or.Reserve Earths.Required
## HDI                                                     -0.08            0.70
## Cropland.Footprint                                      -0.09            0.54
## Grazing.Footprint                                        0.04            0.25
## Forest.Footprint                                         0.10            0.36
## Carbon.Footprint                                        -0.14            0.87
## Fish.Footprint                                          -0.01            0.16
## Total.Ecological.Footprint                              -0.14            1.00
## Biocapacity.Deficit.or.Reserve                           1.00           -0.14
## Earths.Required                                         -0.14            1.00
df_reduced <- df_selected2[, 
  !(names(df_selected2) %in% c("Earths.Required"))
]
df_scaled <- scale(df_reduced)
det(cor(df_scaled))
## [1] 0.0469538
colnames(df_scaled)
## [1] "HDI"                            "Cropland.Footprint"            
## [3] "Grazing.Footprint"              "Forest.Footprint"              
## [5] "Carbon.Footprint"               "Fish.Footprint"                
## [7] "Total.Ecological.Footprint"     "Biocapacity.Deficit.or.Reserve"

Factor Analysis with rotation varimax

fa_1 <- principal(df_scaled, nfactors = 3, rotate = "varimax")
fa_1
## Principal Components Analysis
## Call: principal(r = df_scaled, nfactors = 3, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                                  RC1   RC2   RC3   h2   u2 com
## HDI                             0.83 -0.01 -0.11 0.70 0.30 1.0
## Cropland.Footprint              0.70  0.31  0.01 0.58 0.42 1.4
## Grazing.Footprint               0.21 -0.07  0.74 0.59 0.41 1.2
## Forest.Footprint                0.40  0.70  0.12 0.67 0.33 1.7
## Carbon.Footprint                0.87 -0.14  0.00 0.78 0.22 1.1
## Fish.Footprint                  0.25 -0.10 -0.70 0.56 0.44 1.3
## Total.Ecological.Footprint      0.93 -0.01  0.09 0.88 0.12 1.0
## Biocapacity.Deficit.or.Reserve -0.21  0.72 -0.05 0.57 0.43 1.2
## 
##                        RC1  RC2  RC3
## SS loadings           3.12 1.14 1.07
## Proportion Var        0.39 0.14 0.13
## Cumulative Var        0.39 0.53 0.67
## Proportion Explained  0.59 0.21 0.20
## Cumulative Proportion 0.59 0.80 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 3 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.09 
##  with the empirical chi square  86.22  with prob <  7.4e-16 
## 
## Fit based upon off diagonal values = 0.93
scores <- factor.scores(df_scaled, fa_1, method = "regression")
head(scores$scores)
##             RC1           RC2         RC3
## [1,] -1.3043640 -0.4059612527  0.44008295
## [2,] -0.1618322  0.0001942359  0.25738952
## [3,] -0.2783624 -0.2909968041  0.17155656
## [4,] -1.1170970 -0.2500024208 -0.09504026
## [5,]  0.2653933 -0.4798952378  0.07169314
## [6,]  0.2980877  0.0451555327  1.01545927