1. Import Data

Di tahap ini, dataset CSV dimuat ke dalam R untuk dianalisis.

data <- read.csv("C:/Users/ella/OneDrive/ドキュメント/Semester 4/Tugas2_Anmul/global-data-on-sustainable-energy (1).csv")

2. Cek struktur dan ringkasan

Memeriksa struktur dataset dan ringkasan statistik awal untuk mengetahui tipe data dan distribusi nilai.

str(data)
## 'data.frame':    3649 obs. of  21 variables:
##  $ Entity                                                          : chr  "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
##  $ Year                                                            : int  2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 ...
##  $ Access.to.electricity....of.population.                         : num  1.61 4.07 9.41 14.74 20.06 ...
##  $ Access.to.clean.fuels.for.cooking                               : num  6.2 7.2 8.2 9.5 10.9 ...
##  $ Renewable.electricity.generating.capacity.per.capita            : num  9.22 8.86 8.47 8.09 7.75 7.51 7.4 7.25 7.49 7.5 ...
##  $ Financial.flows.to.developing.countries..US...                  : num  20000 130000 3950000 25970000 NA ...
##  $ Renewable.energy.share.in.the.total.final.energy.consumption....: num  45 45.6 37.8 36.7 44.2 ...
##  $ Electricity.from.fossil.fuels..TWh.                             : num  0.16 0.09 0.13 0.31 0.33 0.34 0.2 0.2 0.19 0.16 ...
##  $ Electricity.from.nuclear..TWh.                                  : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Electricity.from.renewables..TWh.                               : num  0.31 0.5 0.56 0.63 0.56 0.59 0.64 0.75 0.54 0.78 ...
##  $ Low.carbon.electricity....electricity.                          : num  66 84.7 81.2 67 62.9 ...
##  $ Primary.energy.consumption.per.capita..kWh.person.              : num  303 237 211 230 204 ...
##  $ Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP.     : num  1.64 1.74 1.4 1.4 1.2 1.41 1.5 1.53 1.94 2.25 ...
##  $ Value_co2_emissions_kt_by_country                               : num  760 730 1030 1220 1030 ...
##  $ Renewables....equivalent.primary.energy.                        : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ gdp_growth                                                      : num  NA NA NA 8.83 1.41 ...
##  $ gdp_per_capita                                                  : num  NA NA 179 191 211 ...
##  $ Density.n.P.Km2.                                                : chr  "60" "60" "60" "60" ...
##  $ Land.Area.Km2.                                                  : int  652230 652230 652230 652230 652230 652230 652230 652230 652230 652230 ...
##  $ Latitude                                                        : num  33.9 33.9 33.9 33.9 33.9 ...
##  $ Longitude                                                       : num  67.7 67.7 67.7 67.7 67.7 ...
summary(data)
##     Entity               Year      Access.to.electricity....of.population.
##  Length:3649        Min.   :2000   Min.   :  1.252                        
##  Class :character   1st Qu.:2005   1st Qu.: 59.801                        
##  Mode  :character   Median :2010   Median : 98.362                        
##                     Mean   :2010   Mean   : 78.934                        
##                     3rd Qu.:2015   3rd Qu.:100.000                        
##                     Max.   :2020   Max.   :100.000                        
##                                    NA's   :10                             
##  Access.to.clean.fuels.for.cooking
##  Min.   :  0.00                   
##  1st Qu.: 23.18                   
##  Median : 83.15                   
##  Mean   : 63.26                   
##  3rd Qu.:100.00                   
##  Max.   :100.00                   
##  NA's   :169                      
##  Renewable.electricity.generating.capacity.per.capita
##  Min.   :   0.00                                     
##  1st Qu.:   3.54                                     
##  Median :  32.91                                     
##  Mean   : 113.14                                     
##  3rd Qu.: 112.21                                     
##  Max.   :3060.19                                     
##  NA's   :931                                         
##  Financial.flows.to.developing.countries..US...
##  Min.   :0.000e+00                             
##  1st Qu.:2.600e+05                             
##  Median :5.665e+06                             
##  Mean   :9.422e+07                             
##  3rd Qu.:5.535e+07                             
##  Max.   :5.202e+09                             
##  NA's   :2089                                  
##  Renewable.energy.share.in.the.total.final.energy.consumption....
##  Min.   : 0.000                                                  
##  1st Qu.: 6.515                                                  
##  Median :23.300                                                  
##  Mean   :32.638                                                  
##  3rd Qu.:55.245                                                  
##  Max.   :96.040                                                  
##  NA's   :194                                                     
##  Electricity.from.fossil.fuels..TWh. Electricity.from.nuclear..TWh.
##  Min.   :   0.00                     Min.   :  0.00                
##  1st Qu.:   0.29                     1st Qu.:  0.00                
##  Median :   2.97                     Median :  0.00                
##  Mean   :  70.36                     Mean   : 13.45                
##  3rd Qu.:  26.84                     3rd Qu.:  0.00                
##  Max.   :5184.13                     Max.   :809.41                
##  NA's   :21                          NA's   :126                   
##  Electricity.from.renewables..TWh. Low.carbon.electricity....electricity.
##  Min.   :   0.00                   Min.   :  0.000                       
##  1st Qu.:   0.04                   1st Qu.:  2.878                       
##  Median :   1.47                   Median : 27.865                       
##  Mean   :  23.97                   Mean   : 36.801                       
##  3rd Qu.:   9.60                   3rd Qu.: 64.404                       
##  Max.   :2184.94                   Max.   :100.000                       
##  NA's   :21                        NA's   :42                            
##  Primary.energy.consumption.per.capita..kWh.person.
##  Min.   :     0                                    
##  1st Qu.:  3117                                    
##  Median : 13121                                    
##  Mean   : 25744                                    
##  3rd Qu.: 33893                                    
##  Max.   :262586                                    
##                                                    
##  Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP.
##  Min.   : 0.110                                             
##  1st Qu.: 3.170                                             
##  Median : 4.300                                             
##  Mean   : 5.307                                             
##  3rd Qu.: 6.027                                             
##  Max.   :32.570                                             
##  NA's   :207                                                
##  Value_co2_emissions_kt_by_country Renewables....equivalent.primary.energy.
##  Min.   :      10                  Min.   : 0.000                          
##  1st Qu.:    2020                  1st Qu.: 2.137                          
##  Median :   10500                  Median : 6.291                          
##  Mean   :  159866                  Mean   :11.987                          
##  3rd Qu.:   60580                  3rd Qu.:16.842                          
##  Max.   :10707220                  Max.   :86.837                          
##  NA's   :428                       NA's   :2137                            
##    gdp_growth      gdp_per_capita     Density.n.P.Km2.   Land.Area.Km2.   
##  Min.   :-62.076   Min.   :   111.9   Length:3649        Min.   :     21  
##  1st Qu.:  1.383   1st Qu.:  1337.8   Class :character   1st Qu.:  25713  
##  Median :  3.560   Median :  4578.6   Mode  :character   Median : 117600  
##  Mean   :  3.442   Mean   : 13283.8                      Mean   : 633213  
##  3rd Qu.:  5.830   3rd Qu.: 15768.6                      3rd Qu.: 513120  
##  Max.   :123.140   Max.   :123514.2                      Max.   :9984670  
##  NA's   :317       NA's   :282                           NA's   :1        
##     Latitude         Longitude      
##  Min.   :-40.901   Min.   :-175.20  
##  1st Qu.:  3.203   1st Qu.: -11.78  
##  Median : 17.190   Median :  19.15  
##  Mean   : 18.246   Mean   :  14.82  
##  3rd Qu.: 38.970   3rd Qu.:  46.20  
##  Max.   : 64.963   Max.   : 178.07  
##  NA's   :1         NA's   :1

