dimension_reduction

Dimension reduction project

The aim of this project is to perform dimension reduction on the data set [link] that contains information on the statistical performance indicators in every country on the planet. The number of variables is 79, but some of them are categorical, meaning it is impossible to perform dimension reduction

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(corrplot)
Warning: package 'corrplot' was built under R version 4.3.2
corrplot 0.92 loaded
library(MASS)

Attaching package: 'MASS'
The following object is masked from 'package:dplyr':

    select
library(factoextra)
Warning: package 'factoextra' was built under R version 4.3.2
Loading required package: ggplot2
Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(ggplot2)

Data manipulation and overview

Reading data

spi_index_labelled <- read.csv("C:/Users/mateu/Downloads/spi_index_labelled.csv")
head(spi_index_labelled)
   country iso3c date               SPI.INDEX.PIL1
1                  NA Pillar 1  - Data Use - Score
2   Norway   NOR 2019                          100
3    Italy   ITA 2019                          100
4  Austria   AUT 2019                          100
5   Poland   POL 2019                          100
6 Slovenia   SVN 2019                          100
                    SPI.INDEX.PIL2                   SPI.INDEX.PIL3
1 Pillar 2 - Data Services - Score Pillar 3 - Data Products - Score
2                 92.2333333333333                         77.56875
3                 91.8666666666666                          75.2875
4                             91.3                            74.55
5                             95.1                          70.5375
6                 96.9333333333333                         76.28125
                   SPI.INDEX.PIL4                         SPI.INDEX.PIL5
1 Pillar 4 - Data Sources - Score Pillar 5 - Data Infrastructure - Score
2                80.6666666666667                                    100
3                          81.825                                    100
4                           79.75                                    100
5                79.7166666666667                                    100
6                71.4416666666667                                    100
          SPI.INDEX                                       SPI.DIM1.5.INDEX
1 SPI Overall Score Dimension 1.5: Data use by international organizations
2          90.09375                                                      1
3  89.7958333333333                                                      1
4             89.12                                                      1
5  89.0708333333333                                                      1
6          88.93125                                                      1
              SPI.DIM2.1.INDEX             SPI.DIM2.2.INDEX
1 Dimension 2.1: Data Releases Dimension 2.2: Online access
2                            1                        0.767
3                            1                        0.756
4                            1                        0.739
5                            1                        0.853
6                            1                        0.908
              SPI.DIM2.4.INDEX                 SPI.DIM3.1.INDEX
1 Dimension 2.4: Data services Dimension 3.1: Social Statistics
2                            1                0.757833333333333
3                            1                0.711166666666667
4                            1                0.721666666666667
5                            1                0.678666666666667
6                            1                           0.7335
                    SPI.DIM3.2.INDEX                        SPI.DIM3.3.INDEX
1 Dimension 3.2: Economic Statistics Dimension 3.3: Environmental Statistics
2                  0.782166666666667                                       1
3                  0.787166666666667                                       1
4                  0.750666666666667                                       1
5                             0.7515                                    0.75
6                  0.791333333333333                                       1
                         SPI.DIM3.4.INDEX
1 Dimension 3.4: Institutional Statistics
2                                  0.5855
3                                   0.528
4                                   0.547
5                                  0.6025
6                                   0.528
                                 SPI.DIM4.1.CEN.INDEX
1 Dimension 4.1: Censuses and Surveys - Censuses only
2                                   0.666666666666667
3                                                   1
4                                                   1
5                                   0.666666666666667
6                                   0.666666666666667
                                SPI.DIM4.1.SVY.INDEX
1 Dimension 4.1: Censuses and Surveys - Surveys only
2                                                  1
3                                              0.934
4                                              0.866
5                                              0.934
6                                              0.934
                    SPI.DIM4.2.INDEX               SPI.DIM4.3.INDEX
1 Dimension 4.2: Administrative Data Dimension 4.3: Geospatial Data
2                                  1                           0.56
3                                  1                          0.339
4                                  1                          0.324
5                                  1                          0.588
6                                  1                          0.257
                           SPI.DIM5.1.INDEX
1 Dimension 5.1: Legislation and governance
2                                         1
3                                         1
4                                         1
5                                         1
6                                         1
                      SPI.DIM5.2.INDEX       SPI.DIM5.5.INDEX
1 Dimension 5.2: Standards and Methods Dimension 5.5: Finance
2                                    1                      1
3                                    1                      1
4                                    1                      1
5                                    1                      1
6                                    1                      1
                                                                                                                SPI.D1.5.POV
1 Dimension 1.5: Data use by international organisations - Availability of Comparable Poverty headcount ratio at $1.90 a day
2                                                                                                                          1
3                                                                                                                          1
4                                                                                                                          1
5                                                                                                                          1
6                                                                                                                          1
                                                                                                                                                            SPI.D1.5.CHLD.MORT
1 Dimension 1.5: Data use by international organisations - Availability of Mortality rate, under-5 (per 1,000 live births) data meeting quality standards according to UN IGME
2                                                                                                                                                                            1
3                                                                                                                                                                            1
4                                                                                                                                                                            1
5                                                                                                                                                                            1
6                                                                                                                                                                            1
                                                                                     SPI.D1.5.DT.TDS.DPPF.XP.ZS
