library(readr)
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(psych)
library(factoextra)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(corrplot)
## corrplot 0.95 loaded
library(knitr)
data_hfi <- read.csv("hfi_cc_2018.csv")
Filter data tahun 2016 dan ambil 12 variabel
hfi_fitur <- data_hfi %>%
filter(year == 2016) %>%
select(
pf_rol, # Rule of Law
pf_ss, # Security and Safety
pf_movement, # Movement
pf_religion, # Religion
pf_association, # Association, Assembly, and Civil Society
pf_expression, # Expression and Information
pf_identity, # Identity and Relationships
ef_government, # Size of Government
ef_legal, # Legal System and Property Rights
ef_money, # Sound Money
ef_trade, # Freedom to Trade Internationally
ef_regulation # Regulation
)
# cek missing value
hfi_clean <- na.omit(hfi_fitur)
str(hfi_clean)
## 'data.frame': 136 obs. of 12 variables:
## $ pf_rol : num 5.29 3.82 3.45 5.74 5 ...
## $ pf_ss : num 8.81 8.04 8.3 9.04 8.83 ...
## $ pf_movement : num 6.67 5 5 10 6.67 ...
## $ pf_religion : num 9.19 4.94 8.79 7.8 6.22 ...
## $ pf_association: num 10 5 4 7.5 6.5 10 10 3 5 7 ...
## $ pf_expression : num 8.61 7.38 6.45 8.74 7.15 ...
## $ pf_identity : num 6.25 0.833 7.5 10 8 ...
## $ ef_government : num 7.94 3.62 6.5 5.35 7 ...
## $ ef_legal : num 5.07 4.69 2.96 3.9 5.81 ...
## $ ef_money : num 9.55 7.25 5.61 5.61 9.52 ...
## $ ef_trade : num 8.21 4.13 5.26 3.98 8.14 ...
## $ ef_regulation : num 6.91 5.27 5.52 5.37 7.38 ...
## - attr(*, "na.action")= 'omit' Named int [1:26] 9 12 15 17 20 29 35 49 53 60 ...
## ..- attr(*, "names")= chr [1:26] "9" "12" "15" "17" ...
desc <- describe(hfi_clean)
kable(
desc,
caption="Tabel 1 Statistik Variabel Penelitian"
)
| vars | n | mean | sd | median | trimmed | mad | min | max | range | skew | kurtosis | se | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| pf_rol | 1 | 136 | 5.234692 | 1.677037 | 4.875973 | 5.175042 | 1.8904399 | 2.060257 | 8.687101 | 6.626843 | 0.3294305 | -0.9148099 | 0.1438047 |
| pf_ss | 2 | 136 | 8.245901 | 1.383879 | 8.437167 | 8.379945 | 1.5046301 | 3.963850 | 9.959940 | 5.996090 | -0.7383648 | -0.1593997 | 0.1186667 |
| pf_movement | 3 | 136 | 7.714461 | 2.689326 | 8.333333 | 8.143939 | 2.4710000 | 0.000000 | 10.000000 | 10.000000 | -1.1229070 | 0.4878708 | 0.2306078 |
| pf_religion | 4 | 136 | 7.319485 | 1.682392 | 7.840741 | 7.498047 | 1.3357128 | 0.000000 | 9.731481 | 9.731481 | -1.1576961 | 1.5376239 | 0.1442640 |
| pf_association | 5 | 136 | 7.110294 | 2.774014 | 7.750000 | 7.413636 | 3.3358500 | 0.500000 | 10.000000 | 9.500000 | -0.7080035 | -0.7105218 | 0.2378697 |
| pf_expression | 6 | 136 | 7.808461 | 1.531554 | 8.204702 | 7.955778 | 1.6296590 | 3.202381 | 9.797619 | 6.595238 | -0.7452358 | -0.2429400 | 0.1313297 |
| pf_identity | 7 | 136 | 7.068627 | 3.124675 | 8.333333 | 7.500758 | 2.4710000 | 0.000000 | 10.000000 | 10.000000 | -0.9547623 | -0.3782450 | 0.2679387 |
| ef_government | 8 | 136 | 6.485281 | 1.281175 | 6.541030 | 6.508517 | 1.4235797 | 3.616782 | 9.528485 | 5.911703 | -0.1208735 | -0.5710284 | 0.1098598 |
| ef_legal | 9 | 136 | 5.287487 | 1.596612 | 5.140786 | 5.226520 | 1.7319915 | 1.856230 | 8.798181 | 6.941951 | 0.3171899 | -0.5904395 | 0.1369084 |
| ef_money | 10 | 136 | 8.351133 | 1.403993 | 8.901630 | 8.531657 | 1.0447499 | 1.942101 | 9.922187 | 7.980086 | -1.2597699 | 1.9180007 | 0.1203914 |
| ef_trade | 11 | 136 | 7.061859 | 1.241091 | 7.238713 | 7.178041 | 1.2931531 | 2.877141 | 9.323969 | 6.446828 | -0.8503063 | 0.4213520 | 0.1064227 |
| ef_regulation | 12 | 136 | 7.064448 | 1.033340 | 7.104888 | 7.124737 | 0.9047881 | 2.483540 | 9.439828 | 6.956288 | -0.8190510 | 2.1316759 | 0.0886082 |
korelasi matriks
cor_matrix <- cor(hfi_clean)
cat("\n--- Kaiser-Meyer-Olkin (KMO) Test ---\n")
##
## --- Kaiser-Meyer-Olkin (KMO) Test ---
# Cek Expect > 0.5
print(KMO(cor_matrix))
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = cor_matrix)
## Overall MSA = 0.87
## MSA for each item =
## pf_rol pf_ss pf_movement pf_religion pf_association
## 0.85 0.92 0.93 0.89 0.82
## pf_expression pf_identity ef_government ef_legal ef_money
## 0.87 0.87 0.63 0.84 0.86
## ef_trade ef_regulation
## 0.87 0.90
cat("\n--- Bartlett's Test of Sphericity ---\n")
##
## --- Bartlett's Test of Sphericity ---
# Cek expect p < 0.05
print(cortest.bartlett(cor_matrix, n = nrow(hfi_clean)))
## $chisq
## [1] 1251.071
##
## $p.value
## [1] 2.606544e-218
##
## $df
## [1] 66
Standarisasi dan run PCA
pca_result <- prcomp(hfi_clean, center = TRUE, scale. = TRUE)
summary(pca_result)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.4636 1.3700 1.09462 0.84724 0.71229 0.62502 0.60975
## Proportion of Variance 0.5058 0.1564 0.09985 0.05982 0.04228 0.03255 0.03098
## Cumulative Proportion 0.5058 0.6622 0.76201 0.82183 0.86411 0.89666 0.92765
## PC8 PC9 PC10 PC11 PC12
## Standard deviation 0.5412 0.45896 0.40901 0.35537 0.26680
## Proportion of Variance 0.0244 0.01755 0.01394 0.01052 0.00593
## Cumulative Proportion 0.9520 0.96960 0.98354 0.99407 1.00000
fviz_eig(pca_result, addlabels = TRUE, ylim = c(0, 70), main = "PCA Scree Plot (HFI 2016)")
boxplot(hfi_clean,
las = 2,
col = "lightblue",
main = "Boxplot Variabel HFI 2016",
ylab = "Nilai",
cex.axis = 0.7)
fa.parallel(hfi_clean, fa="fa", n.iter=100, main="Scree Plot dengan Parallel Analysis")
## Parallel analysis suggests that the number of factors = 3 and the number of components = NA
Perform Factor Analysis Personal Freedom vs Economic Freedom
fa_result <- fa(hfi_clean, nfactors = 2, rotate = "varimax", fm = "minres")
print(fa_result, digits = 2, sort = TRUE)
## Factor Analysis using method = minres
## Call: fa(r = hfi_clean, nfactors = 2, rotate = "varimax", fm = "minres")
## Standardized loadings (pattern matrix) based upon correlation matrix
## item MR1 MR2 h2 u2 com
## ef_legal 9 0.93 0.16 0.891 0.11 1.1
## pf_rol 1 0.87 0.30 0.843 0.16 1.2
## ef_trade 11 0.76 0.34 0.701 0.30 1.4
## ef_regulation 12 0.75 0.16 0.587 0.41 1.1
## pf_ss 2 0.71 0.30 0.600 0.40 1.4
## ef_money 10 0.63 0.25 0.459 0.54 1.3
## ef_government 8 -0.23 -0.02 0.053 0.95 1.0
## pf_association 5 0.20 0.85 0.768 0.23 1.1
## pf_expression 6 0.37 0.82 0.814 0.19 1.4
## pf_religion 4 -0.01 0.79 0.623 0.38 1.0
## pf_movement 3 0.33 0.67 0.561 0.44 1.5
## pf_identity 7 0.33 0.55 0.411 0.59 1.6
##
## MR1 MR2
## SS loadings 4.12 3.19
## Proportion Var 0.34 0.27
## Cumulative Var 0.34 0.61
## Proportion Explained 0.56 0.44
## Cumulative Proportion 0.56 1.00
##
## Mean item complexity = 1.3
## Test of the hypothesis that 2 factors are sufficient.
##
## df null model = 66 with the objective function = 9.61 with Chi Square = 1251.07
## df of the model are 43 and the objective function was 1.52
##
## The root mean square of the residuals (RMSR) is 0.06
## The df corrected root mean square of the residuals is 0.08
##
## The harmonic n.obs is 136 with the empirical chi square 37.92 with prob < 0.69
## The total n.obs was 136 with Likelihood Chi Square = 196.31 with prob < 1.8e-21
##
## Tucker Lewis Index of factoring reliability = 0.799
## RMSEA index = 0.162 and the 90 % confidence intervals are 0.14 0.186
## BIC = -14.94
## Fit based upon off diagonal values = 0.98
## Measures of factor score adequacy
## MR1 MR2
## Correlation of (regression) scores with factors 0.97 0.94
## Multiple R square of scores with factors 0.93 0.89
## Minimum correlation of possible factor scores 0.87 0.78
fa.diagram(fa_result, main = "HFI Factor Structure (2 Factors)")