3. Data Cleaning dan Preprocessing

Tahap ini bertujuan menyiapkan data agar siap untuk analisis PCA dan FA. ### 3.1 Ubah kolom karakter menjadi numeric

data$Density.n.P.Km2. <- as.numeric(data$Density.n.P.Km2.)
## Warning: NAs introduced by coercion

3.2 Pilih semua kolom numeric

data_numeric <- data[, sapply(data, is.numeric)]

3.3 Hapus kolom yang tidak relevan

Kolom seperti Year, Latitude, Longitude, dan Electricity from nuclear dihapus karena tidak relevan atau sebagian besar bernilai 0.

sum(data$Electricity.from.nuclear..TWh. == 0, na.rm = TRUE)
## [1] 2945
data_numeric <- subset(data_numeric, 
                             select = -c(Year, Latitude, Longitude, Land.Area.Km2., 
                                         Electricity.from.nuclear..TWh.))

3.4 Cek Persentase Missing Value per Variabel

Memeriksa seberapa banyak data hilang di tiap variabel.

na_percent <- colSums(is.na(data_numeric)) / nrow(data_numeric) * 100

tabel_na <- data.frame(
  Variabel = names(na_percent),
  Persen_NA = round(na_percent, 2)
)

kable(tabel_na,
      caption = "Tabel Persentase Missing Value per Variabel",
      row.names = FALSE)
Tabel Persentase Missing Value per Variabel
Variabel Persen_NA
Access.to.electricity….of.population. 0.27
Access.to.clean.fuels.for.cooking 4.63
Renewable.electricity.generating.capacity.per.capita 25.51
Financial.flows.to.developing.countries..US… 57.25
Renewable.energy.share.in.the.total.final.energy.consumption…. 5.32
Electricity.from.fossil.fuels..TWh. 0.58
Electricity.from.renewables..TWh. 0.58
Low.carbon.electricity….electricity. 1.15
Primary.energy.consumption.per.capita..kWh.person. 0.00
Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. 5.67
Value_co2_emissions_kt_by_country 11.73
Renewables….equivalent.primary.energy. 58.56
gdp_growth 8.69
gdp_per_capita 7.73
Density.n.P.Km2. 2.90

3.5 Hapus variabel dengan NA > 30%

Variabel dengan missing value lebih dari 30% dihapus untuk menjaga kualitas data.

threshold <- 30

variabel_dihapus <- names(na_percent[na_percent > threshold])

data_numeric <- data_numeric[, na_percent <= threshold]

variabel_dihapus
## [1] "Financial.flows.to.developing.countries..US..."
## [2] "Renewables....equivalent.primary.energy."

3.6 Cek Skewness

Melihat distribusi data, apakah simetris atau skewed.

desc_stats <- describe(data_numeric)

tabel_skew <- data.frame(
  Variabel = rownames(desc_stats),
  Skewness = round(desc_stats$skew, 3)
)

kable(tabel_skew, caption = "Nilai Skewness Tiap Variabel")
Nilai Skewness Tiap Variabel
Variabel Skewness
Access.to.electricity….of.population. -1.205
Access.to.clean.fuels.for.cooking -0.508
Renewable.electricity.generating.capacity.per.capita 5.361
Renewable.energy.share.in.the.total.final.energy.consumption…. 0.670
Electricity.from.fossil.fuels..TWh. 9.389
Electricity.from.renewables..TWh. 11.048
Low.carbon.electricity….electricity. 0.506
Primary.energy.consumption.per.capita..kWh.person. 2.649
Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. 2.587
Value_co2_emissions_kt_by_country 9.329
gdp_growth 2.540
gdp_per_capita 2.357
Density.n.P.Km2. 2.797

3.7 Tangani Missing Value dengan Median Imputation

Mengganti nilai hilang dengan median tiap kolom agar tidak mempengaruhi analisis.

for(i in 1:ncol(data_numeric)){
  data_numeric[is.na(data_numeric[, i]), i] <- 
    median(data_numeric[, i], na.rm = TRUE)
}

3.8 Cek kembali apakah masih ada Missing Value (NA)

colSums(is.na(data_numeric))
##                          Access.to.electricity....of.population. 
##                                                                0 
##                                Access.to.clean.fuels.for.cooking 
##                                                                0 
##             Renewable.electricity.generating.capacity.per.capita 
##                                                                0 
## Renewable.energy.share.in.the.total.final.energy.consumption.... 
##                                                                0 
##                              Electricity.from.fossil.fuels..TWh. 
##                                                                0 
##                                Electricity.from.renewables..TWh. 
##                                                                0 
##                           Low.carbon.electricity....electricity. 
##                                                                0 
##               Primary.energy.consumption.per.capita..kWh.person. 
##                                                                0 
##      Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. 
##                                                                0 
##                                Value_co2_emissions_kt_by_country 
##                                                                0 
##                                                       gdp_growth 
##                                                                0 
##                                                   gdp_per_capita 
##                                                                0 
##                                                 Density.n.P.Km2. 
##                                                                0

3.9 Mengecek Outlier

3.9.1 Visualisasi Outlier dengan Boxplot

for(i in 1:ncol(data_numeric)){
  boxplot(data_numeric[, i],
          main = paste("Boxplot", colnames(data_numeric)[i]),
          col = "lightblue",
          ylab = colnames(data_numeric)[i],
          cex.main = 1,   
          cex.lab = 0.8,  
          cex.axis = 0.8) 
}

3.9.2 Analisis Outlier per Variabel

count_outliers <- function(x){
  Q1 <- quantile(x, 0.25, na.rm = TRUE)
  Q3 <- quantile(x, 0.75, na.rm = TRUE)
  IQR <- Q3 - Q1
  sum(x < (Q1 - 1.5*IQR) | x > (Q3 + 1.5*IQR), na.rm = TRUE)
}