1 Dimension 1.5: Data use by international organisations - Quality of Debt service data according to World Bank
2                                                                                                             1
3                                                                                                             1
4                                                                                                             1
5                                                                                                             1
6                                                                                                             1
                                                                SPI.D1.5.SAFE.MAN.WATER
1 Dimension1.5: Data use by international organisations - Safely Managed Drinking Water
2                                                                                     1
3                                                                                     1
4                                                                                     1
5                                                                                     1
6                                                                                     1
                                                                                                SPI.D1.5.LFP
1 Dimension 1.5: Data use by international organisations - Labor force participation rate by sex and age (%)
2                                                                                                          1
3                                                                                                          1
4                                                                                                          1
5                                                                                                          1
6                                                                                                          1
                                            SPI.D2.1.GDDS
1 Dimension 2.1: Data releases - SDDS/e-GDDS subscription
2                                                       1
3                                                       1
4                                                       1
5                                                       1
6                                                       1
                                 SPI.D2.2.Machine.readable
1 Dimension 2.2: Online access - Machine Readability Score
2                                                        1
3                                                    0.771
4                                                    0.907
5                                                        1
6                                                    0.963
                                     SPI.D2.2.Non.proprietary
1 Dimension 2.2: Online access - Non-Proprietary format Score
2                                                           1
3                                                       0.786
4                                                       0.963
5                                                           1
6                                                           1
                              SPI.D2.2.Download.options
1 Dimension 2.2: Online access - Download Options Score
2                                                 0.623
3                                                  0.69
4                                                 0.686
5                                                  0.68
6                                                 0.784
                              SPI.D2.2.Metadata.available
1 Dimension 2.2: Online access - Metadata Available Score
2                                                    0.67
3                                                   0.762
4                                                   0.703
5                                                   0.679
6                                                   0.897
                              SPI.D2.2.Terms.of.use
1 Dimension 2.2: Online access - Terms of Use Score
2                                             0.542
3                                             0.771
4                                             0.434
5                                             0.905
6                                             0.897
                                    SPI.D2.2.Openness.subscore
1 Dimension 2.2: Online access - ODIN Open Data Openness score
2                                                        0.767
3                                                        0.756
4                                                        0.739
5                                                        0.853
6                                                        0.908
                                        SPI.D2.4.NADA
1 Dimension 2.4: Data access services - NADA metadata
2                                                   1
3                                                   1
4                                                   1
5                                                   1
6                                                   1
                                    SPI.D3.1.POV
1 Dimension 3.1: SDG Goal 1 - GOAL 1: No Poverty
2                                              1
3                                          0.857
4                                              1
5                                          0.714
6                                              1
                                    SPI.D3.2.HNGR
1 Dimension 3.2: SDG Goal 2 - GOAL 2: Zero Hunger
2                                           0.889
3                                             0.8
4                                             0.6
5                                             0.7
6                                             0.7
                                                   SPI.D3.3.HLTH
1 Dimension 3.3: SDG Goal 3 - GOAL 3: Good Health and Well-being
2                                                          0.905
3                                                          0.857
4                                                            0.9
5                                                          0.905
6                                                          0.857
                                          SPI.D3.4.EDUC
1 Dimension 3.4: SDG Goal 4 - GOAL 4: Quality Education
2                                                 0.545
3                                                 0.545
4                                                 0.455
5                                                 0.545
6                                                 0.636
                                        SPI.D3.5.GEND
1 Dimension 3.5: SDG Goal 5 - GOAL 5: Gender Equality
2                                               0.375
3                                               0.375
4                                               0.375
5                                               0.375
6                                               0.375
                                                   SPI.D3.6.WTRS
1 Dimension 3.6: SDG Goal 6 - GOAL 6: Clean Water and Sanitation
2                                                          0.833
3                                                          0.833
4                                                              1
5                                                          0.833
6                                                          0.833
                                                    SPI.D3.7.ENRG
1 Dimension 3.7: SDG Goal 7 - GOAL 7: Affordable and Clean Energy
2                                                             0.8
3                                                             0.8
4                                                             0.8
5                                                             0.8
6                                                             0.8
                                                        SPI.D3.8.WORK
1 Dimension 3.8: SDG Goal 8 - GOAL 8: Decent Work and Economic Growth
2                                                               0.643
3                                                               0.769
4                                                               0.692
5                                                               0.692
6                                                               0.769
                                                                SPI.D3.9.INDY
1 Dimension 3.9: SDG Goal 9 - GOAL 9: Industry, Innovation and Infrastructure
2                                                                           1
3                                                                           1
4                                                                           1
5                                                                           1
6                                                                           1
                                             SPI.D3.10.NEQL
1 Dimension 3.10: SDG Goal 10 - GOAL 10: Reduced Inequality
2                                                       0.5
3                                                     0.571
4                                                     0.429
5                                                     0.667
6                                                     0.429
                                                             SPI.D3.11.CITY
1 Dimension 3.11: SDG Goal 11 - GOAL 11: Sustainable Cities and Communities
2                                                                         1
3                                                                     0.833
4                                                                     0.833
5                                                                       0.6
6                                                                         1
                                                                 SPI.D3.12.CNSP
1 Dimension 3.12: SDG Goal 12 - GOAL 12: Responsible Consumption and Production
2                                                                          0.75
3                                                                          0.75
4                                                                          0.75
5                                                                          0.75
6                                                                          0.75
                                       SPI.D3.15.LAND
1 Dimension 3.15: SDG Goal 15 - GOAL 15: Life on Land
2                                                   1
3                                                   1
4                                                   1
5                                                   1
6                                                   1
                                                                SPI.D3.16.INST
1 Dimension 3.16: SDG Goal 16 - GOAL 16: Peace and Justice Strong Institutions
2                                                                        0.556
3                                                                        0.556
4                                                                        0.556
5                                                                        0.667
6                                                                        0.556
                                                           SPI.D3.17.PTNS
1 Dimension 3.17: SDG Goal 17 - GOAL 17: Partnerships to achieve the Goal
2                                                                   0.615
3                                                                     0.5
4                                                                   0.538
5                                                                   0.538
6                                                                     0.5
                                         SPI.D3.13.CLMT
1 Dimension 3.13: SDG Goal 13 - GOAL 13: Climate Action
2                                                     1
3                                                     1
4                                                     1
5                                                   0.5
6                                                     1
                                                    SPI.D4.1.1.POPU
1 Dimension 4.1: censuses and surveys - Population & Housing census
2                                                                 1
3                                                                 1
4                                                                 1
5                                                                 1
6                                                                 1
                                           SPI.D4.1.2.AGRI
1 Dimension 4.1: censuses and surveys - Agriculture census
2                                                        1
3                                                        1
4                                                        1
5                                                        1
6                                                        1
                                                      SPI.D4.1.3.BIZZ
1 Dimension 4.1: censuses and surveys - Business/establishment census
2                                                                   0
3                                                                   1
4                                                                   1
5                                                                   0
6                                                                   0
                                                        SPI.D4.1.4.HOUS
1 Dimension 4.1: censuses and surveys - Household Survey on income, etc
2                                                                     1
3                                                                     1
4                                                                     1
5                                                                     1
6                                                                     1
                                          SPI.D4.1.5.AGSVY
1 Dimension 4.1: censuses and surveys - Agriculture survey
2                                                        1
3                                                        1
4                                                        1
5                                                        1
6                                                        1
                                           SPI.D4.1.6.LABR
1 Dimension 4.1: censuses and surveys - Labor Force Survey
2                                                        1
3                                                        1
4                                                        1
5                                                        1
6                                                        1
                                                  SPI.D4.1.7.HLTH
1 Dimension 4.1: censuses and surveys - Health/Demographic survey
2                                                               1
3                                                            0.67
4                                                            0.33
5                                                            0.67
6                                                            0.67
                                                     SPI.D4.1.8.BZSVY
1 Dimension 4.1: censuses and surveys - Business/establishment survey
2                                                                   1
3                                                                   1
4                                                                   1
5                                                                   1
6                                                                   1
                                  SPI.D4.2.3.CRVS
1 Dimension 4.2: administrative data - CRVS (WDI)
2                                               1
3                                               1
4                                               1
5                                               1
6                                               1
                                                 SPI.D4.3.GEO.first.admin.level
1 Dimension 4.3: geospatial data - Geospatial data available at 1st Admin Level
2                                                                          0.56
3                                                                         0.339
4                                                                         0.324
5                                                                         0.588
6                                                                         0.257
                                                                                                 SPI.D5.1.DILG
1 Dimension 5.1: Legislation and governance - Legislation Indicator based on PARIS21 indicators on SDG 17.18.2
2                                                                                                            1
3                                                                                                            1
4                                                                                                            1
5                                                                                                            1
6                                                                                                            1
                                                SPI.D5.2.1.SNAU
1 Dimension 5.2: standards - System of national accounts in use
2                                                             1
3                                                             1
4                                                             1
5                                                             1
6                                                             1
                                         SPI.D5.2.2.NABY
1 Dimension 5.2: standards - National Accounts base year
2                                                      1
3                                                      1
4                                                      1
5                                                      1
6                                                      1
                                                 SPI.D5.2.3.CNIN
1 Dimension 5.2: standards - Classification of national industry
2                                                              1
3                                                              1
4                                                              1
5                                                              1
6                                                              1
                          SPI.D5.2.4.CPIBY
1 Dimension 5.2: standards - CPI base year
2                                        1
3                                        1
4                                        1
5                                        1
6                                        1
                                                     SPI.D5.2.5.HOUS
1 Dimension 5.2: standards - Classification of household consumption
2                                                                  1
3                                                                  1
4                                                                  1
5                                                                  1
6                                                                  1
                                                    SPI.D5.2.6.EMPL
1 Dimension 5.2: standards - Classification of status of employment
2                                                                 1
3                                                                 1
4                                                                 1
5                                                                 1
6                                                                 1
                                                  SPI.D5.2.7.CGOV
1 Dimension 5.2: standards - Central government accounting status
2                                                               1
3                                                               1
4                                                               1
5                                                               1
6                                                               1
                                                          SPI.D5.2.8.FINA
1 Dimension 5.2: standards - Compilation of government finance statistics
2                                                                       1
3                                                                       1
4                                                                       1
5                                                                       1
6                                                                       1
                                                              SPI.D5.2.9.MONY
1 Dimension 5.2: standards - Compilation of monetary and financial statistics
2                                                                           1
3                                                                           1
4                                                                           1
5                                                                           1
6                                                                           1
                             SPI.D5.2.10.GSBP