outlier_counts <- sapply(data_numeric, count_outliers)


outlier_table <- data.frame(
  Variabel = names(outlier_counts),
  Jumlah_Outlier = outlier_counts
)


outlier_table <- outlier_table[order(-outlier_table$Jumlah_Outlier), ]


for(i in 1:nrow(outlier_table)){
  cat(outlier_table$Variabel[i], "=", outlier_table$Jumlah_Outlier[i], "outlier\n")
}
## Electricity.from.renewables..TWh. = 533 outlier
## Electricity.from.fossil.fuels..TWh. = 519 outlier
## Value_co2_emissions_kt_by_country = 509 outlier
## gdp_per_capita = 475 outlier
## Renewable.electricity.generating.capacity.per.capita = 469 outlier
## Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. = 316 outlier
## gdp_growth = 282 outlier
## Primary.energy.consumption.per.capita..kWh.person. = 237 outlier
## Density.n.P.Km2. = 231 outlier
## Access.to.electricity....of.population. = 0 outlier
## Access.to.clean.fuels.for.cooking = 0 outlier
## Renewable.energy.share.in.the.total.final.energy.consumption.... = 0 outlier
## Low.carbon.electricity....electricity. = 0 outlier

3.10 Handle Outlier

Membatasi nilai ekstrem agar tidak mempengaruhi analisis.

winsorize <- function(x){
  Q1 <- quantile(x, 0.25, na.rm = TRUE)
  Q3 <- quantile(x, 0.75, na.rm = TRUE)
  IQR <- Q3 - Q1
  lower <- Q1 - 1.5*IQR
  upper <- Q3 + 1.5*IQR
  x[x < lower] <- lower
  x[x > upper] <- upper
  return(x)
}


data_numeric_clean <- as.data.frame(lapply(data_numeric, winsorize))


head(data_numeric_clean)
##   Access.to.electricity....of.population. Access.to.clean.fuels.for.cooking
## 1                                1.613591                               6.2
## 2                                4.074574                               7.2
## 3                                9.409158                               8.2
## 4                               14.738506                               9.5
## 5                               20.064968                              10.9
## 6                               25.390894                              12.2
##   Renewable.electricity.generating.capacity.per.capita
## 1                                                 9.22
## 2                                                 8.86
## 3                                                 8.47
## 4                                                 8.09
## 5                                                 7.75
## 6                                                 7.51
##   Renewable.energy.share.in.the.total.final.energy.consumption....
## 1                                                            44.99
## 2                                                            45.60
## 3                                                            37.83
## 4                                                            36.66
## 5                                                            44.24
## 6                                                            33.88
##   Electricity.from.fossil.fuels..TWh. Electricity.from.renewables..TWh.
## 1                                0.16                              0.31
## 2                                0.09                              0.50
## 3                                0.13                              0.56
## 4                                0.31                              0.63
## 5                                0.33                              0.56
## 6                                0.34                              0.59
##   Low.carbon.electricity....electricity.
## 1                               65.95744
## 2                               84.74577
## 3                               81.15942
## 4                               67.02128
## 5                               62.92135
## 6                               63.44086
##   Primary.energy.consumption.per.capita..kWh.person.
## 1                                           302.5948
## 2                                           236.8919
## 3                                           210.8622
## 4                                           229.9682
## 5                                           204.2312
## 6                                           252.0691
##   Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP.
## 1                                                        1.64
## 2                                                        1.74
## 3                                                        1.40
## 4                                                        1.40
## 5                                                        1.20
## 6                                                        1.41
##   Value_co2_emissions_kt_by_country gdp_growth gdp_per_capita Density.n.P.Km2.
## 1                               760   3.559855      4578.6332               60
## 2                               730   3.559855      4578.6332               60
## 3                              1030   3.559855       179.4266               60
## 4                              1220   8.832278       190.6838               60
## 5                              1030   1.414118       211.3821               60
## 6                              1550  11.229715       242.0313               60

3.11 Cek outlier setelah winsorizing

count_outliers <- function(x){
  Q1 <- quantile(x, 0.25, na.rm = TRUE)
  Q3 <- quantile(x, 0.75, na.rm = TRUE)
  IQR <- Q3 - Q1
  sum(x < (Q1 - 1.5*IQR) | x > (Q3 + 1.5*IQR), na.rm = TRUE)
}


outlier_counts_after <- sapply(data_numeric_clean, count_outliers)


for(i in 1:length(outlier_counts_after)){
  cat(names(outlier_counts_after)[i], "=", outlier_counts_after[i], "outlier\n")
}
## Access.to.electricity....of.population. = 0 outlier
## Access.to.clean.fuels.for.cooking = 0 outlier
## Renewable.electricity.generating.capacity.per.capita = 0 outlier
## Renewable.energy.share.in.the.total.final.energy.consumption.... = 0 outlier
## Electricity.from.fossil.fuels..TWh. = 0 outlier
## Electricity.from.renewables..TWh. = 0 outlier
## Low.carbon.electricity....electricity. = 0 outlier
## Primary.energy.consumption.per.capita..kWh.person. = 0 outlier
## Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. = 0 outlier
## Value_co2_emissions_kt_by_country = 0 outlier
## gdp_growth = 0 outlier
## gdp_per_capita = 0 outlier
## Density.n.P.Km2. = 0 outlier

4. Standarisasi Data

Data dinormalisasi agar tiap variabel memiliki skala yang sama untuk PCA/FA.

data_scaled <- scale(data_numeric_clean)

5. Karakteristik Data setelah preprocessing

5.1 Jumlah Observasi dan Variabel

n_obs <- nrow(data_numeric_clean)
n_var <- ncol(data_numeric_clean)

n_obs
## [1] 3649
n_var
## [1] 13

5.2 Tampilan Data (Head)

kable(head(data_numeric_clean, 10),
      caption = "Tabel 1. Sampel Data Setelah Preprocessing")
Tabel 1. Sampel Data Setelah Preprocessing
Access.to.electricity….of.population. Access.to.clean.fuels.for.cooking Renewable.electricity.generating.capacity.per.capita Renewable.energy.share.in.the.total.final.energy.consumption…. Electricity.from.fossil.fuels..TWh. Electricity.from.renewables..TWh. Low.carbon.electricity….electricity. Primary.energy.consumption.per.capita..kWh.person. Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. Value_co2_emissions_kt_by_country gdp_growth gdp_per_capita Density.n.P.Km2.
1.613591 6.20 9.22 44.99 0.16 0.31 65.95744 302.5948 1.64 760 3.559855 4578.6332 60
4.074574 7.20 8.86 45.60 0.09 0.50 84.74577 236.8919 1.74 730 3.559855 4578.6332 60
9.409158 8.20 8.47 37.83 0.13 0.56 81.15942 210.8622 1.40 1030 3.559855 179.4266 60
14.738506 9.50 8.09 36.66 0.31 0.63 67.02128 229.9682 1.40 1220 8.832278 190.6838 60
20.064968 10.90 7.75 44.24 0.33 0.56 62.92135 204.2312 1.20 1030 1.414118 211.3821 60
25.390894 12.20 7.51 33.88 0.34 0.59 63.44086 252.0691 1.41 1550 11.229715 242.0313 60
30.718690 13.85 7.40 31.89 0.20 0.64 76.19048 304.4209 1.50 1760 5.357403 263.7336 60
36.051010 15.30 7.25 28.78 0.20 0.75 78.94737 354.2799 1.53 1770 11.381768 359.6932 60
42.400000 16.70 7.49 21.17 0.19 0.54 73.97260 607.8335 1.94 3560 3.924984 364.6635 60
46.740050 18.40 7.50 16.53 0.16 0.78 82.97872 975.0482 2.25 4880 11.381768 437.2687 60

5.3 Statistik Deskriptif

desc_stats <- describe(data_numeric_clean)

tabel_deskriptif <- data.frame(
  Variabel = rownames(desc_stats),
  Mean = round(desc_stats$mean, 3),
  SD = round(desc_stats$sd, 3),
  Median = round(apply(data_numeric_clean, 2, median, na.rm = TRUE), 3),
  Min = round(desc_stats$min, 3),
  Max = round(desc_stats$max, 3),
  row.names = NULL
)

kable(tabel_deskriptif, 
      caption = "Tabel Statistik Deskriptif Variabel", 
      align = 'c', 
      digits = 3)
Tabel Statistik Deskriptif Variabel
Variabel Mean SD Median Min Max
Access.to.electricity….of.population. 78.987 30.251 98.362 1.252 100.000
Access.to.clean.fuels.for.cooking 64.177 38.357 83.150 0.000 100.000
Renewable.electricity.generating.capacity.per.capita 50.782 52.472 32.910 0.000 156.415
Renewable.energy.share.in.the.total.final.energy.consumption…. 32.142 29.165 23.300 0.000 96.040
Electricity.from.fossil.fuels..TWh. 17.102 23.945 2.970 0.000 65.850
Electricity.from.renewables..TWh. 6.368 8.673 1.470 0.000 23.825
Low.carbon.electricity….electricity. 36.698 34.130 27.865 0.000 100.000
Primary.energy.consumption.per.capita..kWh.person. 22351.646 23614.715 13120.570 0.000 80056.844
Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. 4.890 2.284 4.300 0.110 9.870
Value_co2_emissions_kt_by_country 33944.478 44063.705 10500.000 10.000 124560.005
gdp_growth 3.499 3.537 3.560 -4.187 11.382
gdp_per_capita 9740.795 11178.232 4578.633 111.927 32784.472
Density.n.P.Km2. 129.109 128.535 83.000 2.000 456.500

5.4 Visualisasi Data

for(i in 1:ncol(data_numeric_clean)){
  boxplot(data_numeric_clean[, i],
          main = paste("Boxplot", colnames(data_numeric_clean)[i]),
          col = "lightblue",
          ylab = colnames(data_numeric_clean)[i],
          cex.main = 1,  
          cex.lab = 0.8,  
          cex.axis = 0.8) 
}

6. Uji Kelayakan PCA/FA

6.1 KMO Test

Menilai kecukupan sampel untuk PCA/FA.

KMO(data_scaled)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = data_scaled)
## Overall MSA =  0.73
## MSA for each item = 
##                          Access.to.electricity....of.population. 
##                                                             0.83 
##                                Access.to.clean.fuels.for.cooking 
##                                                             0.85 
##             Renewable.electricity.generating.capacity.per.capita 
##                                                             0.63 
## Renewable.energy.share.in.the.total.final.energy.consumption.... 
##                                                             0.83 
##                              Electricity.from.fossil.fuels..TWh. 
##                                                             0.70 
##                                Electricity.from.renewables..TWh. 
##                                                             0.73 
##                           Low.carbon.electricity....electricity. 
##                                                             0.56 
##               Primary.energy.consumption.per.capita..kWh.person. 
##                                                             0.69 
##      Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. 
##                                                             0.46 
##                                Value_co2_emissions_kt_by_country 
##                                                             0.74 
##                                                       gdp_growth 
##                                                             0.74 
##                                                   gdp_per_capita 
##                                                             0.68 
##                                                 Density.n.P.Km2. 
##                                                             0.53

6.2 Bartlett Test

Mengukur apakah korelasi antar variabel signifikan.

cortest.bartlett(data_scaled)
## R was not square, finding R from data
## $chisq
## [1] 32067.45
## 
## $p.value
## [1] 0
## 
## $df
## [1] 78

6.3 Hapus variabel MSA rendah (<0.5)

data_refined <- subset(data_scaled,
                       select = -c( Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP.))

6.4 Cek KMO setelah penghapusan

KMO(data_refined)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = data_refined)
## Overall MSA =  0.75
## MSA for each item = 
##                          Access.to.electricity....of.population. 
##                                                             0.82 
##                                Access.to.clean.fuels.for.cooking 
##                                                             0.85 
##             Renewable.electricity.generating.capacity.per.capita 
##                                                             0.60 
## Renewable.energy.share.in.the.total.final.energy.consumption.... 
##                                                             0.85 
##                              Electricity.from.fossil.fuels..TWh. 
##                                                             0.70 
##                                Electricity.from.renewables..TWh. 
##                                                             0.71 
##                           Low.carbon.electricity....electricity. 
##                                                             0.55 
##               Primary.energy.consumption.per.capita..kWh.person. 
##                                                             0.75 
##                                Value_co2_emissions_kt_by_country 
##                                                             0.73 
##                                                       gdp_growth 
##                                                             0.67 
##                                                   gdp_per_capita 
##                                                             0.73 
##                                                 Density.n.P.Km2. 
##                                                             0.45

6.3 Hapus variabel MSA rendah (<0.5)

data_refined2 <- subset(data_refined,
                        select = -c( Density.n.P.Km2.))

6.4 Cek KMO setelah penghapusan