1 Dimension 5.2: standards - Business process
2                                           1
3                                           1
4                                           1
5                                           1
6                                           1
                                                                                        SPI.D5.5.DIFI
1 Dimension 5.5: Finance - Finance Indicator based on PARIS21 indicators on SDG 17.18.3 & SDG 17.19.1
2                                                                                                   1
3                                                                                                   1
4                                                                                                   1
5                                                                                                   1
6                                                                                                   1
       income                region weights population
1                                        NA         NA
2 High income Europe & Central Asia       1    5347896
3 High income Europe & Central Asia       1   60297396
4 High income Europe & Central Asia       1    8877067
5 High income Europe & Central Asia       1   37970874
6 High income Europe & Central Asia       1    2087946

We are going to use only data from 2019 for 173 countries. We need to delete the first row as well.

data2019<-spi_index_labelled[2:175,]
colnames(data2019)
 [1] "country"                        "iso3c"                         
 [3] "date"                           "SPI.INDEX.PIL1"                
 [5] "SPI.INDEX.PIL2"                 "SPI.INDEX.PIL3"                
 [7] "SPI.INDEX.PIL4"                 "SPI.INDEX.PIL5"                
 [9] "SPI.INDEX"                      "SPI.DIM1.5.INDEX"              
[11] "SPI.DIM2.1.INDEX"               "SPI.DIM2.2.INDEX"              
[13] "SPI.DIM2.4.INDEX"               "SPI.DIM3.1.INDEX"              
[15] "SPI.DIM3.2.INDEX"               "SPI.DIM3.3.INDEX"              
[17] "SPI.DIM3.4.INDEX"               "SPI.DIM4.1.CEN.INDEX"          
[19] "SPI.DIM4.1.SVY.INDEX"           "SPI.DIM4.2.INDEX"              
[21] "SPI.DIM4.3.INDEX"               "SPI.DIM5.1.INDEX"              
[23] "SPI.DIM5.2.INDEX"               "SPI.DIM5.5.INDEX"              
[25] "SPI.D1.5.POV"                   "SPI.D1.5.CHLD.MORT"            
[27] "SPI.D1.5.DT.TDS.DPPF.XP.ZS"     "SPI.D1.5.SAFE.MAN.WATER"       
[29] "SPI.D1.5.LFP"                   "SPI.D2.1.GDDS"                 
[31] "SPI.D2.2.Machine.readable"      "SPI.D2.2.Non.proprietary"      
[33] "SPI.D2.2.Download.options"      "SPI.D2.2.Metadata.available"   
[35] "SPI.D2.2.Terms.of.use"          "SPI.D2.2.Openness.subscore"    
[37] "SPI.D2.4.NADA"                  "SPI.D3.1.POV"                  
[39] "SPI.D3.2.HNGR"                  "SPI.D3.3.HLTH"                 
[41] "SPI.D3.4.EDUC"                  "SPI.D3.5.GEND"                 
[43] "SPI.D3.6.WTRS"                  "SPI.D3.7.ENRG"                 
[45] "SPI.D3.8.WORK"                  "SPI.D3.9.INDY"                 
[47] "SPI.D3.10.NEQL"                 "SPI.D3.11.CITY"                
[49] "SPI.D3.12.CNSP"                 "SPI.D3.15.LAND"                
[51] "SPI.D3.16.INST"                 "SPI.D3.17.PTNS"                
[53] "SPI.D3.13.CLMT"                 "SPI.D4.1.1.POPU"               
[55] "SPI.D4.1.2.AGRI"                "SPI.D4.1.3.BIZZ"               
[57] "SPI.D4.1.4.HOUS"                "SPI.D4.1.5.AGSVY"              
[59] "SPI.D4.1.6.LABR"                "SPI.D4.1.7.HLTH"               
[61] "SPI.D4.1.8.BZSVY"               "SPI.D4.2.3.CRVS"               
[63] "SPI.D4.3.GEO.first.admin.level" "SPI.D5.1.DILG"                 
[65] "SPI.D5.2.1.SNAU"                "SPI.D5.2.2.NABY"               
[67] "SPI.D5.2.3.CNIN"                "SPI.D5.2.4.CPIBY"              
[69] "SPI.D5.2.5.HOUS"                "SPI.D5.2.6.EMPL"               
[71] "SPI.D5.2.7.CGOV"                "SPI.D5.2.8.FINA"               
[73] "SPI.D5.2.9.MONY"                "SPI.D5.2.10.GSBP"              
[75] "SPI.D5.5.DIFI"                  "income"                        
[77] "region"                         "weights"                       
[79] "population"                    

Dropping the columns that are not related with statistical offices quality. Also the aggregated indicators.

data2019<-data.frame(data2019)
drop<-c("iso3c","date","SPI.INDEX.PIL1","SPI.INDEX.PIL2","SPI.INDEX.PIL3","SPI.INDEX.PIL4","SPI.INDEX.PIL5","SPI.INDEX","income","region","weights","population", "SPI.DIM1.5.INDEX")
data2019<-data2019[,!(names(data2019) %in% drop)]
head(data2019)
        country SPI.DIM2.1.INDEX SPI.DIM2.2.INDEX SPI.DIM2.4.INDEX