KMO(data_refined2)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = data_refined2)
## Overall MSA =  0.76
## MSA for each item = 
##                          Access.to.electricity....of.population. 
##                                                             0.83 
##                                Access.to.clean.fuels.for.cooking 
##                                                             0.85 
##             Renewable.electricity.generating.capacity.per.capita 
##                                                             0.60 
## Renewable.energy.share.in.the.total.final.energy.consumption.... 
##                                                             0.84 
##                              Electricity.from.fossil.fuels..TWh. 
##                                                             0.70 
##                                Electricity.from.renewables..TWh. 
##                                                             0.71 
##                           Low.carbon.electricity....electricity. 
##                                                             0.52 
##               Primary.energy.consumption.per.capita..kWh.person. 
##                                                             0.77 
##                                Value_co2_emissions_kt_by_country 
##                                                             0.73 
##                                                       gdp_growth 
##                                                             0.65 
##                                                   gdp_per_capita 
##                                                             0.76

7. PCA

7.1 Hitung Eigenvalue

ev <- eigen(cor(data_refined2))
print(ev$values)
##  [1] 4.59920773 1.81191555 1.40553939 1.12602605 0.90426826 0.36024830
##  [7] 0.28017301 0.16797447 0.12766003 0.12097501 0.09601221

7.2 Tentukan Jumlah Komponen (Kaiser Rule)

sum(ev$values > 1)
## [1] 4

7.3 Jalankan PCA

pca_result <- prcomp(data_refined2)
summary(pca_result)
## Importance of components:
##                           PC1    PC2    PC3    PC4     PC5     PC6     PC7
## Standard deviation     2.1446 1.3461 1.1856 1.0611 0.95093 0.60021 0.52931
## Proportion of Variance 0.4181 0.1647 0.1278 0.1024 0.08221 0.03275 0.02547
## Cumulative Proportion  0.4181 0.5828 0.7106 0.8130 0.89518 0.92793 0.95340
##                            PC8     PC9   PC10    PC11
## Standard deviation     0.40985 0.35730 0.3478 0.30986
## Proportion of Variance 0.01527 0.01161 0.0110 0.00873
## Cumulative Proportion  0.96867 0.98027 0.9913 1.00000

7.4 Scree plot

plot(ev$values, 
     type = "b",
     main = "Scree Plot",
     ylab = "Eigenvalue",
     xlab = "Component Number")

abline(h = 1, col = "red", lty = 2)

7.6 Biplot PCA

biplot(pca_result, scale=0)

7.7 Loading PCA (koefisien komponen)

pca_loadings <- pca_result$rotation
head(pca_loadings)
##                                                                          PC1
## Access.to.electricity....of.population.                           0.38737074
## Access.to.clean.fuels.for.cooking                                 0.40721079
## Renewable.electricity.generating.capacity.per.capita              0.06361808
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.36186018
## Electricity.from.fossil.fuels..TWh.                               0.33467694
## Electricity.from.renewables..TWh.                                 0.23947689
##                                                                          PC2
## Access.to.electricity....of.population.                          -0.04338688
## Access.to.clean.fuels.for.cooking                                -0.06954139
## Renewable.electricity.generating.capacity.per.capita              0.44830885
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.29185180
## Electricity.from.fossil.fuels..TWh.                               0.15838370
## Electricity.from.renewables..TWh.                                 0.53847818
##                                                                         PC3
## Access.to.electricity....of.population.                           0.2760126
## Access.to.clean.fuels.for.cooking                                 0.2738385
## Renewable.electricity.generating.capacity.per.capita              0.3905276
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.1104015
## Electricity.from.fossil.fuels..TWh.                              -0.4882333
## Electricity.from.renewables..TWh.                                -0.1479972
##                                                                          PC4
## Access.to.electricity....of.population.                          -0.26435596
## Access.to.clean.fuels.for.cooking                                -0.12945435
## Renewable.electricity.generating.capacity.per.capita             -0.46963532
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.29642441
## Electricity.from.fossil.fuels..TWh.                              -0.08886986
## Electricity.from.renewables..TWh.                                 0.12729308
##                                                                           PC5
## Access.to.electricity....of.population.                          -0.006445551
## Access.to.clean.fuels.for.cooking                                -0.065599702
## Renewable.electricity.generating.capacity.per.capita              0.102307679
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.080296291
## Electricity.from.fossil.fuels..TWh.                               0.171258616
## Electricity.from.renewables..TWh.                                 0.028663753
##                                                                         PC6
## Access.to.electricity....of.population.                          -0.3172267
## Access.to.clean.fuels.for.cooking                                -0.1924430
## Renewable.electricity.generating.capacity.per.capita              0.6293242
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.2264497
## Electricity.from.fossil.fuels..TWh.                               0.1675911
## Electricity.from.renewables..TWh.                                -0.3166441
##                                                                          PC7
## Access.to.electricity....of.population.                          -0.10929019
## Access.to.clean.fuels.for.cooking                                 0.10695794
## Renewable.electricity.generating.capacity.per.capita             -0.04946749
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.12492291
## Electricity.from.fossil.fuels..TWh.                               0.15213472
## Electricity.from.renewables..TWh.                                -0.62492530
##                                                                          PC8
## Access.to.electricity....of.population.                          -0.46581245
## Access.to.clean.fuels.for.cooking                                -0.18593297
## Renewable.electricity.generating.capacity.per.capita              0.06970722
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.71994761
## Electricity.from.fossil.fuels..TWh.                              -0.01755566
## Electricity.from.renewables..TWh.                                 0.07488047
##                                                                          PC9
## Access.to.electricity....of.population.                           0.23862059
## Access.to.clean.fuels.for.cooking                                 0.14813038
## Renewable.electricity.generating.capacity.per.capita             -0.04816832
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.26642428
## Electricity.from.fossil.fuels..TWh.                               0.05607712
## Electricity.from.renewables..TWh.                                -0.32004850
##                                                                         PC10
## Access.to.electricity....of.population.                          -0.53105742
## Access.to.clean.fuels.for.cooking                                 0.77399127
## Renewable.electricity.generating.capacity.per.capita             -0.02758679
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.14479650
## Electricity.from.fossil.fuels..TWh.                               0.17289135
## Electricity.from.renewables..TWh.                                 0.06208677
##                                                                         PC11
## Access.to.electricity....of.population.                          -0.18284636
## Access.to.clean.fuels.for.cooking                                 0.17100759
## Renewable.electricity.generating.capacity.per.capita              0.07070772
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.01478733
## Electricity.from.fossil.fuels..TWh.                              -0.70903510
## Electricity.from.renewables..TWh.                                 0.10524141

7.8 Split Sample Validation

set.seed(123)
index <- sample(1:nrow(data_refined2), nrow(data_refined2)/2)

data_half1 <- data_refined2[index, ]
data_half2 <- data_refined2[-index, ]