2        Norway                1            0.767                1
3         Italy                1            0.756                1
4       Austria                1            0.739                1
5        Poland                1            0.853                1
6      Slovenia                1            0.908                1
7 United States                1             0.82                1
   SPI.DIM3.1.INDEX  SPI.DIM3.2.INDEX SPI.DIM3.3.INDEX SPI.DIM3.4.INDEX
2 0.757833333333333 0.782166666666667                1           0.5855
3 0.711166666666667 0.787166666666667                1            0.528
4 0.721666666666667 0.750666666666667                1            0.547
5 0.678666666666667            0.7515             0.75           0.6025
6            0.7335 0.791333333333333                1            0.528
7             0.593 0.604833333333333           0.9445           0.5115
  SPI.DIM4.1.CEN.INDEX SPI.DIM4.1.SVY.INDEX SPI.DIM4.2.INDEX SPI.DIM4.3.INDEX
2    0.666666666666667                    1                1             0.56
3                    1                0.934                1            0.339
4                    1                0.866                1            0.324
5    0.666666666666667                0.934                1            0.588
6    0.666666666666667                0.934                1            0.257
7                    1                    1                1              0.5
  SPI.DIM5.1.INDEX SPI.DIM5.2.INDEX SPI.DIM5.5.INDEX SPI.D1.5.POV
2                1                1                1            1
3                1                1                1            1
4                1                1                1            1
5                1                1                1            1
6                1                1                1            1
7                1                1                1            1
  SPI.D1.5.CHLD.MORT SPI.D1.5.DT.TDS.DPPF.XP.ZS SPI.D1.5.SAFE.MAN.WATER
2                  1                          1                       1
3                  1                          1                       1
4                  1                          1                       1
5                  1                          1                       1
6                  1                          1                       1
7                  1                          1                       1
  SPI.D1.5.LFP SPI.D2.1.GDDS SPI.D2.2.Machine.readable SPI.D2.2.Non.proprietary
2            1             1                         1                        1
3            1             1                     0.771                    0.786
4            1             1                     0.907                    0.963
5            1             1                         1                        1
6            1             1                     0.963                        1
7            1             1                      0.83                    0.952
  SPI.D2.2.Download.options SPI.D2.2.Metadata.available SPI.D2.2.Terms.of.use
2                     0.623                        0.67                 0.542
3                      0.69                       0.762                 0.771
4                     0.686                       0.703                 0.434
5                      0.68                       0.679                 0.905
6                     0.784                       0.897                 0.897
7                     0.566                       0.797                 0.952
  SPI.D2.2.Openness.subscore SPI.D2.4.NADA SPI.D3.1.POV SPI.D3.2.HNGR
2                      0.767             1            1         0.889
3                      0.756             1        0.857           0.8
4                      0.739             1            1           0.6
5                      0.853             1        0.714           0.7
6                      0.908             1            1           0.7
7                       0.82             1        0.857           0.7
  SPI.D3.3.HLTH SPI.D3.4.EDUC SPI.D3.5.GEND SPI.D3.6.WTRS SPI.D3.7.ENRG
2         0.905         0.545         0.375         0.833           0.8
3         0.857         0.545         0.375         0.833           0.8
4           0.9         0.455         0.375             1           0.8
5         0.905         0.545         0.375         0.833           0.8
6         0.857         0.636         0.375         0.833           0.8
7         0.762         0.364         0.375           0.5           0.6
  SPI.D3.8.WORK SPI.D3.9.INDY SPI.D3.10.NEQL SPI.D3.11.CITY SPI.D3.12.CNSP
2         0.643             1            0.5              1           0.75
3         0.769             1          0.571          0.833           0.75
4         0.692             1          0.429          0.833           0.75
5         0.692             1          0.667            0.6           0.75
6         0.769             1          0.429              1           0.75
7         0.571         0.625            0.5          0.833            0.5
  SPI.D3.15.LAND SPI.D3.16.INST SPI.D3.17.PTNS SPI.D3.13.CLMT SPI.D4.1.1.POPU
2              1          0.556          0.615              1               1
3              1          0.556            0.5              1               1
4              1          0.556          0.538              1               1
5              1          0.667          0.538            0.5               1
6              1          0.556            0.5              1               1
7          0.889          0.556          0.467              1               1
  SPI.D4.1.2.AGRI SPI.D4.1.3.BIZZ SPI.D4.1.4.HOUS SPI.D4.1.5.AGSVY
2               1               0               1                1
3               1               1               1                1
4               1               1               1                1
5               1               0               1                1
6               1               0               1                1
7               1               1               1                1
  SPI.D4.1.6.LABR SPI.D4.1.7.HLTH SPI.D4.1.8.BZSVY SPI.D4.2.3.CRVS
2               1               1                1               1
3               1            0.67                1               1
4               1            0.33                1               1
5               1            0.67                1               1
6               1            0.67                1               1
7               1               1                1               1
  SPI.D4.3.GEO.first.admin.level SPI.D5.1.DILG SPI.D5.2.1.SNAU SPI.D5.2.2.NABY
2                           0.56             1               1               1
3                          0.339             1               1               1
4                          0.324             1               1               1
5                          0.588             1               1               1
6                          0.257             1               1               1
7                            0.5             1               1               1
  SPI.D5.2.3.CNIN SPI.D5.2.4.CPIBY SPI.D5.2.5.HOUS SPI.D5.2.6.EMPL