prcomp(data_half1)
## Standard deviations (1, .., p=11):
##  [1] 2.1566661 1.3484568 1.1748694 1.0401165 0.9446660 0.6058358 0.5310176
##  [8] 0.4065966 0.3645758 0.3499810 0.3166225
## 
## Rotation (n x k) = (11 x 11):
##                                                                          PC1
## Access.to.electricity....of.population.                          -0.38055051
## Access.to.clean.fuels.for.cooking                                -0.40222333
## Renewable.electricity.generating.capacity.per.capita             -0.05767614
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.36047519
## Electricity.from.fossil.fuels..TWh.                              -0.33612388
## Electricity.from.renewables..TWh.                                -0.23303952
## Low.carbon.electricity....electricity.                            0.09517157
## Primary.energy.consumption.per.capita..kWh.person.               -0.37634589
## Value_co2_emissions_kt_by_country                                -0.32544812
## gdp_growth                                                        0.09961994
## gdp_per_capita                                                   -0.35539788
##                                                                           PC2
## Access.to.electricity....of.population.                          -0.028953102
## Access.to.clean.fuels.for.cooking                                -0.067681347
## Renewable.electricity.generating.capacity.per.capita              0.456007720
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.284565479
## Electricity.from.fossil.fuels..TWh.                               0.155291719
## Electricity.from.renewables..TWh.                                 0.543076758
## Low.carbon.electricity....electricity.                            0.575282205
## Primary.energy.consumption.per.capita..kWh.person.               -0.137789373
## Value_co2_emissions_kt_by_country                                 0.185020534
## gdp_growth                                                        0.003082471
## gdp_per_capita                                                   -0.049344618
##                                                                          PC3
## Access.to.electricity....of.population.                          -0.30268295
## Access.to.clean.fuels.for.cooking                                -0.29284983
## Renewable.electricity.generating.capacity.per.capita             -0.41984207
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.15919543
## Electricity.from.fossil.fuels..TWh.                               0.47697051
## Electricity.from.renewables..TWh.                                 0.15778935
## Low.carbon.electricity....electricity.                           -0.25090096
## Primary.energy.consumption.per.capita..kWh.person.               -0.05279836
## Value_co2_emissions_kt_by_country                                 0.49168997
## gdp_growth                                                        0.23877973
## gdp_per_capita                                                   -0.06402635
##                                                                          PC4
## Access.to.electricity....of.population.                           0.24563327
## Access.to.clean.fuels.for.cooking                                 0.11052102
## Renewable.electricity.generating.capacity.per.capita              0.41784636
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.28628179
## Electricity.from.fossil.fuels..TWh.                               0.15234917
## Electricity.from.renewables..TWh.                                -0.09085917
## Low.carbon.electricity....electricity.                           -0.28342634
## Primary.energy.consumption.per.capita..kWh.person.               -0.36342806
## Value_co2_emissions_kt_by_country                                 0.09928730
## gdp_growth                                                        0.41224889
## gdp_per_capita                                                   -0.49720553
##                                                                           PC5
## Access.to.electricity....of.population.                          -0.007041847
## Access.to.clean.fuels.for.cooking                                -0.074370044
## Renewable.electricity.generating.capacity.per.capita              0.069524703
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.056520370
## Electricity.from.fossil.fuels..TWh.                               0.175458700
## Electricity.from.renewables..TWh.                                 0.042054336
## Low.carbon.electricity....electricity.                           -0.238804667
## Primary.energy.consumption.per.capita..kWh.person.               -0.316609873
## Value_co2_emissions_kt_by_country                                 0.080440954
## gdp_growth                                                       -0.862592137
## gdp_per_capita                                                   -0.214549593
##                                                                          PC6
## Access.to.electricity....of.population.                           0.30675544
## Access.to.clean.fuels.for.cooking                                 0.21052095
## Renewable.electricity.generating.capacity.per.capita             -0.64641109
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.20350911
## Electricity.from.fossil.fuels..TWh.                              -0.17303112
## Electricity.from.renewables..TWh.                                 0.31435217
## Low.carbon.electricity....electricity.                            0.31556270
## Primary.energy.consumption.per.capita..kWh.person.               -0.28223083
## Value_co2_emissions_kt_by_country                                -0.01952281
## gdp_growth                                                        0.01130239
## gdp_per_capita                                                   -0.30629850
##                                                                          PC7
## Access.to.electricity....of.population.                          -0.10001790
## Access.to.clean.fuels.for.cooking                                 0.09349039
## Renewable.electricity.generating.capacity.per.capita             -0.02532537
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.12137570
## Electricity.from.fossil.fuels..TWh.                               0.15232803
## Electricity.from.renewables..TWh.                                -0.62785025
## Low.carbon.electricity....electricity.                            0.53630574
## Primary.energy.consumption.per.capita..kWh.person.                0.17842796
## Value_co2_emissions_kt_by_country                                 0.37727011
## gdp_growth                                                       -0.11201360
## gdp_per_capita                                                   -0.27229138
##                                                                          PC8
## Access.to.electricity....of.population.                          -0.48706824
## Access.to.clean.fuels.for.cooking                                -0.11269682
## Renewable.electricity.generating.capacity.per.capita              0.04791123
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.69825134
## Electricity.from.fossil.fuels..TWh.                               0.02201760
## Electricity.from.renewables..TWh.                                 0.06320726
## Low.carbon.electricity....electricity.                            0.17671980
## Primary.energy.consumption.per.capita..kWh.person.               -0.32325725
## Value_co2_emissions_kt_by_country                                -0.06703863
## gdp_growth                                                        0.05075278
## gdp_per_capita                                                    0.33606315
##                                                                          PC9
## Access.to.electricity....of.population.                           0.28699883
## Access.to.clean.fuels.for.cooking                                 0.12853955
## Renewable.electricity.generating.capacity.per.capita             -0.04799134
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.29201918
## Electricity.from.fossil.fuels..TWh.                               0.05491605
## Electricity.from.renewables..TWh.                                -0.32756415
## Low.carbon.electricity....electricity.                            0.05846982
## Primary.energy.consumption.per.capita..kWh.person.               -0.61629875
## Value_co2_emissions_kt_by_country                                 0.17738664
## gdp_growth                                                        0.05237556
## gdp_per_capita                                                    0.53456968
##                                                                         PC10
## Access.to.electricity....of.population.                          -0.49379124
## Access.to.clean.fuels.for.cooking                                 0.79103339
## Renewable.electricity.generating.capacity.per.capita             -0.02603383
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.22272541
## Electricity.from.fossil.fuels..TWh.                               0.16885145
## Electricity.from.renewables..TWh.                                 0.03684986
## Low.carbon.electricity....electricity.                           -0.07617220
## Primary.energy.consumption.per.capita..kWh.person.               -0.09057330
## Value_co2_emissions_kt_by_country                                -0.16974003
## gdp_growth                                                        0.01495129
## gdp_per_capita                                                   -0.08510196
##                                                                           PC11
## Access.to.electricity....of.population.                           0.1865601826
## Access.to.clean.fuels.for.cooking                                -0.1487026184
## Renewable.electricity.generating.capacity.per.capita             -0.0962741113
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.0005973434
## Electricity.from.fossil.fuels..TWh.                               0.7044525325
## Electricity.from.renewables..TWh.                                -0.1008672851
## Low.carbon.electricity....electricity.                            0.1789659845
## Primary.energy.consumption.per.capita..kWh.person.                0.0159600140
## Value_co2_emissions_kt_by_country                                -0.6279151495
## gdp_growth                                                        0.0286162731
## gdp_per_capita                                                   -0.0025133204
prcomp(data_half2)
## Standard deviations (1, .., p=11):
##  [1] 2.1332246 1.3441329 1.1992419 1.0794830 0.9569964 0.5937709 0.5260289
##  [8] 0.4126890 0.3494165 0.3440745 0.3016099
## 
## Rotation (n x k) = (11 x 11):
##                                                                          PC1
## Access.to.electricity....of.population.                           0.39417584
## Access.to.clean.fuels.for.cooking                                 0.41214844
## Renewable.electricity.generating.capacity.per.capita              0.07006988
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.36314373
## Electricity.from.fossil.fuels..TWh.                               0.33312970
## Electricity.from.renewables..TWh.                                 0.24607527
## Low.carbon.electricity....electricity.                           -0.09107558
## Primary.energy.consumption.per.capita..kWh.person.                0.35243601
## Value_co2_emissions_kt_by_country                                 0.32698797
## gdp_growth                                                       -0.09792645
## gdp_per_capita                                                    0.34268186
##                                                                          PC2
## Access.to.electricity....of.population.                          -0.05887670
## Access.to.clean.fuels.for.cooking                                -0.07267003
## Renewable.electricity.generating.capacity.per.capita              0.43893582
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.29903827
## Electricity.from.fossil.fuels..TWh.                               0.16406179
## Electricity.from.renewables..TWh.                                 0.53397298
## Low.carbon.electricity....electricity.                            0.57295924
## Primary.energy.consumption.per.capita..kWh.person.               -0.13745631
## Value_co2_emissions_kt_by_country                                 0.20968026
## gdp_growth                                                        0.05870978
## gdp_per_capita                                                   -0.05031380
##                                                                          PC3
## Access.to.electricity....of.population.                           0.24573343
## Access.to.clean.fuels.for.cooking                                 0.25298207
## Renewable.electricity.generating.capacity.per.capita              0.35324951
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.05718224
## Electricity.from.fossil.fuels..TWh.                              -0.49151349
## Electricity.from.renewables..TWh.                                -0.12891998
## Low.carbon.electricity....electricity.                            0.33885316
## Primary.energy.consumption.per.capita..kWh.person.                0.15310405
## Value_co2_emissions_kt_by_country                                -0.49478848
## gdp_growth                                                       -0.27366288
## gdp_per_capita                                                    0.17715792
##                                                                          PC4
## Access.to.electricity....of.population.                          -0.28192209
## Access.to.clean.fuels.for.cooking                                -0.14706079
## Renewable.electricity.generating.capacity.per.capita             -0.51815438
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.29904074
## Electricity.from.fossil.fuels..TWh.                              -0.02278863
## Electricity.from.renewables..TWh.                                 0.16339005
## Low.carbon.electricity....electricity.                            0.20965799
## Primary.energy.consumption.per.capita..kWh.person.                0.32053768
## Value_co2_emissions_kt_by_country                                -0.01142679
## gdp_growth                                                       -0.40564915
## gdp_per_capita                                                    0.44987267
##                                                                           PC5
## Access.to.electricity....of.population.                          -0.006782817
## Access.to.clean.fuels.for.cooking                                -0.057338506
## Renewable.electricity.generating.capacity.per.capita              0.138603071
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.101086177
## Electricity.from.fossil.fuels..TWh.                               0.164574774
## Electricity.from.renewables..TWh.                                 0.013048191
## Low.carbon.electricity....electricity.                           -0.164596423
## Primary.energy.consumption.per.capita..kWh.person.               -0.337643930
## Value_co2_emissions_kt_by_country                                 0.079521090
## gdp_growth                                                       -0.855882271
## gdp_per_capita                                                   -0.245007100
##                                                                          PC6
## Access.to.electricity....of.population.                          -0.32647988
## Access.to.clean.fuels.for.cooking                                -0.17121597
## Renewable.electricity.generating.capacity.per.capita              0.60993869
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.25196080
## Electricity.from.fossil.fuels..TWh.                               0.16180195
## Electricity.from.renewables..TWh.                                -0.31163311
## Low.carbon.electricity....electricity.                           -0.33099614
## Primary.energy.consumption.per.capita..kWh.person.                0.31710418
## Value_co2_emissions_kt_by_country                                 0.07235279
## gdp_growth                                                       -0.03068595
## gdp_per_capita                                                    0.29833104
##                                                                          PC7
## Access.to.electricity....of.population.                          -0.11742398
## Access.to.clean.fuels.for.cooking                                 0.12016809
## Renewable.electricity.generating.capacity.per.capita             -0.06804686
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.12010013
## Electricity.from.fossil.fuels..TWh.                               0.15561227
## Electricity.from.renewables..TWh.                                -0.62547268
## Low.carbon.electricity....electricity.                            0.55412375
## Primary.energy.consumption.per.capita..kWh.person.                0.19044872
## Value_co2_emissions_kt_by_country                                 0.36438179
## gdp_growth                                                       -0.06292869
## gdp_per_capita                                                   -0.23922294
##                                                                          PC8
## Access.to.electricity....of.population.                           0.44791898
## Access.to.clean.fuels.for.cooking                                 0.24225112
## Renewable.electricity.generating.capacity.per.capita             -0.09008141
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.72806613
## Electricity.from.fossil.fuels..TWh.                               0.04887394
## Electricity.from.renewables..TWh.                                -0.07455414
## Low.carbon.electricity....electricity.                           -0.16379875
## Primary.energy.consumption.per.capita..kWh.person.                0.21901102
## Value_co2_emissions_kt_by_country                                 0.04052949
## gdp_growth                                                       -0.06672406
## gdp_per_capita                                                   -0.33712083
##                                                                          PC9
## Access.to.electricity....of.population.                           0.20577338
## Access.to.clean.fuels.for.cooking                                 0.15483117
## Renewable.electricity.generating.capacity.per.capita             -0.04777312
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.24570755
## Electricity.from.fossil.fuels..TWh.                               0.05498784
## Electricity.from.renewables..TWh.                                -0.31377571
## Low.carbon.electricity....electricity.                            0.05708082
## Primary.energy.consumption.per.capita..kWh.person.               -0.64727686
## Value_co2_emissions_kt_by_country                                 0.15726722
## gdp_growth                                                        0.05416583
## gdp_per_capita                                                    0.56538379
##                                                                         PC10
## Access.to.electricity....of.population.                           0.55360531
## Access.to.clean.fuels.for.cooking                                -0.75714803
## Renewable.electricity.generating.capacity.per.capita              0.02836237
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.08240530
## Electricity.from.fossil.fuels..TWh.                              -0.17089744
## Electricity.from.renewables..TWh.                                -0.08279453
## Low.carbon.electricity....electricity.                            0.06103569
## Primary.energy.consumption.per.capita..kWh.person.                0.11340806
## Value_co2_emissions_kt_by_country                                 0.23043127
## gdp_growth                                                       -0.03064285
## gdp_per_capita                                                    0.07725155
##                                                                          PC11
## Access.to.electricity....of.population.                          -0.177249874
## Access.to.clean.fuels.for.cooking                                 0.190398295
## Renewable.electricity.generating.capacity.per.capita              0.045701579
## Renewable.energy.share.in.the.total.final.energy.consumption....  0.025253615
## Electricity.from.fossil.fuels..TWh.                              -0.712674777
## Electricity.from.renewables..TWh.                                 0.107857229
## Low.carbon.electricity....electricity.                           -0.164705342
## Primary.energy.consumption.per.capita..kWh.person.               -0.009253537
## Value_co2_emissions_kt_by_country                                 0.616733360
## gdp_growth                                                       -0.041950367
## gdp_per_capita                                                   -0.027068873