2               1                1               1               1
3               1                1               1               1
4               1                1               1               1
5               1                1               1               1
6               1                1               1               1
7               1                1               1               1
  SPI.D5.2.7.CGOV SPI.D5.2.8.FINA SPI.D5.2.9.MONY SPI.D5.2.10.GSBP
2               1               1               1                1
3               1               1               1                1
4               1               1               1                1
5               1               1               1                1
6               1               1               1                1
7               1               1               1                1
  SPI.D5.5.DIFI
2             1
3             1
4             1
5             1
6             1
7             1

Now filtering out the ordinal data.

threshold <- 5

selected_columns <- sapply(data2019, function(x) length(unique(x))) <= threshold

# Filter the dataframe
filtered_data <- data2019[, !selected_columns]
complete_data <- filtered_data[!complete.cases(filtered_data), ]
complete_data
 [1] country                        SPI.DIM2.2.INDEX              
 [3] SPI.DIM3.1.INDEX               SPI.DIM3.2.INDEX              
 [5] SPI.DIM3.3.INDEX               SPI.DIM3.4.INDEX              
 [7] SPI.DIM4.1.CEN.INDEX           SPI.DIM4.1.SVY.INDEX          
 [9] SPI.DIM4.3.INDEX               SPI.DIM5.2.INDEX              
[11] SPI.D2.2.Machine.readable      SPI.D2.2.Non.proprietary      
[13] SPI.D2.2.Download.options      SPI.D2.2.Metadata.available   
[15] SPI.D2.2.Terms.of.use          SPI.D2.2.Openness.subscore    
[17] SPI.D3.1.POV                   SPI.D3.2.HNGR                 
[19] SPI.D3.3.HLTH                  SPI.D3.4.EDUC                 
[21] SPI.D3.5.GEND                  SPI.D3.6.WTRS                 
[23] SPI.D3.8.WORK                  SPI.D3.9.INDY                 
[25] SPI.D3.10.NEQL                 SPI.D3.11.CITY                
[27] SPI.D3.15.LAND                 SPI.D3.16.INST                
[29] SPI.D3.17.PTNS                 SPI.D4.3.GEO.first.admin.level
<0 rows> (or 0-length row.names)

As we can see, now there are no incomplete cases.

data2019n <- filtered_data


columns_to_convert <- names(data2019n)[-1]

data2019n[, columns_to_convert] <- lapply(data2019n[, columns_to_convert], function(x) as.numeric(as.character(x)))

summary(data2019n)
   country          SPI.DIM2.2.INDEX SPI.DIM3.1.INDEX SPI.DIM3.2.INDEX
 Length:174         Min.   :0.0190   Min.   :0.3028   Min.   :0.3607  
 Class :character   1st Qu.:0.3040   1st Qu.:0.5371   1st Qu.:0.4985  
 Mode  :character   Median :0.3980   Median :0.6490   Median :0.6073  
                    Mean   :0.4660   Mean   :0.6234   Mean   :0.5958  
                    3rd Qu.:0.6188   3rd Qu.:0.7168   3rd Qu.:0.6775  
                    Max.   :1.0000   Max.   :0.9072   Max.   :0.9153  
 SPI.DIM3.3.INDEX SPI.DIM3.4.INDEX SPI.DIM4.1.CEN.INDEX SPI.DIM4.1.SVY.INDEX
 Min.   :0.2220   Min.   :0.2670   Min.   :0.0000       Min.   :0.0000      
 1st Qu.:0.4445   1st Qu.:0.5220   1st Qu.:0.3333       1st Qu.:0.4000      
 Median :0.6945   Median :0.5790   Median :0.6667       Median :0.6000      
 Mean   :0.7276   Mean   :0.5789   Mean   :0.5699       Mean   :0.6124      
 3rd Qu.:0.9445   3rd Qu.:0.6659   3rd Qu.:0.6667       3rd Qu.:0.8000      
 Max.   :1.0000   Max.   :0.8290   Max.   :1.0000       Max.   :1.0000      
 SPI.DIM4.3.INDEX SPI.DIM5.2.INDEX SPI.D2.2.Machine.readable
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000           
 1st Qu.:0.1128   1st Qu.:0.3000   1st Qu.:0.1323           
 Median :0.1780   Median :0.4500   Median :0.4175           
 Mean   :0.1969   Mean   :0.5460   Mean   :0.4677           
 3rd Qu.:0.2785   3rd Qu.:0.8375   3rd Qu.:0.8093           
 Max.   :0.6980   Max.   :1.0000   Max.   :1.0000           
 SPI.D2.2.Non.proprietary SPI.D2.2.Download.options SPI.D2.2.Metadata.available
 Min.   :0.0000           Min.   :0.0240            Min.   :0.0000             
 1st Qu.:0.5952           1st Qu.:0.2530            1st Qu.:0.3772             
 Median :0.7715           Median :0.3495            Median :0.4715             
 Mean   :0.7214           Mean   :0.3975            Mean   :0.4929             
 3rd Qu.:0.8890           3rd Qu.:0.5312            3rd Qu.:0.5753             
 Max.   :1.0000           Max.   :1.0000            Max.   :1.0000             
 SPI.D2.2.Terms.of.use SPI.D2.2.Openness.subscore  SPI.D3.1.POV   
 Min.   :0.0000        Min.   :0.0190             Min.   :0.0000  
 1st Qu.:0.0000        1st Qu.:0.3040             1st Qu.:0.4290  
 Median :0.0000        Median :0.3980             Median :0.7140  
 Mean   :0.2508        Mean   :0.4660             Mean   :0.6773  
 3rd Qu.:0.4765        3rd Qu.:0.6188             3rd Qu.:0.8570  
 Max.   :1.0000        Max.   :1.0000             Max.   :1.0000  
 SPI.D3.2.HNGR    SPI.D3.3.HLTH    SPI.D3.4.EDUC   SPI.D3.5.GEND   
 Min.   :0.1430   Min.   :0.2380   Min.   :0.091   Min.   :0.1250  
 1st Qu.:0.5560   1st Qu.:0.7140   1st Qu.:0.364   1st Qu.:0.2500  
 Median :0.7000   Median :0.8000   Median :0.455   Median :0.3750  
 Mean   :0.6595   Mean   :0.7805   Mean   :0.453   Mean   :0.3505  
 3rd Qu.:0.8000   3rd Qu.:0.8570   3rd Qu.:0.545   3rd Qu.:0.5000  
 Max.   :1.0000   Max.   :1.0000   Max.   :0.818   Max.   :0.7500  
 SPI.D3.6.WTRS    SPI.D3.8.WORK   SPI.D3.9.INDY    SPI.D3.10.NEQL  
 Min.   :0.3330   Min.   :0.143   Min.   :0.1250   Min.   :0.1670  
 1st Qu.:0.7003   1st Qu.:0.308   1st Qu.:0.3750   1st Qu.:0.3330  
 Median :0.8330   Median :0.462   Median :0.6250   Median :0.4290  
 Mean   :0.8195   Mean   :0.480   Mean   :0.6073   Mean   :0.4586  
 3rd Qu.:1.0000   3rd Qu.:0.615   3rd Qu.:0.7500   3rd Qu.:0.6000  
 Max.   :1.0000   Max.   :0.923   Max.   :1.0000   Max.   :0.8000  
 SPI.D3.11.CITY   SPI.D3.15.LAND   SPI.D3.16.INST   SPI.D3.17.PTNS  
 Min.   :0.1670   Min.   :0.4440   Min.   :0.2220   Min.   :0.2940  
 1st Qu.:0.3330   1st Qu.:0.8890   1st Qu.:0.4440   1st Qu.:0.5343  
 Median :0.6670   Median :0.8890   Median :0.5560   Median :0.6000  
 Mean   :0.5947   Mean   :0.8718   Mean   :0.5666   Mean   :0.5913  
 3rd Qu.:0.8000   3rd Qu.:0.8890   3rd Qu.:0.6670   3rd Qu.:0.6670  
 Max.   :1.0000   Max.   :1.0000   Max.   :0.8890   Max.   :0.7860  
 SPI.D4.3.GEO.first.admin.level
 Min.   :0.0000                
 1st Qu.:0.1128                
 Median :0.1780                
 Mean   :0.1969                
 3rd Qu.:0.2785                
 Max.   :0.6980                

PCA

data_pca <- prcomp(data2019n[,-1], center = T, scale= T)
summary(data_pca)
Importance of components:
                          PC1    PC2     PC3     PC4     PC5     PC6     PC7
Standard deviation     3.4960 2.1288 1.45733 1.25356 1.06860 0.99761 0.89102
Proportion of Variance 0.4215 0.1563 0.07324 0.05419 0.03938 0.03432 0.02738
Cumulative Proportion  0.4215 0.5777 0.65096 0.70514 0.74452 0.77884 0.80621
                           PC8     PC9    PC10    PC11    PC12    PC13    PC14
Standard deviation     0.85272 0.79446 0.74459 0.70718 0.67600 0.67312 0.62752
Proportion of Variance 0.02507 0.02176 0.01912 0.01725 0.01576 0.01562 0.01358
Cumulative Proportion  0.83129 0.85305 0.87217 0.88941 0.90517 0.92079 0.93437
                          PC15    PC16    PC17    PC18    PC19    PC20    PC21
Standard deviation     0.60089 0.55592 0.51816 0.48957 0.44278 0.40587 0.39342
Proportion of Variance 0.01245 0.01066 0.00926 0.00826 0.00676 0.00568 0.00534
Cumulative Proportion  0.94682 0.95748 0.96674 0.97500 0.98176 0.98745 0.99278
                          PC22    PC23   PC24     PC25      PC26      PC27
Standard deviation     0.35125 0.23835 0.1706 0.001427 1.125e-15 6.157e-16
Proportion of Variance 0.00425 0.00196 0.0010 0.000000 0.000e+00 0.000e+00
Cumulative Proportion  0.99704 0.99900 1.0000 1.000000 1.000e+00 1.000e+00
                            PC28      PC29
Standard deviation     3.681e-16 2.827e-16
Proportion of Variance 0.000e+00 0.000e+00
Cumulative Proportion  1.000e+00 1.000e+00

As we can see we can reduce the number of variables to 6 while explaining 75% of variance or to 12 while explaining 90% of variance. Let’s look at the scree plot.

fviz_eig(data_pca, addlbales = T, ylim=c(0,80))

loadings <- data_pca$rotation

print("Variable Loadings:")
[1] "Variable Loadings:"
print(head(loadings))
                            PC1         PC2         PC3         PC4         PC5