8. Factor Analysis (FA)

8.1 Tentukan jumlah faktor optimal (Parallel Analysis)

fa.parallel(data_refined2, fa="fa")

## Parallel analysis suggests that the number of factors =  4  and the number of components =  NA

8.2 Ekstraksi Faktor dengan Rotasi Varimax

Misal parallel analysis merekomendasikan 4 faktor.

fa_result <- fa(data_refined2,
                nfactors = 4,
                rotate = "varimax",
                fm = "pa")   

8.3 Lihat loading faktor

print(fa_result$loadings, cutoff=0.4)
## 
## Loadings:
##                                                                  PA1    PA3   
## Access.to.electricity....of.population.                           0.821       
## Access.to.clean.fuels.for.cooking                                 0.763       
## Renewable.electricity.generating.capacity.per.capita                          
## Renewable.energy.share.in.the.total.final.energy.consumption.... -0.803       
## Electricity.from.fossil.fuels..TWh.                                      0.925
## Electricity.from.renewables..TWh.                                        0.615
## Low.carbon.electricity....electricity.                                        
## Primary.energy.consumption.per.capita..kWh.person.                            
## Value_co2_emissions_kt_by_country                                        0.896
## gdp_growth                                                                    
## gdp_per_capita                                                                
##                                                                  PA4    PA2   
## Access.to.electricity....of.population.                                       
## Access.to.clean.fuels.for.cooking                                 0.504       
## Renewable.electricity.generating.capacity.per.capita                     0.610
## Renewable.energy.share.in.the.total.final.energy.consumption....              
## Electricity.from.fossil.fuels..TWh.                                           
## Electricity.from.renewables..TWh.                                        0.523
## Low.carbon.electricity....electricity.                                   0.778
## Primary.energy.consumption.per.capita..kWh.person.                0.799       
## Value_co2_emissions_kt_by_country                                             
## gdp_growth                                                                    
## gdp_per_capita                                                    0.908       
## 
##                  PA1   PA3   PA4   PA2
## SS loadings    2.300 2.279 2.082 1.368
## Proportion Var 0.209 0.207 0.189 0.124
## Cumulative Var 0.209 0.416 0.606 0.730