SPI.DIM2.2.INDEX     -0.2234130  0.26929068 -0.05763134  0.01599882 -0.10877895
SPI.DIM3.1.INDEX     -0.2434693 -0.22172500 -0.03924868 -0.04389728 -0.07708868
SPI.DIM3.2.INDEX     -0.2539881 -0.06898791  0.15249745 -0.16012299  0.12946325
SPI.DIM3.3.INDEX     -0.1622832 -0.21119647  0.36514427 -0.03859310 -0.27979753
SPI.DIM3.4.INDEX     -0.1444984 -0.26863986 -0.36601656  0.15214387  0.02860233
SPI.DIM4.1.CEN.INDEX -0.1540554  0.07040690 -0.05101389  0.02530164 -0.17283094
                             PC6         PC7         PC8         PC9
SPI.DIM2.2.INDEX      0.09564713 -0.08335476  0.16489383 -0.04194902
SPI.DIM3.1.INDEX      0.01406155 -0.08443059 -0.10545640  0.01245611
SPI.DIM3.2.INDEX     -0.10217419  0.01917857 -0.11453245 -0.07140584
SPI.DIM3.3.INDEX     -0.11309458 -0.03235520  0.17237008 -0.12700812
SPI.DIM3.4.INDEX     -0.03825113  0.04217487  0.24178301 -0.06565367
SPI.DIM4.1.CEN.INDEX  0.07125570  0.80970381 -0.01048636  0.17502805
                            PC10         PC11        PC12         PC13
SPI.DIM2.2.INDEX      0.04486835  0.026529843  0.01796801  0.016305557
SPI.DIM3.1.INDEX      0.01920430  0.140817916  0.03721249  0.008578093
SPI.DIM3.2.INDEX     -0.06843817 -0.056024272  0.01460682 -0.024560873
SPI.DIM3.3.INDEX     -0.11438816 -0.001088628 -0.12161740  0.086113589
SPI.DIM3.4.INDEX      0.04511480 -0.171195285 -0.13147559 -0.037672647
SPI.DIM4.1.CEN.INDEX -0.12160595  0.296191359 -0.23092402  0.040511366
                            PC14        PC15        PC16         PC17
SPI.DIM2.2.INDEX     -0.02956448 -0.03532554 -0.01374741  0.010622187
SPI.DIM3.1.INDEX     -0.07102327 -0.06302166 -0.08235706  0.016499590
SPI.DIM3.2.INDEX     -0.06889699  0.04353947  0.01402071  0.059390120
SPI.DIM3.3.INDEX     -0.04008307  0.02174968  0.06418388  0.003995137
SPI.DIM3.4.INDEX      0.08996936  0.16819440  0.13949232 -0.013847339
SPI.DIM4.1.CEN.INDEX -0.16195906 -0.03240969  0.04074945 -0.198863947
                             PC18         PC19        PC20         PC21
SPI.DIM2.2.INDEX      0.026397610  0.003742454  0.06816913 -0.090311855
SPI.DIM3.1.INDEX      0.025461814 -0.081270866 -0.07228833  0.053370516
SPI.DIM3.2.INDEX     -0.052437586  0.258315586  0.18503911  0.057516065
SPI.DIM3.3.INDEX     -0.007705645 -0.102853644 -0.02671311 -0.092606065
SPI.DIM3.4.INDEX     -0.119665239 -0.013155927  0.05035510 -0.001022566
SPI.DIM4.1.CEN.INDEX -0.018532982  0.015910795 -0.09734680  0.010549376
                            PC22        PC23         PC24          PC25
SPI.DIM2.2.INDEX     -0.00861016  0.02019766  0.009312399 -5.452527e-01
SPI.DIM3.1.INDEX     -0.22405515  0.06801869 -0.007307258 -6.190692e-06
SPI.DIM3.2.INDEX      0.24603550  0.34753940  0.727120419  7.113507e-04
SPI.DIM3.3.INDEX      0.09255094 -0.72658147  0.241562637  2.826801e-04
SPI.DIM3.4.INDEX      0.03453889  0.01220599  0.009471488 -3.034242e-07
SPI.DIM4.1.CEN.INDEX  0.08739951  0.05250852 -0.014183338  1.933318e-04
                              PC26          PC27          PC28          PC29
SPI.DIM2.2.INDEX     -7.071068e-01  0.000000e+00  0.000000e+00  0.000000e+00
SPI.DIM3.1.INDEX      6.755707e-14  8.670967e-01  6.127789e-02  9.341307e-04
SPI.DIM3.2.INDEX      2.081668e-16 -1.165734e-15  7.268491e-16 -3.840786e-17
SPI.DIM3.3.INDEX      3.348016e-16  5.967449e-16  4.297777e-16  1.512394e-16
SPI.DIM3.4.INDEX     -2.167017e-14  5.153745e-02 -7.314640e-01  1.441136e-01
SPI.DIM4.1.CEN.INDEX  1.595946e-16  2.775558e-17  1.231654e-16 -2.919214e-17

As two first PCs explain about 57% of variance I do not think it is appropriate to show them on a biplot.

Now, what can we do with it?

Depends on the task we wanted to perform. If we were to analyze the continuous variables only we could finish here. If we were asked to perform some operations on the whole data set we could add the rest of variables back to the data set.