8.4 Menampilkan Communality (h2)

communalities <- fa_result$communality
kable(data.frame(Communality = round(communalities, 3)), caption = "Tabel Nilai Communality (h2)")
Tabel Nilai Communality (h2)
Communality
Access.to.electricity….of.population. 0.867
Access.to.clean.fuels.for.cooking 0.889
Renewable.electricity.generating.capacity.per.capita 0.482
Renewable.energy.share.in.the.total.final.energy.consumption…. 0.831
Electricity.from.fossil.fuels..TWh. 0.930
Electricity.from.renewables..TWh. 0.709
Low.carbon.electricity….electricity. 0.717
Primary.energy.consumption.per.capita..kWh.person. 0.790
Value_co2_emissions_kt_by_country 0.860
gdp_growth 0.049
gdp_per_capita 0.905
fa_uniqueness <- fa_result$uniquenesses

8.5 Analisis Cross-Loading (Rasio)

loadings_matrix <- fa_result$loadings[,]
cross_loading <- apply(loadings_matrix, 1, function(x) {
  sorted <- sort(abs(x), decreasing = TRUE)
  if(length(sorted) > 1) {
    ratio <- sorted[1] / sorted[2]
  } else {
    ratio <- NA
  }
  return(ratio)
})
cross_loading
##                          Access.to.electricity....of.population. 
##                                                         2.283420 
##                                Access.to.clean.fuels.for.cooking 
##                                                         1.512528 
##             Renewable.electricity.generating.capacity.per.capita 
##                                                         2.035374 
## Renewable.energy.share.in.the.total.final.energy.consumption.... 
##                                                         2.879764 
##                              Electricity.from.fossil.fuels..TWh. 
##                                                         4.014862 
##                                Electricity.from.renewables..TWh. 
##                                                         1.175362 
##                           Low.carbon.electricity....electricity. 
##                                                         2.469767 
##               Primary.energy.consumption.per.capita..kWh.person. 
##                                                         2.699945 
##                                Value_co2_emissions_kt_by_country 
##                                                         4.993234 
##                                                       gdp_growth 
##                                                         2.050058 
##                                                   gdp_per_capita 
##                                                         3.912442

8.6 Total Variance Explained (Vaccounted)

fa_variance <- fa_result$Vaccounted
print(fa_variance)
##                             PA1       PA3       PA4       PA2
## SS loadings           2.2996271 2.2792031 2.0821590 1.3682236
## Proportion Var        0.2090570 0.2072003 0.1892872 0.1243840
## Cumulative Var        0.2090570 0.4162573 0.6055445 0.7299284
## Proportion Explained  0.2864075 0.2838638 0.2593229 0.1704057
## Cumulative Proportion 0.2864075 0.5702714 0.8295943 1.0000000

8.7 Visualisasi FA

corrplot(fa_result$loadings[,], is.corr = FALSE, tl.cex = 0.7, main = "Factor Loadings Heatmap")